存档完善和修复

This commit is contained in:
2026-05-20 15:26:51 +08:00
parent ec633d9b79
commit 8ae2de5bcb
10 changed files with 106 additions and 41 deletions

View File

@@ -1,5 +1,7 @@
using System;
using UnityEngine;
using BaseGames.Core;
using BaseGames.Core.Save;
using BaseGames.Core.Events;
using BaseGames.Input;
@@ -13,7 +15,7 @@ namespace BaseGames.Player
/// 3. _onSkillSetChanged SO 事件SkillHUD 刷新)
/// 架构 05_PlayerModule §6。
/// </summary>
public class FormController : MonoBehaviour
public class FormController : MonoBehaviour, ISaveable
{
[Header("配置")]
[SerializeField] private FormConfigSO _config;
@@ -37,6 +39,7 @@ namespace BaseGames.Player
private void OnEnable()
{
ServiceLocator.GetOrDefault<ISaveableRegistry>()?.Register(this);
if (_input == null) return;
_input.SwitchSkyFormEvent += OnSwitchSky;
_input.SwitchEarthFormEvent += OnSwitchEarth;
@@ -45,6 +48,7 @@ namespace BaseGames.Player
private void OnDisable()
{
ServiceLocator.GetOrDefault<ISaveableRegistry>()?.Unregister(this);
if (_input == null) return;
_input.SwitchSkyFormEvent -= OnSwitchSky;
_input.SwitchEarthFormEvent -= OnSwitchEarth;
@@ -86,6 +90,31 @@ namespace BaseGames.Player
SwitchForm(form.formType);
}
// ── ISaveable ────────────────────────────────────────────────────────────
public void OnSave(SaveData data)
{
data.Player.ActiveFormId = CurrentForm?.formId;
}
public void OnLoad(SaveData data)
{
if (string.IsNullOrEmpty(data.Player.ActiveFormId) || _config?.forms == null)
{
if (_config?.forms != null && _config.forms.Length > 0)
CurrentForm = _config.forms[0];
return;
}
for (int i = 0; i < _config.forms.Length; i++)
{
if (_config.forms[i]?.formId == data.Player.ActiveFormId)
{
SwitchToFormByIndex(i);
return;
}
}
}
// ── 内部输入处理 ────────────────────────────────────────────────────────
private void OnSwitchSky() => SwitchForm(FormType.TianHun);
private void OnSwitchEarth() => SwitchForm(FormType.DiHun);