/// <summary> /// Get the global bus. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static IBus <T> GetBus <T>() { if (!Application.isPlaying) { return(new DummyBusImpl <T>()); } InitGlobalBus(); return(_globalBusBehaviour != null?_globalBusBehaviour.GetBus <T>() : new DummyBusImpl <T>()); }
/// <summary> /// Get the bus attached to a GameObject, or create one. /// </summary> /// <typeparam name="T">The Message type</typeparam> /// <param name="go">Gameobject that the bus lives on.</param> /// <returns>If the object is alive, a valid bus. If the object is dead, a dummy bus.</returns> public static IBus <T> GetBus <T>(GameObject go) { if (go == null) { return(new DummyBusImpl <T>()); } MessageBusBehaviour localBus = go.GetComponent <MessageBusBehaviour>() ?? go.AddComponent <MessageBusBehaviour>(); return(localBus.GetBus <T>()); }