多轮审查和修复
This commit is contained in:
@@ -1,7 +1,71 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Player
|
||||
{
|
||||
/// <summary>形态控制器。Phase 1 桩 — Phase 2 实现。</summary>
|
||||
public class FormController : MonoBehaviour { }
|
||||
/// <summary>
|
||||
/// 形态控制器。
|
||||
/// 管理天魂/地魂/命魂三形态切换,依次触发:
|
||||
/// 1. _onFormChanged SO 事件(UI/Save 用)
|
||||
/// 2. OnFormChanged C# 事件(WeaponManager 订阅)
|
||||
/// 3. _onSkillSetChanged SO 事件(SkillHUD 刷新)
|
||||
/// 架构 05_PlayerModule §6。
|
||||
/// </summary>
|
||||
public class FormController : MonoBehaviour
|
||||
{
|
||||
[Header("配置")]
|
||||
[SerializeField] private FormConfigSO _config;
|
||||
|
||||
[Header("事件频道")]
|
||||
[SerializeField] private IntEventChannelSO _onFormChanged; // 广播当前形态索引(UI/Save)
|
||||
[SerializeField] private VoidEventChannelSO _onSkillSetChanged; // 通知 SkillHUD 刷新
|
||||
|
||||
// ── 运行时 ─────────────────────────────────────────────────────────────
|
||||
public FormSO CurrentForm { get; private set; }
|
||||
public FormSO[] AllForms => _config.forms;
|
||||
|
||||
/// <summary>C# 事件,WeaponManager 在 OnEnable 自订阅(架构 05 §6)。</summary>
|
||||
public event Action OnFormChanged;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Debug.Assert(_config != null, "[FormController] _config 未赋值,请在 Inspector 中指定 FormConfigSO。", this);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (_config.forms != null && _config.forms.Length > 0)
|
||||
CurrentForm = _config.forms[0];
|
||||
}
|
||||
|
||||
// ── 公共 API ────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>切换到指定形态类型。若已在目标形态则不操作。</summary>
|
||||
public void SwitchForm(FormType newFormType)
|
||||
{
|
||||
FormSO newForm = _config.GetFormByType(newFormType);
|
||||
if (newForm == null || newForm == CurrentForm) return;
|
||||
|
||||
CurrentForm = newForm;
|
||||
|
||||
// 1. SO 事件广播索引(UI/Save)
|
||||
_onFormChanged?.Raise(_config.GetFormIndex(newForm));
|
||||
|
||||
// 2. C# 事件(WeaponManager 等订阅者)
|
||||
OnFormChanged?.Invoke();
|
||||
|
||||
// 3. SkillHUD 刷新事件
|
||||
_onSkillSetChanged?.Raise();
|
||||
}
|
||||
|
||||
/// <summary>通过数组索引切换形态。</summary>
|
||||
public void SwitchToFormByIndex(int index)
|
||||
{
|
||||
if (_config?.forms == null || index < 0 || index >= _config.forms.Length) return;
|
||||
var form = _config.forms[index];
|
||||
if (form != null)
|
||||
SwitchForm(form.formType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user