refactor(fix-system): FixPanel 与 Cable 迁移为显式快照
This commit is contained in:
@@ -94,6 +94,32 @@ namespace AibisDream.FixSystem
|
||||
OnPullUpSocket?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>读档/静默:仅恢复插头精灵可见,不触发 CablePanel 事件。</summary>
|
||||
public void PullUpSocketSilent()
|
||||
{
|
||||
_sprite.enabled = true;
|
||||
}
|
||||
|
||||
/// <summary>读档:无动画回到初始位。</summary>
|
||||
public void RestoreAtStartPositionImmediate()
|
||||
{
|
||||
transform.rotation = _defaultRotation;
|
||||
transform.position = _startPos;
|
||||
}
|
||||
|
||||
/// <summary>读档:无动画插入指定 socket 的视觉终态。</summary>
|
||||
public void RestoreInsertedAt(Transform socketPos)
|
||||
{
|
||||
if (socketPos == null) return;
|
||||
transform.position = socketPos.position;
|
||||
_sprite.enabled = false;
|
||||
}
|
||||
|
||||
public void SetSpriteVisible(bool visible)
|
||||
{
|
||||
_sprite.enabled = visible;
|
||||
}
|
||||
|
||||
private void OnDrag(BaseEventData eventData)
|
||||
{
|
||||
if (!_isDragging) return;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.SaveSystem;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using DG.Tweening;
|
||||
@@ -125,6 +126,67 @@ namespace AibisDream.FixSystem
|
||||
|
||||
#endregion
|
||||
|
||||
#region 快照 Capture / Restore
|
||||
|
||||
public FixPanelSnapshotDto CapturePanelSnapshot()
|
||||
{
|
||||
var cablePanel = GetRepairPanel<CablePanel>();
|
||||
var dto = new FixPanelSnapshotDto
|
||||
{
|
||||
isSystemOn = isSystemOn,
|
||||
currentRepairSystemType = repairSystemManager?.GetCurrentSystemType()?.Name,
|
||||
isCableRetracted = cablePanel != null && cablePanel.isCableRetracted
|
||||
};
|
||||
|
||||
if (cablePanel != null && cablePanel.TryGetPluggedModuleName(out var moduleName))
|
||||
{
|
||||
dto.pluggedModuleName = moduleName;
|
||||
}
|
||||
|
||||
if (dto.isCableRetracted && !string.IsNullOrEmpty(dto.pluggedModuleName))
|
||||
{
|
||||
Debug.LogWarning("[FixPanelSystem] Capture: isCableRetracted 与 pluggedModuleName 冲突,忽略 pluggedModuleName。");
|
||||
dto.pluggedModuleName = null;
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
public void ApplyPanelSnapshot(FixPanelSnapshotDto dto)
|
||||
{
|
||||
if (dto == null) return;
|
||||
|
||||
ApplySystemOnImmediate(dto.isSystemOn);
|
||||
|
||||
if (repairSystemManager != null)
|
||||
{
|
||||
repairSystemManager.RestoreSystemType(dto.currentRepairSystemType);
|
||||
}
|
||||
|
||||
GetRepairPanel<CablePanel>()?.ApplyCableSnapshot(dto.isCableRetracted, dto.pluggedModuleName);
|
||||
}
|
||||
|
||||
/// <summary>读档终态:跳过 StartAllSystems 动画,直接写面板壳层状态。</summary>
|
||||
public void ApplySystemOnImmediate(bool isOn)
|
||||
{
|
||||
isSystemOn = isOn;
|
||||
|
||||
if (panelLight != null)
|
||||
{
|
||||
panelLight.Initialize(isOn);
|
||||
}
|
||||
|
||||
var cablePanel = GetRepairPanel<CablePanel>();
|
||||
cablePanel?.InitLight(isOn);
|
||||
|
||||
if (screenPanel != null)
|
||||
{
|
||||
screenPanel.gameObject.SetActive(isOn);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 屏幕相关操作
|
||||
[Header("默认画布")]
|
||||
[SerializeField] private Canvas canvas;
|
||||
|
||||
@@ -212,6 +212,37 @@ namespace AibisDream.FixSystem
|
||||
: null;
|
||||
}
|
||||
|
||||
/// <summary>读档:按已注册类型名切换中央维修视图(无动画)。</summary>
|
||||
public void RestoreSystemType(string typeName)
|
||||
{
|
||||
Type targetType = typeof(BodyModuleSystem);
|
||||
|
||||
if (!string.IsNullOrEmpty(typeName))
|
||||
{
|
||||
Type matched = null;
|
||||
foreach (var kv in _registeredSystems)
|
||||
{
|
||||
if (kv.Key.Name == typeName)
|
||||
{
|
||||
matched = kv.Key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (matched != null)
|
||||
{
|
||||
targetType = matched;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"[RepairSystemManager] 未找到已注册系统: {typeName},保持当前类型。");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SwitchSystem(targetType);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace AibisDream.FixSystem
|
||||
|
||||
public class CablePanel : MonoBehaviour, IOperatorPanel
|
||||
{
|
||||
private const string CableRetractedKey = "$global.cableRetracted";
|
||||
private const int SortingOrderRetracted = 41;
|
||||
|
||||
#region 组件索引
|
||||
@@ -52,9 +51,8 @@ namespace AibisDream.FixSystem
|
||||
private void Start()
|
||||
{
|
||||
InitComponentRefs();
|
||||
|
||||
InitSystem();
|
||||
LoadCableState();
|
||||
InitCableVisualFromPrefab();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -82,37 +80,90 @@ namespace AibisDream.FixSystem
|
||||
plugRef.OnPlugPointerDown += OnPlugPoinerDown;
|
||||
}
|
||||
|
||||
private void LoadCableState()
|
||||
private void InitCableVisualFromPrefab()
|
||||
{
|
||||
// 从Prefab读取
|
||||
if (isCableRetracted)
|
||||
{
|
||||
SetRetractCable();
|
||||
}
|
||||
else
|
||||
{
|
||||
PlugRef.ReturnToStartPosition();
|
||||
}
|
||||
|
||||
// 从存储系统读取
|
||||
if (!YarnVariableStorage.Instance.TryGetValue(CableRetractedKey, out bool savedRetractedState))
|
||||
return;
|
||||
|
||||
if (savedRetractedState)
|
||||
{
|
||||
SetRetractCable();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isCableRetracted)
|
||||
DropDownCable();
|
||||
DropDownCableImmediate();
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveCableState()
|
||||
public bool TryGetPluggedModuleName(out string moduleName)
|
||||
{
|
||||
Debug.Log("Save cableRetractedstate" + isCableRetracted);
|
||||
YarnVariableStorage.Instance.SetValue(CableRetractedKey, isCableRetracted);
|
||||
if (curSocket is BodyModule bodyModule)
|
||||
{
|
||||
moduleName = bodyModule.data.moduleName;
|
||||
return !string.IsNullOrEmpty(moduleName);
|
||||
}
|
||||
|
||||
moduleName = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>读档:同步写回线缆与插头终态,无动画、无 Yarn、无 PlugIn 事件。</summary>
|
||||
public void ApplyCableSnapshot(bool retracted, string pluggedModuleName)
|
||||
{
|
||||
SilentPullUpSocket();
|
||||
|
||||
if (retracted)
|
||||
{
|
||||
SetRetractCable();
|
||||
curSocket = null;
|
||||
return;
|
||||
}
|
||||
|
||||
DropDownCableImmediate();
|
||||
|
||||
if (!string.IsNullOrEmpty(pluggedModuleName))
|
||||
{
|
||||
RestorePlugToModule(pluggedModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
curSocket = null;
|
||||
SetCableMode(CableMode.Physic);
|
||||
}
|
||||
}
|
||||
|
||||
public void DropDownCableImmediate()
|
||||
{
|
||||
PlugRef.PullUpSocketSilent();
|
||||
CableReelRef.ResetRotation();
|
||||
PlugRef.RestoreAtStartPositionImmediate();
|
||||
SetCableMode(CableMode.Physic);
|
||||
isCableRetracted = false;
|
||||
}
|
||||
|
||||
private void RestorePlugToModule(string moduleName)
|
||||
{
|
||||
var module = BodyModuleSystem?.FindBodyModuleByName(moduleName);
|
||||
if (module == null)
|
||||
{
|
||||
Debug.LogWarning($"[CablePanel] RestorePlugToModule: 未找到模块 {moduleName},插头留在初始位。");
|
||||
curSocket = null;
|
||||
SetCableMode(CableMode.Physic);
|
||||
return;
|
||||
}
|
||||
|
||||
curSocket = module;
|
||||
var socketPos = module.GetSocketPos();
|
||||
PlugRef.RestoreInsertedAt(socketPos);
|
||||
CableRef.SetEndPos(socketPos);
|
||||
BodyModuleSystem.CloseModuleSlots(null);
|
||||
}
|
||||
|
||||
private void SilentPullUpSocket()
|
||||
{
|
||||
if (curSocket == null) return;
|
||||
|
||||
CableRef.SetEndPos(PlugRef.PlugRoot);
|
||||
curSocket.PlugOut();
|
||||
curSocket = null;
|
||||
PlugRef.SetSpriteVisible(true);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -245,7 +296,6 @@ namespace AibisDream.FixSystem
|
||||
{
|
||||
ApplyRetractedState();
|
||||
isCableRetracted = true;
|
||||
SaveCableState();
|
||||
});
|
||||
|
||||
AudioManager.Instance.PlaySfx("event:/ActionFB/mods_close");
|
||||
@@ -262,7 +312,6 @@ namespace AibisDream.FixSystem
|
||||
{
|
||||
SetCableMode(CableMode.Physic);
|
||||
isCableRetracted = false;
|
||||
SaveCableState();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user