Пример #1
0
        public EventSystem()
        {
            this.disposerEvents.Clear();

            Type[] types = DllHelper.GetHotfixTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ObjectEventAttribute), 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.Load();
        }
Пример #2
0
        public void Load()
        {
            UiTypes = new Dictionary <UIType, IUIFactory>();

            Type[] types = DllHelper.GetHotfixTypes();

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(UIFactoryAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                UIFactoryAttribute attribute = attrs[0] as UIFactoryAttribute;
                if (UiTypes.ContainsKey((UIType)attribute.Type))
                {
                    Log.Debug($"已经存在同类UI Factory: {attribute.Type}");
                    throw new Exception($"已经存在同类UI Factory: {attribute.Type}");
                }
                object     o       = Activator.CreateInstance(type);
                IUIFactory factory = o as IUIFactory;
                if (factory == null)
                {
                    Log.Error($"{o.GetType().FullName} 没有继承 IUIFactory");
                    continue;
                }
                this.UiTypes.Add((UIType)attribute.Type, factory);
            }
        }
Пример #3
0
        public void Load()
        {
            this.UiTypes = new Dictionary <int, IUIFactory>();

            Type[] types = DllHelper.GetHotfixTypes();

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(UIFactoryAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                UIFactoryAttribute attribute = attrs[0] as UIFactoryAttribute;
                if (this.UiTypes.ContainsKey(attribute.Type))
                {
                    throw new Exception($"已经存在同类UI Factory: {attribute.Type}");
                }

                IUIFactory iuiFactory = new IILUIFactoryMethod(type);

                this.UiTypes.Add(attribute.Type, iuiFactory);
            }
        }
Пример #4
0
        private void Load()
        {
            this.allConfig = new Dictionary <Type, ICategory>();
            Type[] types = DllHelper.GetHotfixTypes();

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ConfigAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                object obj = Activator.CreateInstance(type);

                ICategory iCategory = obj as ICategory;
                if (iCategory == null)
                {
                    throw new Exception($"class: {type.Name} not inherit from ACategory");
                }
                iCategory.BeginInit();
                iCategory.EndInit();

                this.allConfig[iCategory.ConfigType] = iCategory;
            }
        }
Пример #5
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();
        }
Пример #6
0
        public void Load()
        {
            this.handlers.Clear();

            Model.MessageDispatherComponent messageDispatherComponent = Game.Scene.GetComponent <Model.MessageDispatherComponent>();
            Model.OpcodeTypeComponent       opcodeTypeComponent       = Game.Scene.GetComponent <Model.OpcodeTypeComponent>();

            Type[] types = DllHelper.GetHotfixTypes();

            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                IMHandler iMHandler = Activator.CreateInstance(type) as IMHandler;
                if (iMHandler == null)
                {
                    Log.Error($"message handle {type.Name} 需要继承 IMHandler");
                    continue;
                }

                Type   messageType = iMHandler.GetMessageType();
                ushort opcode      = this.Entity.GetComponent <OpcodeTypeComponent>().GetOpcode(messageType);
                if (opcode != 0)
                {
                    this.RegisterHandler(opcode, iMHandler);
                }

                // 尝试注册到mono层
                if (messageDispatherComponent != null && opcodeTypeComponent != null)
                {
                    ushort monoOpcode = opcodeTypeComponent.GetOpcode(messageType);
                    if (monoOpcode == 0)
                    {
                        continue;
                    }

                    MessageProxy messageProxy = new MessageProxy(messageType, (session, o) => { iMHandler.Handle(session, o); });
                    messageDispatherComponent.RegisterHandler(monoOpcode, messageProxy);
                }
            }
        }
Пример #7
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();
        }
Пример #8
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);
                }
            }
        }
Пример #9
0
        public void Load()
        {
            this.handlers = new Dictionary <ushort, List <IMHandler> >();

            Type[] types = DllHelper.GetHotfixTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0];
                IMHandler iMHandler = (IMHandler)Activator.CreateInstance(type);
                if (!this.handlers.ContainsKey(messageHandlerAttribute.Opcode))
                {
                    this.handlers.Add(messageHandlerAttribute.Opcode, new List <IMHandler>());
                }
                this.handlers[messageHandlerAttribute.Opcode].Add(iMHandler);
            }
        }
Пример #10
0
        public void Awake()
        {
            Type[] types = DllHelper.GetHotfixTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(MessageAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                MessageAttribute messageAttribute = attrs[0] as MessageAttribute;
                if (messageAttribute == null)
                {
                    continue;
                }

                this.opcodeTypes.Add(messageAttribute.Opcode, type);

                ProtoBuf.PType.RegisterType(type.FullName, type);
            }
        }
Пример #11
0
        public EventSystem()
        {
            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);

                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();
        }