// sends a message public static void Broadcast <T0>(string messageName, T0 p0) { #if PROFILE_BROADCAST_MESSAGE Profiler.BeginSample("UKMessager_Broadcast1_" + messageName); #endif #if LOG_BROADCAST_MESSAGE Debug.Log(string.Format("MESSENGER send message {0} ({1})", messageName, p0)); #endif int callsDelivered = 0; EventListeners l; if (eventTable.TryGetValue(messageName, out l)) { int countDead = 0; var listeners = l.Listeners; for (int i = 0; i < listeners.Count; ++i) { if (listeners[i].LifecycleObject != null) { // listener still alive -> try to call UKCallback <T0> callback = listeners[i].Listener as UKCallback <T0>; if (callback != null) { callback(p0); ++callsDelivered; } } else { ++countDead; } } if (countDead > 0) { PurgeDeadListeners(l); } } #if PROFILE_BROADCAST_MESSAGE Profiler.EndSample(); #endif #if LOG_BROADCAST_WITHOUT_RECIPIENT if (callsDelivered == 0) { Debug.LogWarning(string.Format("MESSENGER send message {0} () without recipient", messageName)); } #endif }
public static void AddListener <T0, T1, T2>(string messageName, GameObject lifecycleObject, UKCallback <T0, T1, T2> handler) { AddListenerInternal(messageName, lifecycleObject, handler); }