From 6cd3c00b0b1b0a76b690ad0d978ae265de43a371 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Tue, 13 Jun 2023 19:14:40 +0800 Subject: *misc --- .../Assets/Scripts/Phase/GamePhaseManager.cs | 95 ++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 WorldlineKeepers/Assets/Scripts/Phase/GamePhaseManager.cs (limited to 'WorldlineKeepers/Assets/Scripts/Phase/GamePhaseManager.cs') 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 +{ + + /// + /// 游戏最上层的状态机 + /// + public sealed class GamePhaseManager : Singleton, 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; + } + + } + +} -- cgit v1.1-26-g67d0