TH1/Unity/Assets/Scripts/TH1_DataAssetsScript/GridVFXInfoDataAssets.cs

124 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using UnityEngine;
using RuntimeData;
using TH1Renderer;
[Serializable]
[CreateAssetMenu(fileName = "GridVFXInfoDataAssets", menuName = "TH1 Game Data/Grid VFX Info Data Assets")]
public class GridVFXInfoDataAssets : ScriptableObject
{
[Serializable]
public class GridVFXInfo
{
[Header("基础配置")]
public GridVFXType Type;
public string DisplayName;
[Header("资源引用")]
public AnimationClip AnimClip;
public Sprite Sprite;
[Tooltip("Grid Prefab 中的子对象路径,如 'Flag', 'CommonVFX', 'Treasure', 'Skill', 'Damage', 'Hurt', 'Fog', 'Die', 'Fire'")]
public string GameObjectPath = "CommonVFX";
[Header("视觉参数")]
[Tooltip("是否使用Tint颜色Color.white表示不衰减")]
public Color TintColor = Color.white;
[Tooltip("世界空间缩放1,1,1为默认")]
public Vector3 Scale = Vector3.one;
[Header("特殊处理")]
[Tooltip("是否使用特殊Renderer如FlagGridVFXRenderer, DamageGridVFXRenderer等")]
public bool UseCustomRenderer = false;
[Tooltip("特殊Renderer的完整类名仅在UseCustomRenderer为true时使用")]
public string CustomRendererClassName = "";
[Header("音频(可选)")]
[Tooltip("播放VFX时的音效留空则不播放")]
public string AudioClipPath;
[Header("运行时")]
[Tooltip("是否使用自定义生命周期(-1表示使用动画时长")]
public float LifetimeOverride = -1;
}
[SerializeField]
private List<GridVFXInfo> _gridVFXInfoList = new List<GridVFXInfo>();
[NonSerialized]
private bool _initialized = false;
[NonSerialized]
private Dictionary<GridVFXType, GridVFXInfo> _gridVFXDict = new Dictionary<GridVFXType, GridVFXInfo>();
private void Init()
{
if (_initialized)
return;
foreach (var info in _gridVFXInfoList)
{
if (!_gridVFXDict.ContainsKey(info.Type))
{
_gridVFXDict[info.Type] = info;
}
else
{
Debug.LogWarning($"[GridVFXInfoDataAssets] Duplicate GridVFXType: {info.Type}, ignoring duplicate entry.");
}
}
_initialized = true;
}
/// <summary>
/// 获取指定类型的VFX配置
/// </summary>
public bool GetGridVFXInfo(GridVFXType type, out GridVFXInfo info)
{
Init();
return _gridVFXDict.TryGetValue(type, out info);
}
/// <summary>
/// 检查是否包含指定类型
/// </summary>
public bool ContainsType(GridVFXType type)
{
Init();
return _gridVFXDict.ContainsKey(type);
}
/// <summary>
/// 获取已配置的所有VFX类型
/// </summary>
public IEnumerable<GridVFXType> GetAllConfiguredTypes()
{
Init();
return _gridVFXDict.Keys;
}
/// <summary>
/// 清空当前字典(用于运行时重新加载)
/// </summary>
public void ClearCache()
{
_gridVFXDict.Clear();
_initialized = false;
}
/// <summary>
/// 获取配置条目总数
/// </summary>
public int Count => _gridVFXInfoList.Count;
/// <summary>
/// 获取原始列表(仅用于编辑器扩展)
/// </summary>
public List<GridVFXInfo> GetRawList() => _gridVFXInfoList;
}