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

Prefab Template Processors #453

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Nautilus/Assets/CustomPrefab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ public void AddOnUnregister(Action onUnregisterCallback)
/// Sets a prefab template as the game object constructor of this custom prefab.
/// </summary>
/// <param name="prefabTemplate">The prefab template object to set.</param>
public void SetGameObject(PrefabTemplate prefabTemplate) => Prefab = prefabTemplate.GetPrefabAsync;
public void SetGameObject(PrefabTemplate prefabTemplate)
{
Prefab = prefabTemplate.GetPrefabAsync;
SetPrefabPostProcessor(prefabTemplate.OnPrefabPostProcessor);
}

/// <summary>
/// Sets a game object as the prefab of this custom prefab.
Expand All @@ -282,13 +286,13 @@ public void SetGameObject(GameObject prefab)
/// Sets a post processor for the <see cref="Prefab"/>. This is an asynchronous version.
/// </summary>
/// <param name="postProcessorAsync">The post processor to set.</param>
public void SetPrefabPostProcessor(Func<GameObject, IEnumerator> postProcessorAsync) => OnPrefabPostProcess = obj => postProcessorAsync(obj);
public void SetPrefabPostProcessor(Func<GameObject, IEnumerator> postProcessorAsync) => OnPrefabPostProcess += obj => postProcessorAsync(obj);

/// <summary>
/// Sets a post processor for the <see cref="Prefab"/>. This is a synchronous version.
/// </summary>
/// <param name="postProcessor">The post processor to set.</param>
public void SetPrefabPostProcessor(Action<GameObject> postProcessor) => OnPrefabPostProcess = obj => SyncPostProcessor(obj, postProcessor);
public void SetPrefabPostProcessor(Action<GameObject> postProcessor) => OnPrefabPostProcess += obj => SyncPostProcessor(obj, postProcessor);

/// <summary>
/// Registers this custom prefab into the game.
Expand Down
10 changes: 10 additions & 0 deletions Nautilus/Assets/PrefabTemplates/PrefabTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,14 @@ public PrefabTemplate(PrefabInfo info)
/// If the provided task result already has a game object set to it, it will try to set the necessary components first. Otherwise; sets a default implementation of this entity type.</param>
/// <returns>A coroutine operation. Must be used with either <c>yield return</c>, or <see cref="MonoBehaviour.StartCoroutine(IEnumerator)"/>.</returns>
public abstract IEnumerator GetPrefabAsync(TaskResult<GameObject> gameObject);

/// <summary>
/// Use this method to make changes to the prefab after the Nautilus' prefab processing is completed. Can be used to override or add more features to a prefab once it's settled.
/// </summary>
/// <param name="prefab">The prefab to process.</param>
/// <returns>A coroutine operation.</returns>
public virtual IEnumerator OnPrefabPostProcessor(GameObject prefab)
{
yield break;
}
}