Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

62 行
1.6 KiB

using UnityEngine;
#if PACKAGE_VFXGRAPH
using UnityEngine.VFX;
#endif
namespace GameplayIngredients.Events
{
#if !PACKAGE_VFXGRAPH
[WarnDisabledModule("Visual Effect Graph")]
#else
[AddComponentMenu(ComponentMenu.vfxPath + "On VFX Output Event")]
[RequireComponent(typeof(VisualEffect))]
#endif
public class OnVFXOutputEvent : EventBase
{
public string vfxEventName { get => m_VFXEventName; set { m_VFXEventName = value; CacheEventName(); } }
[SerializeField]
string m_VFXEventName = "On Received Event";
int m_VFXEventID;
[SerializeField]
protected Callable[] onEventReceived;
private void OnEnable()
{
CacheEventName();
#if PACKAGE_VFXGRAPH
GetComponent<VisualEffect>().outputEventReceived += OnVFXOutputEvent_Received;
#else
Debug.LogWarning("OnVFXOutputEvent could not attach to VFX as VFX Graph package is not installed, if you're running HDRP or URP, please install it using package manager.");
#endif
}
private void OnDisable()
{
#if PACKAGE_VFXGRAPH
GetComponent<VisualEffect>().outputEventReceived -= OnVFXOutputEvent_Received;
#endif
}
private void OnValidate()
{
CacheEventName();
}
void CacheEventName()
{
m_VFXEventID = Shader.PropertyToID(m_VFXEventName);
}
#if PACKAGE_VFXGRAPH
void OnVFXOutputEvent_Received(VFXOutputEventArgs args)
{
if(args.nameId == m_VFXEventID)
{
Callable.Call(onEventReceived, gameObject);
}
}
#endif
}
}