Rasagar/Library/PackageCache/com.unity.visualeffectgraph/Runtime/Utilities/EventBinding/VFXEventBinderBase.cs

46 lines
1.1 KiB
C#
Raw Normal View History

2024-08-26 13:07:20 -07:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine.VFX;
namespace UnityEngine.VFX.Utility
{
abstract class VFXEventBinderBase : MonoBehaviour
{
[SerializeField]
protected VisualEffect target;
public string EventName = "Event";
[SerializeField, HideInInspector]
protected VFXEventAttribute eventAttribute;
protected virtual void OnEnable()
{
UpdateCacheEventAttribute();
}
private void OnValidate()
{
UpdateCacheEventAttribute();
}
private void UpdateCacheEventAttribute()
{
if (target != null)
eventAttribute = target.CreateVFXEventAttribute();
else
eventAttribute = null;
}
protected abstract void SetEventAttribute(object[] parameters = null);
protected void SendEventToVisualEffect(params object[] parameters)
{
if (target != null)
{
SetEventAttribute(parameters);
target.SendEvent(EventName, eventAttribute);
}
}
}
}