using System; using System.Collections; using AibisDream.Framework; using UnityEngine; namespace AibisDream.FixSystem { public class FixStateMachine { private IState _curState; private string _curArgs; public IEnumerator SwitchState(FixState nextState, string args = "") { _curArgs = args; yield return _curState?.Exit(); GameLoopManager.Instance?.UpdateFixState(nextState, _curArgs); _curState = CreateState(nextState, _curArgs); yield return _curState.Enter(); } private static IState CreateState(FixState nextState, string args) { IState res = nextState switch { FixState.Clinic => new ClinicState(), FixState.Engine => new EngineState(), FixState.CoolingMachine => new CoolingMachineState(), FixState.BodyModule => new BodyModuleState(), FixState.Memory => new MemoryState(), FixState.Eye => new EyeState(), FixState.UF => new UfState(), FixState.Gear => new GearState(), _ => new ClinicState() }; res.SetArgs(args); return res; } } public interface IState { public FixState GetState { get; } public void SetArgs(string args); public IEnumerator Enter(); public IEnumerator Exit(); } public class ClinicState : IState { public FixState GetState => FixState.Clinic; public void SetArgs(string args) { // 无 } public IEnumerator Enter() { // 切换相机 yield return CameraKit.Instance.SwitchCamera(FixState.Clinic); } public IEnumerator Exit() { // 无 yield break; } } public class BodyModuleState : IState { public FixState GetState => FixState.BodyModule; public void SetArgs(string args) { // 无 } public IEnumerator Enter() { var bodyModuleSystem = FixSystemCenter.SystemDic.Get(); // 拔出插头 bodyModuleSystem.ResetPlug(); // 切换相机 yield return CameraKit.Instance.SwitchCamera(FixState.BodyModule); } public IEnumerator Exit() { var bodyModuleSystem = FixSystemCenter.SystemDic.Get(); // 拔出插头 bodyModuleSystem.ResetPlug(); yield break; } } public class GearState : IState { public FixState GetState => FixState.Gear; private string _configKey; public void SetArgs(string args) { _configKey = args; } public IEnumerator Enter() { // 切换相机 yield return CameraKit.Instance.SwitchCamera(FixState.Gear); // 加载关卡数据 if (!string.IsNullOrEmpty(_configKey)) { var gearSystem = FixSystemCenter.SystemDic.Get(); gearSystem.CurDataKey = _configKey; gearSystem.LoadLevel(); } } public IEnumerator Exit() { yield break; } } public class EngineState : IState { public FixState GetState => FixState.Engine; public void SetArgs(string args) { // 无 } public IEnumerator Enter() { // 切换相机 yield return CameraKit.Instance.SwitchCamera(FixState.Engine); } public IEnumerator Exit() { var bodyModuleSystem = FixSystemCenter.SystemDic.Get(); bodyModuleSystem.ResetPlug(); yield break; } } public class CoolingMachineState : IState { private bool _playLink; public FixState GetState => FixState.CoolingMachine; public void SetArgs(string args) { _playLink = !string.IsNullOrEmpty(args); } public IEnumerator Enter() { var coolingSystem = FixSystemCenter.SystemDic.Get(); // 切相机 yield return CameraKit.Instance.SwitchCamera(FixState.CoolingMachine); // 打开泵机 coolingSystem.gameObject.SetActive(true); yield return coolingSystem.OpenCoolingSystem(); // 播放插线动画 if (_playLink) { yield return coolingSystem.LinkTube(); } } public IEnumerator Exit() { var cooling = FixSystemCenter.SystemDic.Get(); yield return cooling.CloseBottleUI(); yield return cooling.CloseCoolingSystem(); yield return new WaitForSeconds(1f); } } public class UfState : IState { public FixState GetState => FixState.UF; public void SetArgs(string args) { throw new NotImplementedException(); } public IEnumerator Enter() { throw new NotImplementedException(); } public IEnumerator Exit() { throw new NotImplementedException(); } } public class EyeState : IState { public FixState GetState => FixState.Eye; public void SetArgs(string args) { throw new NotImplementedException(); } public IEnumerator Enter() { throw new NotImplementedException(); } public IEnumerator Exit() { throw new NotImplementedException(); } } public class MemoryState : IState { public FixState GetState => FixState.Memory; public void SetArgs(string args) { throw new NotImplementedException(); } public IEnumerator Enter() { throw new NotImplementedException(); } public IEnumerator Exit() { throw new NotImplementedException(); } } }