Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        public static void Register([NotNull] ISignalReceiver receiver)
        {
            if (receiver == null)
            {
                throw new ArgumentNullException("receiver");
            }
            SignalHub hub = FindHub(receiver.Component);

            if (!IsQuitting)
            {
                hub.Register(receiver);
            }
        }
Ejemplo n.º 4
0
        public static SignalHub FindHub(Component component)
        {
            if (IsQuitting)
            {
                return(null);
            }

            if (!component)
            {
                return(GlobalHub);
            }

            SignalHub hub = component.GetComponentInParent <SignalHub>();

            return(hub ? hub : GlobalHub);
        }
Ejemplo n.º 5
0
        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);
        }