using System.Collections; using System.Collections.Generic; using UnityEngine; using LzFramework.UI; using LzFramework.FSM; using LzFramework; using EduCoderTool; using Newtonsoft.Json; namespace DisComputer { /* *@func 主流程控制器 * @author lz * @date 2020/05/26 */ public class MainControl : Singleton { public GameState state; public MainState mainState = MainState.Idle; private StateMachine fsm; private GameStateConfig stateConfig; /// /// 是否读取文件配置 /// public bool isReadConfig; // Start is called before the first frame update void Start() { if(isReadConfig) ReadGameConfig(); else { fsm = StateMachine.Initialize(this, MainState.Idle); } } bool isReadData; /// /// 读取配置文件 /// void ReadGameConfig() { isReadData = true; WebGLConfiguratiobReader webGLConfiguratiobReader = new WebGLConfiguratiobReader("Config/gameState.json"); CoroutineManager.Singleton.CreateCoroutine(webGLConfiguratiobReader.ReadCoroutine(), () => { Debug.LogFormat("On Start"); }, (finish) => { Debug.LogFormat("On Finish"); stateConfig = JsonConvert.DeserializeObject(webGLConfiguratiobReader.ReadResult); if(stateConfig.GameState == GameState.Load.ToString()) { state = GameState.Load; }else { state = GameState.Unload; } isReadData = false; fsm = StateMachine.Initialize(this, MainState.Idle); }); } private void Update() { if (Input.GetKey(KeyCode.U)&& Input.GetKeyDown(KeyCode.Alpha1)) { SetUnLoadMode(7); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha2)) { SetUnLoadMode(6); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha3)) { SetUnLoadMode(5); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha4)) { SetUnLoadMode(4); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha5)) { SetUnLoadMode(3); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha6)) { SetUnLoadMode(2); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha7)) { SetUnLoadMode(1); } if (Input.GetKey(KeyCode.U) && Input.GetKeyDown(KeyCode.Alpha8)) { SetUnLoadMode(0); } if (Input.GetKey(KeyCode.R)&&Input.GetKeyDown(KeyCode.Alpha1)) { SetLoadMode(0); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha2)) { SetLoadMode(1); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha3)) { SetLoadMode(2); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha4)) { SetLoadMode(3); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha5)) { SetLoadMode(4); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha6)) { SetLoadMode(5); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha7)) { SetLoadMode(6); } if (Input.GetKey(KeyCode.R) && Input.GetKeyDown(KeyCode.Alpha8)) { SetLoadMode(7); } } /// /// 改变状态 /// /// public void SetGameState(MainState state) { mainState = state; fsm.ChangeState(mainState); } #region === 状态机接口实例 === private void Idle_Enter() { TTUIPage.ShowPage(); TTUIPage.ShowPage(); TTUIPage.ShowPage(); } private void Idle_Update() { } private void Idle_Exit() { //Debug.LogFormat("退出待机 "); TTUIPage.ClosePage(); } private IEnumerator Active_Enter() { yield return new WaitForEndOfFrame(); //Debug.LogFormat("游戏状态"); } private void Active_Update() { //Debug.LogFormat("游戏中。。。"); } private void Active_Exit() { //Debug.LogFormat("退出游戏状态"); } private void End_Enter() { //Debug.LogFormat("进入游戏结束状态"); } private void End_Exit() { //Debug.LogFormat("退出游戏结束状态"); } #endregion /// /// 启动游戏 /// /// public void StartGame(int step) { if (isReadData) return; GameConfig.state = state; MouseControl.Instance.ClearSelectTarget(); RendereSpareControl.Instance.ClearRendererSpare(); //恢复相机视距 MouseControl.Instance.RewindCameraField(); MessageContainer.SendMessage("quit", this, MsgName.ModelControlShowDesktop); MessageContainer.SendMessage("", this, MsgName.MainViewClearBar); MessageContainer.SendMessage("", this, MsgName.SparePartsViewRemoveSpare); if(state == GameState.Load) { PcControl.Instance.SetLoadState(step); } else { PcControl.Instance.SetUnloadState(step); } GameConfig.curProgressIndex = step; } /// /// 设置拆机模式 /// /// 0从第一步开始拆机箱 public void SetUnLoadMode(int step) { GameConfig.state = GameState.Unload; MouseControl.Instance.ClearSelectTarget(); RendereSpareControl.Instance.ClearRendererSpare(); //恢复相机视距 MouseControl.Instance.RewindCameraField(); MessageContainer.SendMessage("quit", this, MsgName.ModelControlShowDesktop); MessageContainer.SendMessage("", this, MsgName.MainViewClearBar); MessageContainer.SendMessage("", this, MsgName.SparePartsViewRemoveSpare); PcControl.Instance.SetUnloadState(step); GameConfig.curProgressIndex = step; } /// /// 设置装机模式 /// /// 0从第一步开始装主板 public void SetLoadMode(int step) { GameConfig.state = GameState.Load; MouseControl.Instance.ClearSelectTarget(); RendereSpareControl.Instance.ClearRendererSpare(); //恢复相机视距 MouseControl.Instance.RewindCameraField(); MessageContainer.SendMessage("quit", this, MsgName.ModelControlShowDesktop); MessageContainer.SendMessage("", this, MsgName.MainViewClearBar); MessageContainer.SendMessage("", this, MsgName.SparePartsViewRemoveSpare); PcControl.Instance.SetLoadState(step); GameConfig.curProgressIndex = step; } } public enum MainState { Idle, Active, End } } /// /// 游戏状态配置设置 /// public class GameStateConfig { public string GameState { get; set; } }