From 874095249394ff9d64203907639150d30fef9514 Mon Sep 17 00:00:00 2001 From: Khauvinkh Date: Sat, 17 Aug 2024 13:59:08 +0200 Subject: [PATCH] Basic staging utility --- Assets/Scripts/Game Schedule.meta | 3 + Assets/Scripts/Game Schedule/StageProp.cs | 17 +++++ .../Scripts/Game Schedule/StageProp.cs.meta | 3 + .../Scripts/Game Schedule/StagingManager.cs | 75 +++++++++++++++++++ .../Game Schedule/StagingManager.cs.meta | 3 + 5 files changed, 101 insertions(+) create mode 100644 Assets/Scripts/Game Schedule.meta create mode 100644 Assets/Scripts/Game Schedule/StageProp.cs create mode 100644 Assets/Scripts/Game Schedule/StageProp.cs.meta create mode 100644 Assets/Scripts/Game Schedule/StagingManager.cs create mode 100644 Assets/Scripts/Game Schedule/StagingManager.cs.meta diff --git a/Assets/Scripts/Game Schedule.meta b/Assets/Scripts/Game Schedule.meta new file mode 100644 index 0000000..7c8fa0c --- /dev/null +++ b/Assets/Scripts/Game Schedule.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 71cc283a7f7c45649d6fabee033bce4a +timeCreated: 1723894561 \ No newline at end of file diff --git a/Assets/Scripts/Game Schedule/StageProp.cs b/Assets/Scripts/Game Schedule/StageProp.cs new file mode 100644 index 0000000..fdf4b51 --- /dev/null +++ b/Assets/Scripts/Game Schedule/StageProp.cs @@ -0,0 +1,17 @@ +using UnityEngine; + +public class StageProp: MonoBehaviour +{ + public StagingManager.StageEnum ActiveAtStages; + + public void Start() + { + StagingManager.RegisterStageProp(this); + gameObject.SetActive(false); + } + + public void OnDestroy() + { + StagingManager.RemoveStageProp(this); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Game Schedule/StageProp.cs.meta b/Assets/Scripts/Game Schedule/StageProp.cs.meta new file mode 100644 index 0000000..ba39399 --- /dev/null +++ b/Assets/Scripts/Game Schedule/StageProp.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 71cd04e41258435d9d03d9b67cb4b7ed +timeCreated: 1723894689 \ No newline at end of file diff --git a/Assets/Scripts/Game Schedule/StagingManager.cs b/Assets/Scripts/Game Schedule/StagingManager.cs new file mode 100644 index 0000000..0b71f93 --- /dev/null +++ b/Assets/Scripts/Game Schedule/StagingManager.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +public class StagingManager: MonoBehaviour +{ + public static StagingManager Instance; + public static List StageProps; + + public StageEnum CurrentStage; + + [Flags] + public enum StageEnum + { + Level1 = 1, + Level2 = 2, + } + + public void Start() + { + if (Instance == null) + { + Instance = this; + } + } + + public void OnDestroy() + { + StageProps.Clear(); + } + + public static void RegisterStageProp(StageProp stageProp) + { + if (StageProps == null) + { + StageProps = new List(); + } + + if (!StageProps.Contains(stageProp)) + { + StageProps.Add(stageProp); + } + } + + public static void RemoveStageProp(StageProp stageProp) + { + if (StageProps.Contains(stageProp)) + { + StageProps.Remove(stageProp); + } + } + + public static void SetStage(StageEnum stage) + { + Instance.CurrentStage = stage; + + foreach (var stageProp in StageProps) + { + stageProp.gameObject.SetActive((stageProp.ActiveAtStages & stage) != 0); + } + } + + [MenuItem("Tools/Staging/Level1")] + public static void SetStage1() + { + SetStage(StageEnum.Level1); + } + + [MenuItem("Tools/Staging/Level2")] + public static void SetStage2() + { + SetStage(StageEnum.Level2); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Game Schedule/StagingManager.cs.meta b/Assets/Scripts/Game Schedule/StagingManager.cs.meta new file mode 100644 index 0000000..4c6a677 --- /dev/null +++ b/Assets/Scripts/Game Schedule/StagingManager.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 892330fb84d24d79b298b2fa65e8e92f +timeCreated: 1723894601 \ No newline at end of file