104 lines
3.0 KiB
C#
104 lines
3.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Kit;
|
|
using AibisDream.SaveSystem;
|
|
using UnityEngine;
|
|
|
|
namespace AibisDream.FixSystem
|
|
{
|
|
public class FixSystemCenter : Singleton<FixSystemCenter>
|
|
{
|
|
public FixState CurState => StateMachine.CurState;
|
|
|
|
public FixState defaultState = FixState.Default;
|
|
|
|
private readonly FixSystemData _data = new();
|
|
|
|
public override void OnSingletonInit()
|
|
{
|
|
SystemDic ??= new IOCContainer();
|
|
// 初始化状态机
|
|
StateMachine = new FixStateMachine(_data);
|
|
StartCoroutine(StateMachine.Init(defaultState));
|
|
// 注册
|
|
DeepRepairDataRegistry.RegisterData(_data);
|
|
}
|
|
|
|
public override void OnSingletonDestroy()
|
|
{
|
|
// 注销
|
|
DeepRepairDataRegistry.UnregisterData<FixSystemData>();
|
|
CameraKit.Instance.RemoveAllCam();
|
|
GameManager.Instance.StartCoroutine(StateMachine.QuitState());
|
|
SystemDic.Clear();
|
|
}
|
|
|
|
#region 系统索引
|
|
|
|
// 容纳System
|
|
public static IOCContainer SystemDic = new();
|
|
|
|
#endregion
|
|
|
|
#region 状态机相关
|
|
|
|
public static FixStateMachine StateMachine;
|
|
|
|
#endregion
|
|
|
|
#region 快照
|
|
|
|
/// <summary>捕获 Fix 场景宏观快照。</summary>
|
|
public FixSnapshotDto CaptureSnapshot()
|
|
{
|
|
var bodyModule = SystemDic.Get<BodyModuleSystem>();
|
|
var eyeSystem = SystemDic.Get<EyeSystem>();
|
|
var repairManager = RepairSystemManager.Instance;
|
|
|
|
return new FixSnapshotDto
|
|
{
|
|
state = StateMachine.CurState.ToString(),
|
|
args = _data.args,
|
|
moduleState = bodyModule?.GetCurrentModuleState().ToString(),
|
|
eyeColorState = eyeSystem?.GetCurrentColorState().ToString(),
|
|
isSystemOn = FixPanelSystem.Instance?.IsSystemOn ?? false,
|
|
currentRepairSystemType = repairManager?.GetCurrentSystemType()?.Name
|
|
};
|
|
}
|
|
|
|
/// <summary>还原 Fix 场景宏观快照。调用 EnterImmediate 跳过动画。</summary>
|
|
public IEnumerator RestoreSnapshot(FixSnapshotDto dto)
|
|
{
|
|
if (dto == null || string.IsNullOrEmpty(dto.state))
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
if (!Enum.TryParse<FixState>(dto.state, out var state))
|
|
{
|
|
Debug.LogWarning($"[FixSystemCenter] 无法解析 FixState: {dto.state}");
|
|
yield break;
|
|
}
|
|
|
|
yield return StateMachine.SwitchStateImmediate(state, dto.args ?? "");
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
[Serializable]
|
|
[LoadIndex(2)]
|
|
public class FixSystemData : IData
|
|
{
|
|
public FixState curState;
|
|
public string args;
|
|
|
|
public IEnumerator Load()
|
|
{
|
|
yield return FixSystemCenter.StateMachine.SwitchState(curState, args);
|
|
}
|
|
}
|
|
}
|
|
|