Пример #1
0
        /** \brief Routes a message of the specified event to the specified GameObject and its children. */
        /// Both direct and indirect children of the specified GameObject receive the event.\n
        /// \returns Returns a List<R> containing all return data from subscribers of this event type.\n
        /// \returns Otherwise returns null if the message cannot be sent.
        /// \note Only works for subscribed GameObjects. Children must be subscribed as-well in order to receive the event.
        public static List <R> RouteMessageDescendants(GameObject Scope /**< GameObject specifying the scope of the message. */, RoutingEvent EventType /**< Type of event to send. */, RouteParameters <T1, T2, T3> Parameters /**< Struct containing parameters to pass to recipients. */)
        {
            if (TablesExist && ScopeIsValid(Scope) && EventIsRegistered(EventType))
            {
                CleanDeadRoutes(EventType);

                List <Route <R, T1, T2, T3> > RT = RouteTable[EventType].FindAll(x => x.Subscriber.transform.IsChildOf(Scope.transform));
                R[] Results = new R[RT.Count];

                for (int i = 0; i < RT.Count; i++)
                {
                    Results[i] = RT[i].Address(Parameters.FirstParameter, Parameters.SecondParameter, Parameters.ThirdParameter);
                }

                return(new List <R>(Results));
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        /** \brief Routes a message of the specified event to all subscribers in a radius. */
        /// Uses the specified Component as the origin point.\n
        /// \returns Returns a List<R> containing all return data from subscribers of this event type.\n
        /// \returns Otherwise returns null if the message cannot be sent.
        /// \note Only works for subscribed GameObjects.
        public static List <R> RouteMessageArea(Component Origin /**< Component specifying the origin of the event radius.\n Can be of any type derived from Component.\n Does not need to be subscribed unless it also is to receive the event. */, RoutingEvent EventType /**< Type of event to send. */, float Radius /**< Radius of the event in meters. */, RouteParameters <T1, T2, T3> Parameters /**< Struct containing parameters to pass to recipients. */)
        {
            if (TablesExist && ScopeIsValid(Origin.gameObject) && EventIsRegistered(EventType))
            {
                CleanDeadRoutes(EventType);
                decimal RadiusD = (new Decimal(Radius));

                List <Route <R, T1, T2, T3> > RT = RouteTable[EventType].FindAll(x => (new Decimal(Vector3.Distance(Origin.transform.position, x.Subscriber.transform.position)) <= RadiusD));
                R[] Results = new R[RT.Count];

                for (int i = 0; i < RT.Count; i++)
                {
                    Results[i] = RT[i].Address(Parameters.FirstParameter, Parameters.SecondParameter, Parameters.ThirdParameter);
                }

                return(new List <R>(Results));
            }
            else
            {
                return(null);
            }
        }
Пример #3
0
        /** \brief Routes a message of the specified event to all subscribers and returns their values. */
        /// \returns Returns a List<R> containing all return data from subscribers of this event type.\n
        /// \returns Otherwise returns null if the message cannot be sent.
        public static List <R> RouteMessage(RoutingEvent EventType /**< Type of event to send. */, RouteParameters <T1, T2, T3> Parameters /**< Struct containing parameters to pass to recipients. */)
        {
            if (TablesExist && KeyHasValue(EventType) && EventIsRegistered(EventType))
            {
                CleanDeadRoutes(EventType);

                Delegate[] RPL     = PointerTable[EventType].GetInvocationList();
                R[]        Results = new R[RPL.Length];

                for (int i = 0; i < RPL.Length; i++)
                {
                    Results[i] = (RPL[i] as RoutePointer <R, T1, T2, T3>)(Parameters.FirstParameter, Parameters.SecondParameter, Parameters.ThirdParameter);
                }

                return(new List <R>(Results));
            }
            else
            {
                return(null);
            }
        }
Пример #4
0
        /** \brief Routes a message of the specified event to the specified GameObject and its parents. */
        /// Both direct and indirect parents of the specified GameObject receive the event.\n
        /// Accepts a Component that is used to derive a reference to the target GameObject.\n
        /// \returns Returns a List<R> containing all return data from subscribers of this event type.\n
        /// \returns Otherwise returns null if the message cannot be sent.
        /// \note Only works for subscribed GameObjects. Parents must be subscribed as-well in order to receive the event.
        public static List <R> RouteMessageAscendants(Component Scope /**< Component specifying the scope of the message.\n Can be of any type derived from Component.*/, RoutingEvent EventType /**< Type of event to send. */, RouteParameters <T1, T2> Parameters)
        {
            if (TablesExist && ScopeIsValid(Scope) && EventIsRegistered(EventType))
            {
                CleanDeadRoutes(EventType);

                List <Route <R, T1, T2> > RT = RouteTable[EventType].FindAll(x => Scope.transform.IsChildOf(x.Subscriber.transform));
                R[] Results = new R[RT.Count];

                for (int i = 0; i < RT.Count; i++)
                {
                    Results[i] = RT[i].Address(Parameters.FirstParameter, Parameters.SecondParameter);
                }

                return(new List <R>(Results));
            }
            else
            {
                return(null);
            }
        }