namespace UnityEngine.VFX.Utility { /// /// A VFXOutputEventAbstractHandler is an API helper that hooks into an Output Event to allow you to execute scripts based on the event. /// [ExecuteAlways] [RequireComponent(typeof(VisualEffect))] public abstract class VFXOutputEventAbstractHandler : MonoBehaviour { /// /// Returns false if this output event handler can only be executed in play mode or runtime. /// public abstract bool canExecuteInEditor { get; } /// /// Property to enable or disable the execution in editor. /// public bool executeInEditor = true; /// /// The name of the output event to catch. /// public ExposedProperty outputEvent = "On Received Event"; /// /// The VisualEffect emitter of the output event. /// protected VisualEffect m_VisualEffect { private set; get; } /// /// This function is called when the object becomes enabled and active. /// protected virtual void OnEnable() { m_VisualEffect = GetComponent(); if (m_VisualEffect != null) m_VisualEffect.outputEventReceived += OnOutputEventRecieved; } /// /// This function is called when the behavior becomes disabled. /// protected virtual void OnDisable() { if (m_VisualEffect != null) m_VisualEffect.outputEventReceived -= OnOutputEventRecieved; } void OnOutputEventRecieved(VFXOutputEventArgs args) { if (Application.isPlaying || (executeInEditor && canExecuteInEditor)) { if (args.nameId == outputEvent) OnVFXOutputEvent(args.eventAttribute); } } /// /// This function is called when the specified event in outputEvent on the attached VisualEffect is triggered. /// The VFXEventAttribute passed as parameter is temporary and can be modified in a later process. /// /// The VFXEventAttribute handling properties from the spawn event. public abstract void OnVFXOutputEvent(VFXEventAttribute eventAttribute); } }