Exemplo n.º 1
0
        public void Load()
        {
            this.handlers.Clear();

            Type[] types = DllHelper.GetMonoTypes();

            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)
                {
                    Log.Error($"消息opcode为0: {messageType.Name}");
                    continue;
                }
                this.RegisterHandler(opcode, iMHandler);
            }
        }
Exemplo n.º 2
0
        public void Load()
        {
            this.allConfig = new Dictionary <Type, ICategory>();
            Type[] types = DllHelper.GetMonoTypes();

            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;
            }
        }
Exemplo n.º 3
0
        public void Load()
        {
            this.UiTypes.Clear();

            Type[] types = DllHelper.GetMonoTypes();

            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);
            }
        }
Exemplo n.º 4
0
        public void Load()
        {
            this.dictionary = new Dictionary <string, Func <NodeProto, Node> >();
            this.treeCache  = new Dictionary <GameObject, BehaviorTree>();


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

                Type classType = type;
                if (this.dictionary.ContainsKey(type.Name))
                {
                    throw new Exception($"已经存在同类节点: {classType.Name}");
                }
                this.dictionary.Add(type.Name, config =>
                {
                    Node node = (Node)Activator.CreateInstance(classType, config);
                    try
                    {
                        InitFieldValue(ref node, config);
                    }
                    catch (Exception e)
                    {
                        throw new Exception($"InitFieldValue error, node: {node.Id} {node.Type}", e);
                    }
                    return(node);
                });
            }
        }
Exemplo n.º 5
0
        private void Load()
        {
            this.UiTypes = new Dictionary <int, IUIFactory>();

#if ILRuntime
            Type[] types = DllHelper.GetHotfixTypes();
#else
            Type[] types = DllHelper.GetMonoTypes();
#endif
            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 GameException($"已经存在同类UI Factory: {attribute.Type}");
                }

#if ILRuntime
                IUIFactory iuiFactory = new IILUIFactoryMethod(type);
#else
                IUIFactory iuiFactory = new IMonoUIFactoryMethod(type);
#endif

                this.UiTypes.Add(attribute.Type, iuiFactory);
            }
        }
Exemplo n.º 6
0
        public void Load()
        {
            this.dispatcher = new Dictionary <string, IHttpHandler>();

            Type[] types = DllHelper.GetMonoTypes();

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

                HttpHandlerAttribute httpHandlerAttribute = (HttpHandlerAttribute)attrs[0];
                if (!httpHandlerAttribute.AppType.Is(this.appType))
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                IHttpHandler ihttpHandler = obj as IHttpHandler;
                if (ihttpHandler == null)
                {
                    throw new Exception($"HttpHandler handler not inherit IHttpHandler class: {obj.GetType().FullName}");
                }
                this.dispatcher.Add(httpHandlerAttribute.Path, ihttpHandler);
            }
        }
Exemplo n.º 7
0
        public void Load()
        {
            this.handlers = new Dictionary <Type, IMActorHandler>();

            Type[] types = DllHelper.GetMonoTypes();

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

                ActorMessageHandlerAttribute messageHandlerAttribute = (ActorMessageHandlerAttribute)attrs[0];
                if (!messageHandlerAttribute.Type.Is(this.AppType))
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                IMActorHandler imHandler = obj as IMActorHandler;
                if (imHandler == null)
                {
                    throw new Exception($"message handler not inherit AMEvent or AMRpcEvent abstract class: {obj.GetType().FullName}");
                }

                Type messageType = imHandler.GetMessageType();
                handlers.Add(messageType, imHandler);
            }
        }
Exemplo n.º 8
0
        private void Load()
        {
            this.handlers      = new Dictionary <ushort, List <IMHandler> >();
            this.messageOpcode = new Dictionary <Type, MessageAttribute>();
            this.opcodeType    = new Dictionary <ushort, Type>();

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

                MessageAttribute messageAttribute = (MessageAttribute)attrs[0];
                this.messageOpcode[type] = messageAttribute;
                this.opcodeType[messageAttribute.Opcode] = type;
            }

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

                MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0];
                if (!messageHandlerAttribute.Type.Is(this.AppType))
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                IMHandler imHandler = obj as IMHandler;
                if (imHandler == null)
                {
                    throw new Exception($"message handler not inherit AMEvent or AMRpcEvent abstract class: {obj.GetType().FullName}");
                }

                Type             messageType = imHandler.GetMessageType();
                ushort           opcode      = this.GetOpcode(messageType);
                List <IMHandler> list;
                if (!this.handlers.TryGetValue(opcode, out list))
                {
                    list = new List <IMHandler>();
                    this.handlers.Add(opcode, list);
                }
                list.Add(imHandler);
            }
        }
Exemplo n.º 9
0
        private void Load()
        {
            this.handlers    = new Dictionary <ushort, List <IInstanceMethod> >();
            this.opcodeTypes = new DoubleMap <ushort, Type>();

            Type[] monoTypes = DllHelper.GetMonoTypes();
            foreach (Type monoType in monoTypes)
            {
                object[] attrs = monoType.GetCustomAttributes(typeof(MessageAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

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

                this.opcodeTypes.Add(messageAttribute.Opcode, monoType);
            }

#if ILRuntime
            Type[] types = DllHelper.GetHotfixTypes();
#else
            Type[] types = DllHelper.GetMonoTypes();
#endif
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0];
#if ILRuntime
                IInstanceMethod method = new ILInstanceMethod(type, "Handle");
#else
                IInstanceMethod method = new MonoInstanceMethod(type, "Handle");
#endif
                if (!this.handlers.ContainsKey(messageHandlerAttribute.Opcode))
                {
                    this.handlers.Add(messageHandlerAttribute.Opcode, new List <IInstanceMethod>());
                }
                this.handlers[messageHandlerAttribute.Opcode].Add(method);
            }
        }
Exemplo n.º 10
0
        public void Add(DLLType dllType, Assembly assembly)
        {
            this.assemblies[dllType] = assembly;

            this.disposerEvents.Clear();

            Type[] types = DllHelper.GetMonoTypes();
            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();
        }
Exemplo n.º 11
0
        public void Load()
        {
            handlers = new Dictionary <Opcode, List <IMessageMethod> >();

            Type[] types = DllHelper.GetMonoTypes();

            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((Opcode)messageHandlerAttribute.Opcode))
                {
                    this.handlers.Add((Opcode)messageHandlerAttribute.Opcode, new List <IMessageMethod>());
                }
                this.handlers[(Opcode)messageHandlerAttribute.Opcode].Add(new IMessageMonoMethod(iMHandler));
            }

            // hotfix dll
            Type[] hotfixTypes = DllHelper.GetHotfixTypes();
            foreach (Type type in hotfixTypes)
            {
                object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }
                MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0];
#if ILRuntime
                IMessageMethod iMessageMethod = new IMessageILMethod(type, "Handle");
#else
                IMHandler      iMHandler      = (IMHandler)Activator.CreateInstance(type);
                IMessageMethod iMessageMethod = new IMessageMonoMethod(iMHandler);
#endif
                if (!this.handlers.ContainsKey((Opcode)messageHandlerAttribute.Opcode))
                {
                    this.handlers.Add((Opcode)messageHandlerAttribute.Opcode, new List <IMessageMethod>());
                }
                this.handlers[(Opcode)messageHandlerAttribute.Opcode].Add(iMessageMethod);
            }
        }
 public void Initialize()
 {
     Type[] monoTypes = DllHelper.GetMonoTypes();
     foreach (Type monoType in monoTypes)
     {
         object[] attrs = monoType.GetCustomAttributes(typeof(MessageAttribute), false);
         if (attrs.Length == 0)
         {
             continue;
         }
         MessageAttribute messageAttribute = attrs[0] as MessageAttribute;
         if (messageAttribute == null)
         {
             continue;
         }
         this.mOpcodeTypes.Add(messageAttribute.Opcode, monoType);
     }
 }
Exemplo n.º 13
0
        public void Load()
        {
            this.allEvents = new Dictionary <EventIdType, List <IEventMethod> >();

            Type[] types = DllHelper.GetMonoTypes();
            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 <IEventMethod>());
                    }
                    this.allEvents[(EventIdType)aEventAttribute.Type].Add(new IEventMonoMethod(obj));
                }
            }

            // hotfix dll
            Type[] hotfixTypes = DllHelper.GetHotfixTypes();
            foreach (Type type in hotfixTypes)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);
                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
#if ILRuntime
                    IEventMethod method = new IEventILMethod(type, "Run");
#else
                    object       obj    = Activator.CreateInstance(type);
                    IEventMethod method = new IEventMonoMethod(obj);
#endif
                    if (!allEvents.ContainsKey((EventIdType)aEventAttribute.Type))
                    {
                        allEvents.Add((EventIdType)aEventAttribute.Type, new List <IEventMethod>());
                    }
                    allEvents[(EventIdType)aEventAttribute.Type].Add(method);
                }
            }
        }
Exemplo n.º 14
0
        public void Load()
        {
            this.opcodeType    = new Dictionary <Opcode, Type>();
            this.messageOpcode = new Dictionary <Type, MessageAttribute>();

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

                MessageAttribute messageAttribute = (MessageAttribute)attrs[0];
                this.messageOpcode[type] = messageAttribute;
                this.opcodeType[messageAttribute.Opcode] = type;
            }
        }
Exemplo n.º 15
0
        public void Load()
        {
            this.allWatchers = new Dictionary <NumericType, List <INumericWatcher> >();

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

                foreach (object attr in attrs)
                {
                    NumericWatcherAttribute numericWatcherAttribute = (NumericWatcherAttribute)attr;
                    INumericWatcher         obj = (INumericWatcher)Activator.CreateInstance(type);
                    if (!this.allWatchers.ContainsKey(numericWatcherAttribute.NumericType))
                    {
                        this.allWatchers.Add(numericWatcherAttribute.NumericType, new List <INumericWatcher>());
                    }
                    this.allWatchers[numericWatcherAttribute.NumericType].Add(obj);
                }
            }
        }
Exemplo n.º 16
0
        public void Load()
        {
            this.allEvents = new Dictionary <EventIdType, List <object> >();

            Type[] types = DllHelper.GetMonoTypes();
            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);
                }
            }
        }
Exemplo n.º 17
0
        private void Register()
        {
            Type[] types = DllHelper.GetMonoTypes();
            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);
                }
            }
        }
Exemplo n.º 18
0
        private void Load()
        {
            this.allEvents = new Dictionary <int, List <IInstanceMethod> >();

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

                foreach (object attr in attrs)
                {
                    EventAttribute  aEventAttribute = (EventAttribute)attr;
                    IInstanceMethod method          = new MonoInstanceMethod(type, "Run");
                    if (!this.allEvents.ContainsKey(aEventAttribute.Type))
                    {
                        this.allEvents.Add(aEventAttribute.Type, new List <IInstanceMethod>());
                    }
                    this.allEvents[aEventAttribute.Type].Add(method);
                }
            }
#if ILRuntime
            types = DllHelper.GetHotfixTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);

                foreach (object attr in attrs)
                {
                    EventAttribute  aEventAttribute = (EventAttribute)attr;
                    IInstanceMethod method          = new ILInstanceMethod(type, "Run");
                    if (!this.allEvents.ContainsKey(aEventAttribute.Type))
                    {
                        this.allEvents.Add(aEventAttribute.Type, new List <IInstanceMethod>());
                    }
                    this.allEvents[aEventAttribute.Type].Add(method);
                }
            }
#endif
        }
Exemplo n.º 19
0
        public void Load()
        {
            handlers = new Dictionary <ushort, List <IMHandler> >();

            Type[] types = DllHelper.GetMonoTypes();

            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);
            }
        }
        public void Load()
        {
            AppType appType = this.Parent.GetComponent <StartConfigComponent>().StartConfig.AppType;

            this.handlers = new Dictionary <Type, List <IMHandler> >();

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

                MessageHandlerAttribute messageHandlerAttribute = (MessageHandlerAttribute)attrs[0];
                if (!messageHandlerAttribute.Type.Is(appType))
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                IMHandler imHandler = obj as IMHandler;
                if (imHandler == null)
                {
                    throw new Exception($"message handler not inherit AMEvent or AMRpcEvent abstract class: {obj.GetType().FullName}");
                }

                Type messageType = imHandler.GetMessageType();
                if (!this.handlers.TryGetValue(messageType, out List <IMHandler> list))
                {
                    list = new List <IMHandler>();
                    this.handlers.Add(messageType, list);
                }
                list.Add(imHandler);
            }
        }
Exemplo n.º 21
0
        public void Add(DLLType dllType, Assembly assembly)
        {
            this.assemblies[dllType] = assembly;

            this.awakeEvents.Clear();
            this.lateUpdateEvents.Clear();
            this.updateEvents.Clear();
            this.startEvents.Clear();
            this.loadEvents.Clear();

            Type[] types = DllHelper.GetMonoTypes();
            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);
                }
            }
        }
Exemplo n.º 22
0
        public void Add(DLLType dllType, Assembly assembly)
        {
            this.assemblies[dllType] = assembly;

            this.awakeEvents.Clear();
            this.lateUpdateEvents.Clear();
            this.updateEvents.Clear();
            this.startEvents.Clear();
            this.loadEvents.Clear();

            Type[] types = DllHelper.GetMonoTypes();
            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);
                }
            }


            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();
        }
Exemplo n.º 23
0
        private void Register()
        {
            Type[] types = DllHelper.GetMonoTypes();
            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.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 <IEventMethod>());
                    }
                    this.allEvents[(EventIdType)aEventAttribute.Type].Add(new IEventMonoMethod(obj));
                }
            }

            // hotfix dll
            Type[] hotfixTypes = DllHelper.GetHotfixTypes();
            foreach (Type type in hotfixTypes)
            {
                object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);
                foreach (object attr in attrs)
                {
                    EventAttribute aEventAttribute = (EventAttribute)attr;
#if ILRuntime
                    IEventMethod method = new IEventILMethod(type, "Run");
#else
                    object       obj    = Activator.CreateInstance(type);
                    IEventMethod method = new IEventMonoMethod(obj);
#endif
                    if (!allEvents.ContainsKey((EventIdType)aEventAttribute.Type))
                    {
                        allEvents.Add((EventIdType)aEventAttribute.Type, new List <IEventMethod>());
                    }
                    allEvents[(EventIdType)aEventAttribute.Type].Add(method);
                }
            }
        }
Exemplo n.º 24
0
        public void LoadAssemblyInfo()
        {
            this.eventInfo           = new Dictionary <int, EntityTypeInfo>();
            this.typeToEntityEventId = new Dictionary <Type, int>();

            Type[]        types         = DllHelper.GetMonoTypes();
            List <string> allEntityType = Enum.GetNames(typeof(EntityEventType)).ToList();

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

                EntityEventAttribute entityEventAttribute = attrs[0] as EntityEventAttribute;

                int entityEventId = entityEventAttribute.ClassType;

                this.typeToEntityEventId[type] = entityEventId;

                if (!this.eventInfo.ContainsKey(entityEventId))
                {
                    this.eventInfo.Add(entityEventId, new EntityTypeInfo());
                }

                MethodInfo[] methodInfos = type.GetMethods(
                    BindingFlags.Instance | BindingFlags.Static | BindingFlags.InvokeMethod |
                    BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
                foreach (MethodInfo methodInfo in methodInfos)
                {
                    int n = methodInfo.GetParameters().Length;
                    if (methodInfo.IsStatic)
                    {
                        --n;
                    }

                    string sn = n > 0 ? $"{methodInfo.Name}{n}" : methodInfo.Name;
                    if (!allEntityType.Contains(sn))
                    {
                        continue;
                    }

                    EntityEventType t = EnumHelper.FromString <EntityEventType>(sn);
                    this.eventInfo[entityEventId].Add(t, new MonoStaticMethod(methodInfo));
                }
            }

#if !SERVER
            if (this.appDomain == null)
            {
                return;
            }

            IType[] ilTypes = this.appDomain.LoadedTypes.Values.ToArray();
            foreach (IType itype in ilTypes)
            {
                Type     type  = itype.ReflectionType;
                object[] attrs = type.GetCustomAttributes(typeof(EntityEventAttribute), true);
                if (attrs.Length == 0)
                {
                    continue;
                }

                EntityEventAttribute entityEventAttribute = attrs[0] as EntityEventAttribute;

                int entityEventId = entityEventAttribute.ClassType;

                if (!this.eventInfo.ContainsKey(entityEventId))
                {
                    this.eventInfo.Add(entityEventId, new EntityTypeInfo());
                }

                foreach (IMethod methodInfo in itype.GetMethods())
                {
                    int n = methodInfo.ParameterCount;
                    if (methodInfo.IsStatic)
                    {
                        --n;
                    }

                    string sn = n > 0 ? $"{methodInfo.Name}{n}" : methodInfo.Name;
                    if (!allEntityType.Contains(sn))
                    {
                        continue;
                    }

                    EntityEventType t = EnumHelper.FromString <EntityEventType>(sn);
                    this.eventInfo[entityEventId].Add(t, new ILStaticMethod(methodInfo, n));
                }
            }
#endif
        }