diff options
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/Phase/GamePhaseManager.cs')
-rw-r--r-- | WorldlineKeepers/Assets/Scripts/Phase/GamePhaseManager.cs | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Phase/GamePhaseManager.cs b/WorldlineKeepers/Assets/Scripts/Phase/GamePhaseManager.cs new file mode 100644 index 0000000..bb63732 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Phase/GamePhaseManager.cs @@ -0,0 +1,95 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEditorInternal; +using UnityEngine; +using WK.Tools; + +namespace WK +{ + + /// <summary> + /// 游戏最上层的状态机 + /// </summary> + public sealed class GamePhaseManager : Singleton<GamePhaseManager>, ISubsystem + { + private AsyncStatemachine m_Statemachine; + private int[] phases = new int[(int)EGamePhase.Num]; + private EGamePhase prevPhase = EGamePhase.Launch; + private EGamePhase curPhase = EGamePhase.Launch; + + public void OnAwake() + { + SetupGamePhases(); + + } + + private void SetupGamePhases() + { + m_Statemachine = new AsyncStatemachine(); + + phases[(int)EGamePhase.Launch] = m_Statemachine.RegisterState(new GamePhase_Launch()); + phases[(int)EGamePhase.Main] = m_Statemachine.RegisterState(new GamePhase_Main()); + phases[(int)EGamePhase.Battle] = m_Statemachine.RegisterState(new GamePhase_Battle()); + phases[(int)EGamePhase.Dojo] = m_Statemachine.RegisterState(new GamePhase_Dojo()); + + m_Statemachine.Start(phases[(int)EGamePhase.Launch]); + } + + public void OnStart() + { + } + + public void OnUpdate() + { + m_Statemachine.Update(Time.deltaTime); + } + + public void OnFixedUpdate() + { + } + + public void OnDestroy() + { + } + + public void OnApplicationPause() + { + } + + public void OnApplicationQuit() + { + } + + public void AsyncLoadPhase(EGamePhase phase, bool forceLoad = false, AsyncStatemachine.LoadStateComplete loadStateComplete = null) + { + int curRunPhase = m_Statemachine.GetCurStateID(); + if (!forceLoad && curRunPhase == phases[(int)phase]) + { + if (null != loadStateComplete) + { + loadStateComplete(); + } + return; + } + + //LogHelper.LogEditorError("==> PhaseChange:" + curPhase + " --> " + (EGamePhase)phase); + + prevPhase = curPhase; + curPhase = phase; + m_Statemachine.GotoState(phases[(int)phase], false, forceLoad, loadStateComplete); + } + + public EGamePhase GetCurPhase() + { + return curPhase; + } + + public EGamePhase GetPrevPhase() + { + return prevPhase; + } + + } + +} |