//启动时调用 void Start() { UIController = GetComponent <GameUIController>(); gm = GetComponent <GameManager>(); //初始化GameManager静态实例gm mainCamera = Camera.main; //获取摄像机 stateMachineMap = new Dictionary <string, BaseGLStateMachine>(); gameStateQueue = new Queue <string>(); playerCustomProperties = new ExitGames.Client.Photon.Hashtable { { "Score", 0 }, { "Death", 0 } }; //初始化玩家得分 PhotonNetwork.player.SetCustomProperties(playerCustomProperties); //初始化队伍得分 currentScoreOfAttackerTeam = 0; currentScoreOfDefenderTeam = 0; //初始化状态机映射和队列 initStateMachineMapAndQueue(); //将队列首的状态机设置为当前状态机 curGLStatetMachine = stateMachineMap[gameStateQueue.Peek()]; curGLStatetMachine.Enter(); m_gameResult = GameResult.none; winTeam = null; #if (!UNITY_ANDROID) UIController.setCursorState(lockCursor); #endif }
void stateMachineChangeForce(string stateMachineName) { if (stateMachineName == null || stateMachineName == "") { return; } gameStateQueue.Clear(); //清空队列 if (curGLStatetMachine != null) { curGLStatetMachine.Exit(); } curGLStatetMachine = stateMachineMap[stateMachineName]; if (curGLStatetMachine != null) { curGLStatetMachine.Enter();//强制执行新的状态机 } }
void stateMachineChange() { if (curGLStatetMachine != null) { gameStateQueue.Dequeue(); //当前状态机移除队列 并执行exit函数 curGLStatetMachine.Exit(); } if (gameStateQueue.Count == 0) { return; } curGLStatetMachine = stateMachineMap[gameStateQueue.Peek()]; //从队列中找到新的状态机 if (curGLStatetMachine != null) { curGLStatetMachine.Enter();//执行enter函数 } }