refactor(fix-system): BodyModule 持久化从 IData 改为显式快照
This commit is contained in:
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEngine;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.FixSystem;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.SaveSystem;
|
||||
|
||||
@@ -25,12 +25,12 @@ namespace AibisDream.FixSystem
|
||||
|
||||
#region 系统状态
|
||||
|
||||
private readonly ModuleSystemData _data = new();
|
||||
private ModuleState _moduleState = ModuleState.Body;
|
||||
public bool inHotErr;
|
||||
private int _heatValue;
|
||||
|
||||
/// <summary>获取当前 BodyModule 分组(Body/Head)。</summary>
|
||||
public ModuleState GetCurrentModuleState() => _data.moduleState;
|
||||
public ModuleState GetCurrentModuleState() => _moduleState;
|
||||
|
||||
private int HeatValue
|
||||
{
|
||||
@@ -58,9 +58,6 @@ namespace AibisDream.FixSystem
|
||||
|
||||
private void InitComponentRefs()
|
||||
{
|
||||
// 注册数据
|
||||
DeepRepairDataRegistry.RegisterData(_data);
|
||||
|
||||
// 处理内部索引
|
||||
_bodyModuleGroup = transform.Find("Scalehandler")?.transform.Find("Body Module Group")?.gameObject;
|
||||
_headModuleGroup = transform.Find("Scalehandler")?.transform.Find("Head Module Group")?.gameObject;
|
||||
@@ -75,9 +72,39 @@ namespace AibisDream.FixSystem
|
||||
RepairSystemManager.Register(this);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
/// <summary>捕获插线模块持久状态(分组 + UF + Chip)。</summary>
|
||||
public BodyModuleSnapshotDto CaptureBodyModuleSnapshot()
|
||||
{
|
||||
DeepRepairDataRegistry.UnregisterData<ModuleSystemData>();
|
||||
var dto = new BodyModuleSnapshotDto
|
||||
{
|
||||
moduleState = _moduleState.ToString()
|
||||
};
|
||||
|
||||
var ufModule = FindBodyModuleByName("UF")?.GetComponent<UFModule>();
|
||||
ufModule?.CaptureState(dto);
|
||||
|
||||
var chipModule = FindBodyModuleByName("Color")?.GetComponent<ChipModule>();
|
||||
chipModule?.CaptureState(dto);
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
/// <summary>写回插线模块持久状态;须在 fix cue 还原之后调用。</summary>
|
||||
public void ApplyBodyModuleSnapshot(BodyModuleSnapshotDto dto)
|
||||
{
|
||||
if (dto == null) return;
|
||||
|
||||
if (!string.IsNullOrEmpty(dto.moduleState)
|
||||
&& Enum.TryParse<ModuleState>(dto.moduleState, out var moduleState))
|
||||
{
|
||||
SwitchModuleGroup(moduleState);
|
||||
}
|
||||
|
||||
var ufModule = FindBodyModuleByName("UF")?.GetComponent<UFModule>();
|
||||
ufModule?.ApplyState(dto);
|
||||
|
||||
var chipModule = FindBodyModuleByName("Color")?.GetComponent<ChipModule>();
|
||||
chipModule?.ApplyState(dto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -240,8 +267,7 @@ namespace AibisDream.FixSystem
|
||||
// 重新获取ModuleGroup
|
||||
var root = moduleState == ModuleState.Body ? _bodyModuleGroup : _headModuleGroup;
|
||||
BodyModules = root?.GetComponentsInChildren<BodyModule>().ToList();
|
||||
// 更改data
|
||||
_data.moduleState = moduleState;
|
||||
_moduleState = moduleState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -381,18 +407,6 @@ namespace AibisDream.FixSystem
|
||||
}
|
||||
}
|
||||
|
||||
[LoadIndex(2)]
|
||||
public class ModuleSystemData : IData
|
||||
{
|
||||
public ModuleState moduleState;
|
||||
|
||||
public IEnumerator Load()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Get<BodyModuleSystem>().SwitchModuleGroup(moduleState);
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
|
||||
public enum ModuleState
|
||||
{
|
||||
Body,
|
||||
|
||||
@@ -1,28 +1,15 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream;
|
||||
using AibisDream.SaveSystem;
|
||||
using System;
|
||||
|
||||
|
||||
public class ChipModule : MonoBehaviour
|
||||
{
|
||||
private GameObject _chipModule;
|
||||
|
||||
private ChipData _chipData=new ();
|
||||
private bool _isChipRemoved;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 将数据注册到数据容器内
|
||||
DeepRepairDataRegistry.RegisterData(_chipData);
|
||||
// 添加加载逻辑
|
||||
_chipData.LoadEvent += LoadData;
|
||||
_chipModule = transform.Find("Chip").gameObject;
|
||||
}
|
||||
// Start is called before the first frame update
|
||||
|
||||
|
||||
public void RemoveChipModule()
|
||||
{
|
||||
@@ -31,7 +18,7 @@ public class ChipModule : MonoBehaviour
|
||||
_chipModule.SetActive(false);
|
||||
}
|
||||
|
||||
_chipData.isChipRemoved = true;
|
||||
_isChipRemoved = true;
|
||||
}
|
||||
|
||||
public void InstallChipModule()
|
||||
@@ -41,35 +28,29 @@ public class ChipModule : MonoBehaviour
|
||||
_chipModule.SetActive(true);
|
||||
}
|
||||
|
||||
_chipData.isChipRemoved = false;
|
||||
_isChipRemoved = false;
|
||||
}
|
||||
|
||||
public void CaptureState(BodyModuleSnapshotDto dto)
|
||||
{
|
||||
if (dto == null) return;
|
||||
dto.isChipRemoved = _isChipRemoved;
|
||||
}
|
||||
|
||||
public void ApplyState(BodyModuleSnapshotDto dto)
|
||||
{
|
||||
if (dto == null) return;
|
||||
_isChipRemoved = dto.isChipRemoved;
|
||||
Chipinit();
|
||||
}
|
||||
|
||||
public void Chipinit()
|
||||
{
|
||||
_chipModule.SetActive(!_chipData.isChipRemoved);
|
||||
_chipModule.SetActive(!_isChipRemoved);
|
||||
}
|
||||
|
||||
|
||||
private void LoadData(ChipData ufData)
|
||||
{
|
||||
Chipinit(); // 读取存档文件时触发,将当前系统恢复为目标状态
|
||||
}
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
Chipinit();
|
||||
}
|
||||
}
|
||||
|
||||
public class ChipData : IData
|
||||
{
|
||||
public bool isChipRemoved = false;
|
||||
|
||||
public event Action<ChipData> LoadEvent;
|
||||
|
||||
public IEnumerator Load()
|
||||
{
|
||||
LoadEvent?.Invoke(this);
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,19 @@
|
||||
using UnityEngine;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream;
|
||||
using AibisDream.SaveSystem;
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
public class UFModule : MonoBehaviour
|
||||
{
|
||||
private GameObject _ufCover;
|
||||
private GameObject _ufModule;
|
||||
|
||||
private GameObject _ufSocket;
|
||||
|
||||
private GameObject _ufColor;
|
||||
private UFData _ufData = new();
|
||||
|
||||
private bool _isUFCoverRemoved;
|
||||
private bool _isUFRemoved;
|
||||
private bool _isColorRemoved;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 将数据注册到数据容器内
|
||||
DeepRepairDataRegistry.RegisterData(_ufData);
|
||||
// 添加加载逻辑
|
||||
_ufData.LoadEvent += LoadData;
|
||||
_ufModule = transform.Find("Module Pic").gameObject;
|
||||
_ufSocket = transform.Find("Socket").gameObject;
|
||||
_ufCover = _ufModule.transform.Find("Cover").gameObject;
|
||||
@@ -34,7 +27,7 @@ public class UFModule : MonoBehaviour
|
||||
_ufCover.SetActive(false);
|
||||
}
|
||||
|
||||
_ufData.isUFCoverRemoved = true;
|
||||
_isUFCoverRemoved = true;
|
||||
}
|
||||
|
||||
public void RemoveUFModule()
|
||||
@@ -43,10 +36,9 @@ public class UFModule : MonoBehaviour
|
||||
{
|
||||
_ufModule.SetActive(false);
|
||||
_ufSocket.SetActive(false);
|
||||
|
||||
}
|
||||
|
||||
_ufData.isUFRemoved = true;
|
||||
_isUFRemoved = true;
|
||||
}
|
||||
|
||||
public void InstallUFCover()
|
||||
@@ -56,7 +48,7 @@ public class UFModule : MonoBehaviour
|
||||
_ufCover.SetActive(true);
|
||||
}
|
||||
|
||||
_ufData.isUFCoverRemoved = false;
|
||||
_isUFCoverRemoved = false;
|
||||
}
|
||||
|
||||
public void InstallUFModule()
|
||||
@@ -67,8 +59,9 @@ public class UFModule : MonoBehaviour
|
||||
_ufSocket.SetActive(true);
|
||||
}
|
||||
|
||||
_ufData.isUFRemoved = false;
|
||||
_isUFRemoved = false;
|
||||
}
|
||||
|
||||
public void InstallUFColor()
|
||||
{
|
||||
if (!_ufColor.activeInHierarchy)
|
||||
@@ -76,8 +69,9 @@ public class UFModule : MonoBehaviour
|
||||
_ufColor.SetActive(true);
|
||||
}
|
||||
|
||||
_ufData.isColorRemoved = false;
|
||||
_isColorRemoved = false;
|
||||
}
|
||||
|
||||
public void RemoveUFColor()
|
||||
{
|
||||
if (_ufColor.activeInHierarchy)
|
||||
@@ -85,42 +79,36 @@ public class UFModule : MonoBehaviour
|
||||
_ufColor.SetActive(false);
|
||||
}
|
||||
|
||||
_ufData.isColorRemoved = true;
|
||||
_isColorRemoved = true;
|
||||
}
|
||||
|
||||
public void CaptureState(BodyModuleSnapshotDto dto)
|
||||
{
|
||||
if (dto == null) return;
|
||||
dto.isUFCoverRemoved = _isUFCoverRemoved;
|
||||
dto.isUFRemoved = _isUFRemoved;
|
||||
dto.isColorRemoved = _isColorRemoved;
|
||||
}
|
||||
|
||||
public void ApplyState(BodyModuleSnapshotDto dto)
|
||||
{
|
||||
if (dto == null) return;
|
||||
_isUFCoverRemoved = dto.isUFCoverRemoved;
|
||||
_isUFRemoved = dto.isUFRemoved;
|
||||
_isColorRemoved = dto.isColorRemoved;
|
||||
UFinit();
|
||||
}
|
||||
|
||||
public void UFinit()
|
||||
{
|
||||
_ufModule.SetActive(!_ufData.isUFRemoved);
|
||||
_ufSocket.SetActive(!_ufData.isUFRemoved);
|
||||
_ufCover.SetActive(!_ufData.isUFCoverRemoved);
|
||||
_ufColor.SetActive(!_ufData.isColorRemoved);
|
||||
_ufModule.SetActive(!_isUFRemoved);
|
||||
_ufSocket.SetActive(!_isUFRemoved);
|
||||
_ufCover.SetActive(!_isUFCoverRemoved);
|
||||
_ufColor.SetActive(!_isColorRemoved);
|
||||
}
|
||||
|
||||
|
||||
private void LoadData(UFData ufData)
|
||||
{
|
||||
UFinit(); // 读取存档文件时触发,将当前系统恢复为目标状态
|
||||
}
|
||||
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
UFinit();
|
||||
}
|
||||
}
|
||||
|
||||
public class UFData : IData
|
||||
{
|
||||
public bool isUFCoverRemoved = false;
|
||||
public bool isUFRemoved = false;
|
||||
|
||||
public bool isColorRemoved = false;
|
||||
|
||||
public event Action<UFData> LoadEvent;
|
||||
|
||||
public IEnumerator Load()
|
||||
{
|
||||
LoadEvent?.Invoke(this);
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.SaveSystem;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
@@ -14,8 +13,6 @@ namespace AibisDream.FixSystem
|
||||
|
||||
public FixSceneMode defaultMode = FixSceneMode.Default;
|
||||
|
||||
private readonly FixSystemData _data = new();
|
||||
|
||||
public static IOCContainer SystemDic = new();
|
||||
public static FixSceneContext Context;
|
||||
public static FixSceneDirector Director;
|
||||
@@ -24,14 +21,12 @@ namespace AibisDream.FixSystem
|
||||
{
|
||||
SystemDic ??= new IOCContainer();
|
||||
Context = new FixSceneContext(SystemDic);
|
||||
Director = new FixSceneDirector(_data);
|
||||
Director = new FixSceneDirector();
|
||||
StartCoroutine(Director.Init(defaultMode));
|
||||
DeepRepairDataRegistry.RegisterData(_data);
|
||||
}
|
||||
|
||||
public override void OnSingletonDestroy()
|
||||
{
|
||||
DeepRepairDataRegistry.UnregisterData<FixSystemData>();
|
||||
CameraKit.Instance.RemoveAllCam();
|
||||
BubbleSlotKit.Instance.RemoveAll();
|
||||
GameManager.Instance.StartCoroutine(Director.QuitCurrentMode());
|
||||
@@ -48,21 +43,13 @@ namespace AibisDream.FixSystem
|
||||
yield return Director.TransitionToImmediate(nextMode, args);
|
||||
}
|
||||
|
||||
/// <summary>Captures the macro Fix scene snapshot.</summary>
|
||||
/// <summary>Captures the macro Fix scene cue snapshot.</summary>
|
||||
public FixSnapshotDto CaptureSnapshot()
|
||||
{
|
||||
var bodyModule = SystemDic.Get<BodyModuleSystem>();
|
||||
var eyeSystem = SystemDic.Get<EyeSystem>();
|
||||
var repairManager = RepairSystemManager.Instance;
|
||||
|
||||
return new FixSnapshotDto
|
||||
{
|
||||
state = Director.CurrentMode.ToString(),
|
||||
args = _data.args,
|
||||
moduleState = bodyModule?.GetCurrentModuleState().ToString(),
|
||||
eyeColorState = eyeSystem?.GetCurrentColorState().ToString(),
|
||||
isSystemOn = FixPanelSystem.Instance?.IsSystemOn ?? false,
|
||||
currentRepairSystemType = repairManager?.GetCurrentSystemType()?.Name
|
||||
args = Director.CurrentArgs
|
||||
};
|
||||
}
|
||||
|
||||
@@ -83,18 +70,4 @@ namespace AibisDream.FixSystem
|
||||
yield return Director.TransitionToImmediate(mode, dto.args ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[LoadIndex(2)]
|
||||
public class FixSystemData : IData
|
||||
{
|
||||
[FormerlySerializedAs("curState")]
|
||||
public FixSceneMode curMode;
|
||||
public string args;
|
||||
|
||||
public IEnumerator Load()
|
||||
{
|
||||
yield return FixSystemCenter.Director.TransitionTo(curMode, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user