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