Ejemplo n.º 1
0
        public EventSystem()
        {
            this.disposerEvents.Clear();

            Type[] types = DllHelper.GetHotfixTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ObjectSystemAttribute), false);

                if (attrs.Length == 0)
                {
                    continue;
                }

                object        obj          = Activator.CreateInstance(type);
                IObjectSystem objectSystem = obj as IObjectSystem;
                if (objectSystem == null)
                {
                    Log.Error($"组件事件没有继承IObjectEvent: {type.Name}");
                    continue;
                }
                this.disposerEvents[objectSystem.Type()] = objectSystem;
            }

            this.allEvents.Clear();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
                    object         obj             = Activator.CreateInstance(type);
                    IEvent         iEvent          = obj as IEvent;
                    if (iEvent == null)
                    {
                        Log.Error($"{obj.GetType().Name} 没有继承IEvent");
                    }
                    this.RegisterEvent(aEventAttribute.Type, iEvent);

                    // hotfix的事件也要注册到mono层,hotfix可以订阅mono层的事件
                    Action <List <object> > action = list => { Handle(aEventAttribute.Type, list); };
                    Game.EventSystem.RegisterEvent(aEventAttribute.Type, new EventProxy(action));
                }
            }

            this.Load();
        }
Ejemplo n.º 2
0
        public EventSystem()
        {
            this.disposerEvents.Clear();

            Type[] types = DllHelper.GetHotfixTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ObjectSystemAttribute), false);

                if (attrs.Length == 0)
                {
                    continue;
                }

                object        obj          = Activator.CreateInstance(type);
                IObjectSystem objectSystem = obj as IObjectSystem;
                if (objectSystem == null)
                {
                    Log.Error($"组件事件没有继承IObjectEvent: {type.Name}");
                    continue;
                }
                this.disposerEvents[objectSystem.Type()] = objectSystem;
            }

            allEvents.Clear();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
                    object         obj             = Activator.CreateInstance(type);
                    if (!this.allEvents.ContainsKey((EventIdType)aEventAttribute.Type))
                    {
                        this.allEvents.Add((EventIdType)aEventAttribute.Type, new List <object>());
                    }
                    this.allEvents[(EventIdType)aEventAttribute.Type].Add(obj);
                }
            }

            this.Load();
        }
Ejemplo n.º 3
0
        public void Load()
        {
            this.allEvents = new Dictionary <EventIdType, List <object> >();

            Type[] types = DllHelper.GetHotfixTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);
                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
                    object         obj             = Activator.CreateInstance(type);
                    if (!this.allEvents.ContainsKey((EventIdType)aEventAttribute.Type))
                    {
                        this.allEvents.Add((EventIdType)aEventAttribute.Type, new List <object>());
                    }
                    this.allEvents[(EventIdType)aEventAttribute.Type].Add(obj);
                }
            }
        }
Ejemplo n.º 4
0
        public EventSystem()
        {
            this.types.Clear();

            List <Type> ts = ICE.Game.Hotfix.GetHotfixTypes();

            foreach (Type type in ts)
            {
                // ILRuntime无法判断是否有Attribute
                //if (type.GetCustomAttributes(typeof (Attribute), false).Length == 0)
                //{
                //	continue;
                //}

                types.Add(type);
            }

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ObjectSystemAttribute), false);

                if (attrs.Length == 0)
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                switch (obj)
                {
                case IAwakeSystem objectSystem:
                    awakeSystems.Add(objectSystem.Type(), objectSystem);
                    break;

                case IUpdateSystem updateSystem:
                    updateSystems.Add(updateSystem.Type(), updateSystem);
                    break;

                case ILateUpdateSystem lateUpdateSystem:
                    lateUpdateSystems.Add(lateUpdateSystem.Type(), lateUpdateSystem);
                    break;

                case IStartSystem startSystem:
                    startSystems.Add(startSystem.Type(), startSystem);
                    break;

                case IDestroySystem destroySystem:
                    destroySystems.Add(destroySystem.Type(), destroySystem);
                    break;

                case ILoadSystem loadSystem:
                    loadSystems.Add(loadSystem.Type(), loadSystem);
                    break;

                case IChangeSystem changeSystem:
                    changeSystems.Add(changeSystem.Type(), changeSystem);
                    break;

                case IDeserializeSystem deserializeSystem:
                    deserializeSystems.Add(deserializeSystem.Type(), deserializeSystem);
                    break;
                }
            }

            allEvents.Clear();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
                    object         obj             = Activator.CreateInstance(type);
                    IEvent         iEvent          = obj as IEvent;
                    if (iEvent == null)
                    {
                        Log.Error($"{obj.GetType().Name} 没有继承IEvent");
                    }
                    RegisterEvent(aEventAttribute.Type, iEvent);

                    // hotfix的事件也要注册到mono层,hotfix可以订阅mono层的事件
                    Action <List <object> > action = list => { Handle(iEvent, list); };
                    ICE.Game.EventSystem.RegisterEvent(aEventAttribute.Type, new EventProxy(action));
                }
            }

            Load();
        }
Ejemplo n.º 5
0
        public EventSystem()
        {
            Type[] types = Game.Hotfix.GetHotfixTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ObjectSystemAttribute), false);

                if (attrs.Length == 0)
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                AAwakeSystem objectSystem = obj as AAwakeSystem;
                if (objectSystem != null)
                {
                    this.awakeEvents.Add(objectSystem.Type(), objectSystem);
                }

                AUpdateSystem aUpdateSystem = obj as AUpdateSystem;
                if (aUpdateSystem != null)
                {
                    this.updateEvents.Add(aUpdateSystem.Type(), aUpdateSystem);
                }

                ALateUpdateSystem aLateUpdateSystem = obj as ALateUpdateSystem;
                if (aLateUpdateSystem != null)
                {
                    this.lateUpdateEvents.Add(aLateUpdateSystem.Type(), aLateUpdateSystem);
                }

                AStartSystem aStartSystem = obj as AStartSystem;
                if (aStartSystem != null)
                {
                    this.startEvents.Add(aStartSystem.Type(), aStartSystem);
                }

                ALoadSystem aLoadSystem = obj as ALoadSystem;
                if (aLoadSystem != null)
                {
                    this.loadEvents.Add(aLoadSystem.Type(), aLoadSystem);
                }
            }

            this.allEvents.Clear();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
                    object         obj             = Activator.CreateInstance(type);
                    IEvent         iEvent          = obj as IEvent;
                    if (iEvent == null)
                    {
                        Log.Error($"{obj.GetType().Name} 没有继承IEvent");
                    }
                    this.RegisterEvent(aEventAttribute.Type, iEvent);

                    // hotfix的事件也要注册到mono层,hotfix可以订阅mono层的事件
                    Action <List <object> > action = list => { Handle(aEventAttribute.Type, list); };
                    Game.EventSystem.RegisterEvent(aEventAttribute.Type, new EventProxy(action));
                }
            }

            this.Load();
        }