Basic staging utility

This commit is contained in:
Khauvinkh 2024-08-17 13:59:08 +02:00
parent 87a0195f91
commit 8740952493
5 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 71cc283a7f7c45649d6fabee033bce4a
timeCreated: 1723894561

View File

@ -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);
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 71cd04e41258435d9d03d9b67cb4b7ed
timeCreated: 1723894689

View File

@ -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<StageProp> 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<StageProp>();
}
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);
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 892330fb84d24d79b298b2fa65e8e92f
timeCreated: 1723894601