using UnityEngine; using UnityEngine.Serialization; namespace UnityAtoms.MonoHooks { /// /// Generic base class for all Mono Hooks. /// /// Event of type `AtomEvent<EV>` /// Event value type /// Function type `AtomFunction<GameObject, GameObject>` [EditorIcon("atom-icon-delicate")] public abstract class MonoHook : MonoBehaviour where E : AtomEvent where F : AtomFunction { /// /// The Event /// public E Event { get => _event; set => _event = value; } [SerializeField] private E _event; /// /// 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); } RaiseWithGameObject(value, _selectGameObjectReference != null ? _selectGameObjectReference.Call(gameObject) : gameObject); } protected abstract void RaiseWithGameObject(EV value, GameObject gameObject); } }