/// <inheritdoc />
        public virtual void UnregisterHandler <T>(IEventSystemHandler handler) where T : IEventSystemHandler
        {
            if (handler == null)
            {
                return;
            }

            // #if due to Microsoft.MixedReality.Toolkit.ReflectionExtensions overload of Type.IsInterface
            #if WINDOWS_UWP && !ENABLE_IL2CPP
            Debug.Assert(typeof(T).IsInterface(), "UnregisterHandler must be called with an interface as a generic parameter.");
            #else
            Debug.Assert(typeof(T).IsInterface, "UnregisterHandler must be called with an interface as a generic parameter.");
            #endif
            Debug.Assert(typeof(T).IsAssignableFrom(handler.GetType()), "Handler passed to UnregisterHandler doesn't implement a type given as generic parameter.");

            TraverseEventSystemHandlerHierarchy <T>(handler, UnregisterHandler);
        }
        /// <inheritdoc />
        public virtual void RegisterHandler <T>(IEventSystemHandler handler) where T : IEventSystemHandler
        {
            if (handler == null)
            {
                return;
            }

            // #if due to Microsoft.MixedReality.Toolkit.ReflectionExtensions overload of Type.IsInterface
#if WINDOWS_UWP && !ENABLE_IL2CPP
            Debug.Assert(typeof(T).IsInterface(), "RegisterHandler must be called with an interface as a generic parameter.");
#else
            Debug.Assert(typeof(T).IsInterface, "RegisterHandler must be called with an interface as a generic parameter.");
#endif
            Debug.Assert(typeof(T).IsAssignableFrom(handler.GetType()), "Handler passed to RegisterHandler doesn't implement a type given as generic parameter.");

            DebugUtilities.LogVerboseFormat("Registering handler {0} against system {1}", handler.ToString().Trim(), this);

            TraverseEventSystemHandlerHierarchy <T>(handler, RegisterHandler);
        }
        public static bool Execute <T>(GameObject target, BaseEventData eventData, ExecuteEvents.EventFunction <T> functor) where T : IEventSystemHandler
        {
            List <IEventSystemHandler> list = ExecuteEvents.s_HandlerListPool.Get();

            ExecuteEvents.GetEventList <T>(target, list);
            int i = 0;

            while (i < list.Count)
            {
                T handler;
                try
                {
                    handler = (T)((object)list[i]);
                }
                catch (Exception innerException)
                {
                    IEventSystemHandler eventSystemHandler = list[i];
                    Debug.LogException(new Exception(string.Format("Type {0} expected {1} received.", typeof(T).Name, eventSystemHandler.GetType().Name), innerException));
                    goto IL_8F;
                }
                goto Block_2;
IL_8F:
                i++;
                continue;
Block_2:
                try
                {
                    functor(handler, eventData);
                }
                catch (Exception exception)
                {
                    Debug.LogException(exception);
                }
                goto IL_8F;
            }
            int count = list.Count;

            ExecuteEvents.s_HandlerListPool.Release(list);
            return(count > 0);
        }
Exemple #4
0
        public static bool Execute <T>(GameObject target, BaseEventData eventData, EventFunction <T> functor) where T : IEventSystemHandler
        {
            List <IEventSystemHandler> list = s_HandlerListPool.Get();

            GetEventList <T>(target, list);
            for (int i = 0; i < list.Count; i++)
            {
                T handler;
                try
                {
                    handler = (T)list[i];
                }
                catch (Exception innerException)
                {
                    IEventSystemHandler eventSystemHandler = list[i];
                    Debug.LogException(new Exception($"Type {typeof(T).Name} expected {eventSystemHandler.GetType().Name} received.", innerException));
                    continue;
                }
                try
                {
                    functor(handler, eventData);
                }
                catch (Exception exception)
                {
                    Debug.LogException(exception);
                }
            }
            int count = list.Count;

            s_HandlerListPool.Release(list);
            return(count > 0);
        }