chore: initial commit
This commit is contained in:
42
Assets/Scripts/VFX/HitFXSpawner.cs
Normal file
42
Assets/Scripts/VFX/HitFXSpawner.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Combat;
|
||||
|
||||
namespace BaseGames.VFX
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局命中特效派发器:订阅 HitConfirmedEventChannel,
|
||||
/// 根据 DamageInfo.FxType 从 VFXCatalog 查找并播放特效。
|
||||
/// 放置在 Persistent 场景的 [Systems] GameObject 上。
|
||||
/// </summary>
|
||||
public class HitFXSpawner : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private HitConfirmedEventChannelSO _onHitConfirmed;
|
||||
[SerializeField] private VFXCatalogSO _catalog;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_catalog != null)
|
||||
_catalog.Initialize();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_onHitConfirmed != null)
|
||||
_onHitConfirmed.OnEventRaised += HandleHit;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (_onHitConfirmed != null)
|
||||
_onHitConfirmed.OnEventRaised -= HandleHit;
|
||||
}
|
||||
|
||||
private void HandleHit(HitInfo info)
|
||||
{
|
||||
if (_catalog == null || VFXPool.Instance == null) return;
|
||||
|
||||
if (_catalog.TryGetHitFX(info.DamageInfo.FxType, out var vfxRef))
|
||||
VFXPool.Instance.Play(vfxRef, info.HitPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user