Files
Cielonos/Assets/Scripts/MainGame/Effects/VFXData.cs

94 lines
3.4 KiB
C#
Raw Normal View History

2025-11-25 08:19:33 -05:00
using System;
using System.Collections.Generic;
using Cielonos.MainGame.Characters;
using Lean.Pool;
using Sirenix.OdinInspector;
using SoftCircuits.Collections;
using UnityEngine;
using UnityEngine.Serialization;
namespace Cielonos.MainGame
{
[CreateAssetMenu(fileName = "VFXData", menuName = "Cielonos/VFXData")]
public partial class VFXData : SerializedScriptableObject
{
[DictionaryDrawerSettings(KeyLabel = "VFX Name", DisplayMode = DictionaryDisplayOptions.ExpandedFoldout)]
[Searchable]
public OrderedDictionary<string, VFXUnit> collection = new OrderedDictionary<string, VFXUnit>();
public VFXUnit Get(string effectName) => collection[effectName];
}
public partial class VFXData
{
//Runtime
[NonSerialized]
private Transform executorTransform;
public void Initialize(CharacterBase character)
{
executorTransform = character.transform;
}
public GameObject SpawnVFX(string vfxName, Transform overrideStartTransform = null)
{
VFXUnit vfxUnit = Get(vfxName);
Transform startTransform = overrideStartTransform ?? executorTransform;
GameObject vfxInstance = LeanPool.Spawn(vfxUnit.mainVFX, startTransform);
Transform vfxTransform = vfxInstance.transform;
vfxTransform.localPosition = vfxUnit.localPosition;
vfxTransform.localEulerAngles = vfxUnit.localEulerAngles;
vfxTransform.localScale = vfxUnit.localScale;
if (!vfxUnit.keepLocalTransform)
{
vfxTransform.parent = null;
}
return vfxInstance;
}
public GameObject SpawnMuzzleVFX(string effectName, Transform muzzleTransform)
{
return LeanPool.Spawn(Get(effectName).muzzleVFX, muzzleTransform);
}
public GameObject SpawnHitVFX(string effectName, Vector3 hitPosition)
{
return LeanPool.Spawn(Get(effectName).muzzleVFX, hitPosition, Quaternion.identity);
}
}
[Serializable]
public class VFXUnit
{
[BoxGroup("VFX"), LabelWidth(150)]
[PropertyTooltip("特效预制体")]
public GameObject mainVFX;
[BoxGroup("VFX"), LabelWidth(150)]
[PropertyTooltip("枪口特效(可空)")]
public GameObject muzzleVFX;
[BoxGroup("VFX"), LabelWidth(150)]
[PropertyTooltip("击中特效可空通常用于AttackArea获取不需要使用VFXData生成")]
public GameObject hitVFX;
[BoxGroup("VFX"), LabelWidth(150)]
[PropertyTooltip("附加特效(可空)")]
public List<GameObject> otherVFXList;
[BoxGroup("Transform"), LabelWidth(150)]
[PropertyTooltip("特效生成时的位置偏移")]
public Vector3 localPosition = Vector3.zero;
[BoxGroup("Transform"), LabelWidth(150)]
[PropertyTooltip("特效生成时的旋转角度")]
public Vector3 localEulerAngles = Vector3.zero;
[BoxGroup("Transform"), LabelWidth(150)]
[PropertyTooltip("特效生成时的缩放比例")]
public Vector3 localScale = Vector3.one;
[BoxGroup("Transform"), LabelWidth(150)]
[PropertyTooltip("是否在生成后保持特效与父级Transform的联系")]
public bool keepLocalTransform = false;
}
}