/// <summary>Dispatches an event to a gameObject. /// Depending on the events settings, it may bubble up the scene hierarchy.</summary> public static bool dispatchEvent(this GameObject go, Dom.Event e) { // Get the monobehaviour: GameObjectEventTarget monoBehaviour = go.GetComponent <GameObjectEventTarget>(); if (monoBehaviour == null) { // Build it now: monoBehaviour = go.AddComponent <GameObjectEventTarget>(); monoBehaviour.Setup(); } // Dispatch: return(monoBehaviour.Target.dispatchEvent(e)); }
/// <summary>Gets or creates an EventTarget on a GameObject.</summary> public static EventTarget getEventTarget(this GameObject go) { // Get the monobehaviour: GameObjectEventTarget monoBehaviour = go.GetComponent <GameObjectEventTarget>(); if (monoBehaviour == null) { // Add it: monoBehaviour = go.AddComponent <GameObjectEventTarget>(); monoBehaviour.Setup(); } // Return the target property: return(monoBehaviour.Target); }