-
-
Save AG-Dan/63acf648e385ccaef37f71a08d045134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
class GlobalDungeonObject : MonoBehaviour | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using DunGen; | |
using UnityEngine; | |
/// <summary> | |
/// Takes objects marked as global dungeon objects (can move freely throughout the dungeon layout) | |
/// and parents them to the dungeon root instead of the room the object was spawned in. | |
/// Used to prevent global objects from being culled when using the built-in culling scripts | |
/// NOTE: Script execution order might need to be changed to ensure this script runs before the culling | |
/// caches all of the renderers in each tile. | |
/// </summary> | |
class UnparentGlobalDungeonObjects : MonoBehaviour | |
{ | |
public RuntimeDungeon RuntimeDungeon = null; | |
private void Awake() | |
{ | |
RuntimeDungeon.Generator.OnGenerationStatusChanged += OnGenerationStatusChanged; | |
} | |
private void OnDestroy() | |
{ | |
RuntimeDungeon.Generator.OnGenerationStatusChanged -= OnGenerationStatusChanged; | |
} | |
private void OnGenerationStatusChanged(DungeonGenerator generator, GenerationStatus status) | |
{ | |
if (status != GenerationStatus.Complete) | |
return; | |
// GlobalDungeonObject is just an empty MonoBehaviour used to tag objects | |
// other methods can be used instead (tags, name, layer, etc) | |
foreach (var obj in generator.Root.GetComponentsInChildren<GlobalDungeonObject>()) | |
obj.transform.parent = generator.Root.transform; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment