Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additive Prefab Templates #502

Open
Metious opened this issue Nov 15, 2023 · 0 comments
Open

Additive Prefab Templates #502

Metious opened this issue Nov 15, 2023 · 0 comments

Comments

@Metious
Copy link
Member

Metious commented Nov 15, 2023

Describe the feature
A way to queue up prefab templates one by one, then Nautilus would apply the prefab changes from the first template, then add the changes from the second templates up to the previously-made prefab, and so on..

Purpose
Since most of the existing prefab templates are already capable of applying necessary changes if there's already a game object passed to the GetPrefabAsync method (example), this is already possible.. But it's dirty and intimidating to implement from scratch by a modder.

Currently the only way to queue up prefab templates is by creating a prefab factory method, then building up the prefab from scratch using prefab templates, and finally calling the CustomPrefab.SetGameObject(IEnumerator).
This approach "works", but your code will end up looking a mess due to the numerous GetPrefabAsync and new prefab template constructions you'd need to do.

Usage
The simplest approach would probably be adding a new PrefabTemplateBuilder class, then allow people to add new prefab templates using something like AddTemplate(PrefabTemplate), then at the end passing that builder to a SetGameObject overload.

Final interface would look like this:

CustomPrefab prefab = new CustomPrefab("FishEgg", "Some egg for a fish", "FishEgg that makes me go yes.");

PrefabTemplateBuilder builder = new PrefabTemplateBuilder(prefab.Info);

/* 
* Adds the asset bundle template as the first prefab to be constructed. 
* This will be the first and perhaps the only place where you allow the prefab template to construct a game object from scratch.
*/
builder.AddTemplate(new AssetBundleTemplate(assetbundle, "FishEgg"));

/*
* Adds the egg template.
* Since we already have a game object before from the asset bundle template, this would just apply the necessary settings
* to make this game object function like an egg. So [this](https://github.com/SubnauticaModding/Nautilus/blob/master/Nautilus/Assets/PrefabTemplates/EggTemplate.cs#L213-L218) part of the template.
*/
builder.AddTemplate(new EggTemplate().WithHatchingCreature(TechType.Titanium));

// Set the final game object and register this item to the game.
prefab.SetGameObject(builder);
prefab.Register();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant