/// <summary> /// Subscribe to events of type TEvent from the event aggregator for the lifetime of this mono behaviour. /// /// Note: The stream will only ever fire onNext, errors and completes are supressed /// </summary> /// <param name="handler">A handler for when the events occur</param> /// <returns>A disposable to unsubscribe from the stream. This is called for you in OnDestroy.</returns> public IDisposable Subscribe <TEvent>(Action <TEvent> handler) { return(this.Subscribe(PubSub.GetEvent <TEvent>(), handler)); }
/// <summary> /// Subscribe to events of type TEvent from the event aggregator for the lifetime of this mono behaviour. /// /// Note: The stream will only ever fire onNext, errors and completes are supressed /// </summary> /// <param name="self">The PubSubMonoBehaviour</param> /// <param name="gameObject">A GameObject to filter the subscription with</param> /// <param name="handler">A handler for when the events occur</param> /// <returns>A disposable to unsubscribe from the stream. This is called for you in OnDestroy.</returns> public static IDisposable Subscribe <TEvent>(this PubSubMonoBehaviour self, GameObject gameObject, Action <TEvent> handler) where TEvent : class, IGameObjectEvent { return(self.Subscribe(PubSub.GetEvent <TEvent>().Where(e => e.GameObject == gameObject), handler)); }