refactor(fix-system): BodyModule 持久化从 IData 改为显式快照
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user