Skip to content

Instantly share code, notes, and snippets.

@AG-Dan
Created September 23, 2021 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AG-Dan/941cbd2d0469618c3bb9a01f681f7b11 to your computer and use it in GitHub Desktop.
Save AG-Dan/941cbd2d0469618c3bb9a01f681f7b11 to your computer and use it in GitHub Desktop.
An example of how to execute a function on every instance of a custom 'MySpawnerComponent' script when the dungeon generation is completed
using DunGen;
using UnityEngine;
public class RunSpawnerScripts : MonoBehaviour
{
public RuntimeDungeon RuntimeDungeon = null;
private void OnEnable()
{
RuntimeDungeon.Generator.OnGenerationStatusChanged += OnDungeonGenerationStatusChanged;
}
private void OnDisable()
{
RuntimeDungeon.Generator.OnGenerationStatusChanged -= OnDungeonGenerationStatusChanged;
}
private void OnDungeonGenerationStatusChanged(DungeonGenerator generator, GenerationStatus status)
{
if (status == GenerationStatus.Complete)
{
foreach (var spawner in generator.Root.GetComponentsInChildren<MySpawnerComponent>())
spawner.Spawn();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment