94 lines
3.5 KiB
C#
94 lines
3.5 KiB
C#
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 CharacterBase executor;
|
||
[NonSerialized] private Transform executorTransform;
|
||
|
||
public void Initialize(CharacterBase character)
|
||
{
|
||
executor = character;
|
||
executorTransform = character.transform;
|
||
}
|
||
|
||
public GameObject SpawnVFX(string vfxName, Transform overrideStartTransform = null)
|
||
{
|
||
VFXUnit vfxUnit = Get(vfxName);
|
||
|
||
Transform startTransform = overrideStartTransform ?? executorTransform;
|
||
GameObject vfxInstance = VFXObject.Spawn(vfxUnit.mainVFX, executor, 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 VFXObject.Spawn(Get(effectName).muzzleVFX, executor, muzzleTransform);
|
||
}
|
||
|
||
public GameObject SpawnHitVFX(string effectName, Vector3 hitPosition)
|
||
{
|
||
return VFXObject.Spawn(Get(effectName).muzzleVFX, executor, 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;
|
||
}
|
||
} |