67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.AddressableAssets;
|
||
using BaseGames.Combat;
|
||
|
||
namespace BaseGames.VFX
|
||
{
|
||
/// <summary>
|
||
/// VFX 资产映射字典:HitFxType → VFX Prefab Addressable 引用。
|
||
/// 在 GameManager.OnGameplayStarted 中调用 Initialize() 建立快速查表。
|
||
/// 资产路径:Assets/ScriptableObjects/VFX/VFX_Catalog.asset
|
||
/// </summary>
|
||
[CreateAssetMenu(menuName = "VFX/VFXCatalog")]
|
||
public class VFXCatalogSO : ScriptableObject
|
||
{
|
||
[Header("命中特效映射")]
|
||
public VFXEntry[] hitEffects;
|
||
|
||
[Header("预热配置")]
|
||
public VFXWarmupEntry[] warmups;
|
||
|
||
private Dictionary<HitFxType, AssetReferenceGameObject> _map;
|
||
|
||
/// <summary>建立快速查表字典。在 Gameplay 开始前调用一次。</summary>
|
||
public void Initialize()
|
||
{
|
||
_map = new Dictionary<HitFxType, AssetReferenceGameObject>();
|
||
if (hitEffects == null) return;
|
||
foreach (var e in hitEffects)
|
||
_map[e.type] = e.vfxRef;
|
||
}
|
||
|
||
/// <summary>根据 HitFxType 查找对应 VFX Prefab 引用。</summary>
|
||
public bool TryGetHitFX(HitFxType type, out AssetReferenceGameObject vfxRef)
|
||
{
|
||
if (_map != null)
|
||
return _map.TryGetValue(type, out vfxRef);
|
||
|
||
// 未初始化时回退至线性查找
|
||
if (hitEffects != null)
|
||
{
|
||
foreach (var e in hitEffects)
|
||
{
|
||
if (e.type == type) { vfxRef = e.vfxRef; return true; }
|
||
}
|
||
}
|
||
vfxRef = default;
|
||
return false;
|
||
}
|
||
}
|
||
|
||
[Serializable]
|
||
public struct VFXEntry
|
||
{
|
||
public HitFxType type;
|
||
public AssetReferenceGameObject vfxRef;
|
||
}
|
||
|
||
[Serializable]
|
||
public struct VFXWarmupEntry
|
||
{
|
||
public AssetReferenceGameObject vfxRef;
|
||
[Min(1)] public int warmupCount;
|
||
}
|
||
}
|