You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
311 lines
8.3 KiB
311 lines
8.3 KiB
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<MainControl>
|
|
{
|
|
|
|
|
|
public GameState state;
|
|
|
|
public MainState mainState = MainState.Idle;
|
|
private StateMachine<MainState> fsm;
|
|
private GameStateConfig stateConfig;
|
|
|
|
/// <summary>
|
|
/// 是否读取文件配置
|
|
/// </summary>
|
|
public bool isReadConfig;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
if(isReadConfig)
|
|
ReadGameConfig();
|
|
else
|
|
{
|
|
fsm = StateMachine<MainState>.Initialize(this, MainState.Idle);
|
|
}
|
|
}
|
|
|
|
|
|
bool isReadData;
|
|
/// <summary>
|
|
/// 读取配置文件
|
|
/// </summary>
|
|
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<GameStateConfig>(webGLConfiguratiobReader.ReadResult);
|
|
if(stateConfig.GameState == GameState.Load.ToString())
|
|
{
|
|
state = GameState.Load;
|
|
}else
|
|
{
|
|
state = GameState.Unload;
|
|
}
|
|
isReadData = false;
|
|
fsm = StateMachine<MainState>.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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 改变状态
|
|
/// </summary>
|
|
/// <param name="state"></param>
|
|
public void SetGameState(MainState state)
|
|
{
|
|
mainState = state;
|
|
fsm.ChangeState(mainState);
|
|
}
|
|
|
|
#region === 状态机接口实例 ===
|
|
|
|
private void Idle_Enter()
|
|
{
|
|
TTUIPage.ShowPage<MainMenuView>();
|
|
TTUIPage.ShowPage<TipView>();
|
|
TTUIPage.ShowPage<IdleView>();
|
|
|
|
}
|
|
|
|
private void Idle_Update()
|
|
{
|
|
|
|
}
|
|
|
|
private void Idle_Exit()
|
|
{
|
|
//Debug.LogFormat("退出待机 ");
|
|
TTUIPage.ClosePage<IdleView>();
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
/// <summary>
|
|
/// 启动游戏
|
|
/// </summary>
|
|
/// <param name="step"></param>
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 设置拆机模式
|
|
/// </summary>
|
|
/// <param name="step">0从第一步开始拆机箱</param>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置装机模式
|
|
/// </summary>
|
|
/// <param name="step">0从第一步开始装主板</param>
|
|
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
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 游戏状态配置设置
|
|
/// </summary>
|
|
public class GameStateConfig
|
|
{
|
|
public string GameState { get; set; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|