存档完善和修复
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user