protected static ComponentInterceptedEvents[] GetEventsInfo(GameObject gameObject)
        {
            // TODO: could this becached somewhere?
            List<Type> interfaces = new List<Type>();
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                Type[] types = assembly.GetTypes();
                foreach (var type in types)
                {
                    if (!type.IsInterface)
                        continue;

                    if (!typeof(IEventSystemHandler).IsAssignableFrom(type))
                        continue;

                    interfaces.Add(type);
                }
            }

            List<ComponentInterceptedEvents> componentEvents = new List<ComponentInterceptedEvents>();
            List<GUIContent> events = new List<GUIContent>();
            MonoBehaviour[] mbs = gameObject.GetComponents<MonoBehaviour>();

            for (int i = 0, imax = mbs.Length; i < imax; ++i)
            {
                MonoBehaviour mb = mbs[i];
                if (mb == null)
                    continue;

                Type type = mb.GetType();

                if (typeof(IEventSystemHandler).IsAssignableFrom(type))
                {
                    foreach (var eventInterface in interfaces)
                    {
                        if (!eventInterface.IsAssignableFrom(type))
                            continue;

                        MethodInfo[] methodInfos = eventInterface.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                        foreach (MethodInfo methodInfo in methodInfos)
                        {
                            events.Add(new GUIContent(methodInfo.Name));
                        }
                    }
                }

                if (events.Count > 0)
                {
                    ComponentInterceptedEvents componentEvent = new ComponentInterceptedEvents();
                    componentEvent.componentName = new GUIContent(type.Name);
                    componentEvent.interceptedEvents = events.OrderBy(e => e.text).ToArray();
                    componentEvents.Add(componentEvent);

                    events.Clear();
                }
            }

            return componentEvents.ToArray();
        }
        protected static List<ComponentInterceptedEvents> GetEventsInfo(GameObject gameObject)
        {
            InitializeEvetnsInterfaceCacheIfNeeded();

            List<ComponentInterceptedEvents> componentEvents = new List<ComponentInterceptedEvents>();

            MonoBehaviour[] mbs = gameObject.GetComponents<MonoBehaviour>();

            for (int i = 0, imax = mbs.Length; i < imax; ++i)
            {
                ComponentInterceptedEvents componentEvent = null;

                MonoBehaviour mb = mbs[i];
                if (mb == null)
                    continue;

                Type type = mb.GetType();

                if (!s_ComponentEvents2.ContainsKey(type))
                {
                    List<int> events = null;
                    Profiler.BeginSample("ComponentInterceptedEvents.GetEventsInfo.NewType");
                    if (typeof(IEventSystemHandler).IsAssignableFrom(type))
                    {
                        for (int index = 0; index < s_EventSystemInterfaces.Count; index++)
                        {
                            var eventInterface = s_EventSystemInterfaces[index];
                            if (!eventInterface.IsAssignableFrom(type))
                                continue;

                            if (events == null)
                                events = new List<int>();

                            events.AddRange(s_InterfaceEventSystemEvents[eventInterface]);
                        }
                    }

                    if (events != null)
                    {
                        componentEvent = new ComponentInterceptedEvents();
                        componentEvent.componentName = new GUIContent(type.Name);
                        componentEvent.interceptedEvents = events.OrderBy(index => s_PossibleEvents[index].text).ToArray();
                    }
                    s_ComponentEvents2.Add(type, componentEvent);

                    Profiler.EndSample();
                }
                else
                {
                    componentEvent = s_ComponentEvents2[type];
                }


                if (componentEvent != null)
                {
                    componentEvents.Add(componentEvent);
                }
            }

            return componentEvents;
        }
        protected static ComponentInterceptedEvents[] GetEventsInfo(GameObject gameObject)
        {
            // TODO: could this becached somewhere?
            List <Type> interfaces = new List <Type>();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                Type[] types = assembly.GetTypes();
                foreach (var type in types)
                {
                    if (!type.IsInterface)
                    {
                        continue;
                    }

                    if (!typeof(IEventSystemHandler).IsAssignableFrom(type))
                    {
                        continue;
                    }

                    interfaces.Add(type);
                }
            }

            List <ComponentInterceptedEvents> componentEvents = new List <ComponentInterceptedEvents>();
            List <GUIContent> events = new List <GUIContent>();

            MonoBehaviour[] mbs = gameObject.GetComponents <MonoBehaviour>();

            for (int i = 0, imax = mbs.Length; i < imax; ++i)
            {
                MonoBehaviour mb = mbs[i];
                if (mb == null)
                {
                    continue;
                }

                Type type = mb.GetType();


                if (typeof(IEventSystemHandler).IsAssignableFrom(type))
                {
                    foreach (var eventInterface in interfaces)
                    {
                        if (!eventInterface.IsAssignableFrom(type))
                        {
                            continue;
                        }

                        MethodInfo[] methodInfos = eventInterface.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
                        foreach (MethodInfo methodInfo in methodInfos)
                        {
                            events.Add(new GUIContent(methodInfo.Name));
                        }
                    }
                }

                if (events.Count > 0)
                {
                    ComponentInterceptedEvents componentEvent = new ComponentInterceptedEvents();
                    componentEvent.componentName     = new GUIContent(type.Name);
                    componentEvent.interceptedEvents = events.OrderBy(e => e.text).ToArray();
                    componentEvents.Add(componentEvent);

                    events.Clear();
                }
            }

            return(componentEvents.ToArray());
        }
Esempio n. 4
0
        protected static List <ComponentInterceptedEvents> GetEventsInfo(GameObject gameObject)
        {
            InitializeEvetnsInterfaceCacheIfNeeded();

            List <ComponentInterceptedEvents> componentEvents = new List <ComponentInterceptedEvents>();

            MonoBehaviour[] mbs = gameObject.GetComponents <MonoBehaviour>();

            for (int i = 0, imax = mbs.Length; i < imax; ++i)
            {
                ComponentInterceptedEvents componentEvent = null;

                MonoBehaviour mb = mbs[i];
                if (mb == null)
                {
                    continue;
                }

                Type type = mb.GetType();

                if (!s_ComponentEvents2.ContainsKey(type))
                {
                    List <int> events = null;
                    Profiler.BeginSample("ComponentInterceptedEvents.GetEventsInfo.NewType");
                    if (typeof(IEventSystemHandler).IsAssignableFrom(type))
                    {
                        for (int index = 0; index < s_EventSystemInterfaces.Count; index++)
                        {
                            var eventInterface = s_EventSystemInterfaces[index];
                            if (!eventInterface.IsAssignableFrom(type))
                            {
                                continue;
                            }

                            if (events == null)
                            {
                                events = new List <int>();
                            }

                            events.AddRange(s_InterfaceEventSystemEvents[eventInterface]);
                        }
                    }

                    if (events != null)
                    {
                        componentEvent = new ComponentInterceptedEvents();
                        componentEvent.componentName     = new GUIContent(type.Name);
                        componentEvent.interceptedEvents = events.OrderBy(index => s_PossibleEvents[index].text).ToArray();
                    }
                    s_ComponentEvents2.Add(type, componentEvent);

                    Profiler.EndSample();
                }
                else
                {
                    componentEvent = s_ComponentEvents2[type];
                }


                if (componentEvent != null)
                {
                    componentEvents.Add(componentEvent);
                }
            }

            return(componentEvents);
        }