/// <summary> /// Copy listener properties from the given listener /// </summary> /// <param name="copyFrom">listener to copy properties from</param> public void CopyFrom(NamedEventListener copyFrom) { if (copyFrom == null || !copyFrom.IsValid()) { UnityEngine.Debug.LogError("Invalid interaction to copy from."); return; } EventName = copyFrom.EventName; CopyEventListener(copyFrom.EventListener); EventListenerPropertyType = copyFrom.EventListenerPropertyType; ReceiveEventState = copyFrom.ReceiveEventState; }
/// <summary> /// Copies all named event listeners from one object to another /// </summary> /// <param name="copyFrom">Obj to copy from</param> /// <param name="copyTo">Obj to copy to</param> public static void CopyAll(GameObject copyFrom, GameObject copyTo) { // Deactivate this object so we can copy component values without // the component's Awake function being called bool originalActiveState = copyTo.activeSelf; copyTo.SetActive(false); // Copy listeners from our placeholder foreach (NamedEventListener interaction in copyFrom.GetComponents <NamedEventListener>()) { NamedEventListener newInteraction = copyTo.AddComponent <NamedEventListener>(); newInteraction.CopyFrom(interaction); } // Reset the original state copyTo.SetActive(originalActiveState); }
private void Awake() { if (CopyTo != null) { // Copy all listeners from the current object to the specified object foreach (GameObject copyTo in CopyTo) { NamedEventListener.CopyAll(gameObject, copyTo); } } if (CopyFrom != null) { // Copy all listeners from the specified objects to this game object foreach (GameObject copyFrom in CopyFrom) { NamedEventListener.CopyAll(copyFrom, gameObject); } } }