using UnityEngine; using UnityEngine.Serialization; namespace UnityAtoms.MonoHooks { /// /// Generic base class for all Mono Hooks. /// /// Event of type `AtomEvent<EV>` /// Event of type `AtomEvent<EV, GameObject>` /// Event value type /// Function type `AtomFunction<GameObject, GameObject>` [EditorIcon("atom-icon-delicate")] public abstract class MonoHook : MonoBehaviour where E1 : AtomEvent where E2 : AtomEvent where F : AtomFunction { /// /// The Event /// public E1 Event; /// /// Event including a GameObject reference. /// public E2 EventWithGameObjectReference; /// /// Selector function for the Event `EventWithGameObjectReference`. Makes it possible to for example select the parent GameObject and pass that a long to the `EventWithGameObjectReference`. /// [SerializeField] protected F _selectGameObjectReference; protected void OnHook(EV value) { if (Event != null) { Event.Raise(value); } if (EventWithGameObjectReference != null) { EventWithGameObjectReference.Raise(value, _selectGameObjectReference != null ? _selectGameObjectReference.Call(gameObject) : gameObject); } } } }