public static SignalHub FindParentHub([NotNull] Component component) { if (component == null) { throw new ArgumentNullException("component"); } SignalHub hub = FindHub(component); if (!hub) { if (Application.isPlaying) { Debug.LogWarning("Can't find hub for " + component.name, component); } return(null); } SignalHub parent = FindHub(hub.transform.parent); if (hub != parent) { return(parent); } if (hub != GlobalHub) { Debug.LogWarning("Can't find parent hub for " + component.name, component); } return(null); }
public static void Unregister(Component receiver, int signal, SignalSpace direction = SignalSpace.Local) { if (IsQuitting) { return; } switch (direction) { case SignalSpace.Local: SignalHub hub = FindHub(receiver); hub.Unregister(receiver, signal); break; case SignalSpace.Parent: SignalHub parentHub = FindParentHub(receiver); parentHub.Unregister(receiver, signal); break; case SignalSpace.Global: GlobalHub.Unregister(receiver, signal); break; default: throw new ArgumentOutOfRangeException("direction", direction, null); } }
public static void Register([NotNull] ISignalReceiver receiver) { if (receiver == null) { throw new ArgumentNullException("receiver"); } SignalHub hub = FindHub(receiver.Component); if (!IsQuitting) { hub.Register(receiver); } }
public static SignalHub FindHub(Component component) { if (IsQuitting) { return(null); } if (!component) { return(GlobalHub); } SignalHub hub = component.GetComponentInParent <SignalHub>(); return(hub ? hub : GlobalHub); }
public static void UnregisterAll(Component receiver) { if (IsQuitting) { return; } SignalHub hub = FindHub(receiver); hub.UnregisterAll(receiver); SignalHub parentHub = FindParentHub(receiver); if (parentHub) { parentHub.UnregisterAll(receiver); } GlobalHub.UnregisterAll(receiver); }