using Thousandto.Core.Base; using Thousandto.Core.Support; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using FLogger = UnityEngine.Gonbest.MagicCube.FLogger; namespace Thousandto.Code.Logic { /// /// 游戏状态系统 /// public class GameStateSystem: BaseStateSystem { #region//私有变量 //所有状态集合 private IGameState[] _statesCache = null; #endregion #region//继承 /// /// 初始化 /// protected override void OnInitialize() { //FLogger.DebugLog("InitGameSate"); try { _statesCache = new IGameState[(int)GameStateId.Count]; _statesCache[(int)GameStateId.PreLoad] = new PreLoadState(GameStateId.PreLoad); _statesCache[(int)GameStateId.Login] = new LoginState(GameStateId.Login); _statesCache[(int)GameStateId.SceneLoading] = new SceneLoadingState(GameStateId.SceneLoading); _statesCache[(int)GameStateId.World] = new WorldState(GameStateId.World); _statesCache[(int)GameStateId.RetToLogin] = new RetToLoginState(GameStateId.RetToLogin); _statesCache[(int)GameStateId.RetToUpdate] = new RetToUpdateState(GameStateId.RetToUpdate); for (int i = 0; i < (int)GameStateId.Count; ++i) { if (_statesCache[i] != null) { _statesCache[i].Load(); } } //最新进行资源预加载 ChangeState((int)GameStateId.PreLoad); } catch (Exception e) { FLogger.DebugLogException(e); } } /// /// 反初始化 /// protected override void OnUnInitialize() { if (Fsm != null) { Fsm.Clear(); } } /// /// 通过id获取游戏状态 /// /// /// protected override IGameState OnGetStateById(int id) { if (id < _statesCache.Length) return _statesCache[id]; return null; } /// /// 切换状态 /// /// /// protected override void OnChangeState(int stateId, object arg) { if (Fsm != null) Fsm.ChangeState(stateId, arg); } /// /// 处理状态消息 /// /// protected override void OnHandlerMessage(object msg) { if (Fsm != null) Fsm.HandlerMessage(msg); } /// /// 更新fsm /// /// protected override void OnUpdate(float dt) { if (Fsm != null) Fsm.Update(dt); } #endregion } }