UI系统优化
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using BaseGames.Player;
|
||||
using BaseGames.Input;
|
||||
using BaseGames.Feedback;
|
||||
using BaseGames.Core;
|
||||
|
||||
namespace BaseGames.Spells
|
||||
{
|
||||
@@ -12,7 +14,7 @@ namespace BaseGames.Spells
|
||||
///
|
||||
/// 输入事件:订阅 InputReaderSO.SpellCastEvent(对应 InputActionAsset 中的 "Spell" Action)。
|
||||
/// </summary>
|
||||
public class SpellManager : MonoBehaviour
|
||||
public class SpellManager : MonoBehaviour, ISpellService
|
||||
{
|
||||
[Header("依赖引用")]
|
||||
[SerializeField] private PlayerStats _stats;
|
||||
@@ -27,6 +29,10 @@ namespace BaseGames.Spells
|
||||
private float _cooldownRemaining;
|
||||
private IFeedbackPlayer _feedback;
|
||||
|
||||
// ── ISpellService 事件 ────────────────────────────────────────────────
|
||||
/// <inheritdoc/>
|
||||
public event Action<SpellSO> OnSpellChanged;
|
||||
|
||||
// ── 生命周期 ──────────────────────────────────────────────────────────
|
||||
|
||||
private void Awake()
|
||||
@@ -38,12 +44,14 @@ namespace BaseGames.Spells
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
ServiceLocator.Register<ISpellService>(this);
|
||||
if (_input != null)
|
||||
_input.SpellCastEvent += TryCastSpell;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ServiceLocator.Unregister<ISpellService>(this);
|
||||
if (_input != null)
|
||||
_input.SpellCastEvent -= TryCastSpell;
|
||||
}
|
||||
@@ -61,6 +69,7 @@ namespace BaseGames.Spells
|
||||
{
|
||||
_equippedSpell = spell;
|
||||
_cooldownRemaining = 0f;
|
||||
OnSpellChanged?.Invoke(spell);
|
||||
}
|
||||
|
||||
/// <summary>卸下当前装备的法术。</summary>
|
||||
@@ -68,6 +77,7 @@ namespace BaseGames.Spells
|
||||
{
|
||||
_equippedSpell = null;
|
||||
_cooldownRemaining = 0f;
|
||||
OnSpellChanged?.Invoke(null);
|
||||
}
|
||||
|
||||
/// <summary>返回当前冷却进度(0 = 就绪,1 = 刚施放)。供 UI 血条使用。</summary>
|
||||
|
||||
Reference in New Issue
Block a user