/// <summary> /// Create a MessageToken to invoke at a later point. If no targets found null is returned. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static MessageToken <T> CreateBroadcastToken <T>() where T : class { if (GlobalMessagePool <T> .Count == 0) { return(null); } return(new MessageToken <T>(GlobalMessagePool <T> .CopyReceivers())); }
/// <summary> /// Broadcast a message globally to all that match T. This can be slow, use sparingly. /// </summary> /// <typeparam name="TInterface"></typeparam> /// <typeparam name="TArg"></typeparam> /// <param name="arg"></param> /// <param name="functor"></param> public static void FindAndBroadcast <TInterface, TArg>(TArg arg, System.Action <TInterface, TArg> functor, bool includeDisabledComponents = false) where TInterface : class { if (functor == null) { throw new System.ArgumentNullException("functor"); } using (var coll = TempCollection.GetSet <TInterface>()) { ObjUtil.FindObjectsOfInterface <TInterface>(coll); GlobalMessagePool <TInterface> .CopyReceivers(coll); var e = coll.GetEnumerator(); while (e.MoveNext()) { if (includeDisabledComponents || TargetIsValid(e.Current)) { functor(e.Current, arg); } } } }