コード例 #1
0
        public static void Load(this ActorMessageDispatherComponent self)
        {
            AppType appType = self.Entity.GetComponent <StartConfigComponent>().StartConfig.AppType;

            self.ActorMessageHandlers.Clear();
            self.ActorTypeHandlers.Clear();

            Type[] types = DllHelper.GetMonoTypes();

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

                ActorTypeHandlerAttribute actorTypeHandlerAttribute = (ActorTypeHandlerAttribute)attrs[0];
                if (!actorTypeHandlerAttribute.appType.Is(appType))
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                IActorTypeHandler iActorTypeHandler = obj as IActorTypeHandler;
                if (iActorTypeHandler == null)
                {
                    throw new Exception($"actor handler not inherit IEntityActorHandler: {obj.GetType().FullName}");
                }

                self.ActorTypeHandlers.Add(actorTypeHandlerAttribute.actorType, iActorTypeHandler);
            }

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

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

                object obj = Activator.CreateInstance(type);

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

                Type messageType = imHandler.GetMessageType();
                self.ActorMessageHandlers.Add(messageType, imHandler);
            }
        }
コード例 #2
0
        public static void Load(this MessageDispatherComponent self)
        {
            self.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      = Game.Scene.GetComponent <OpcodeTypeComponent>().GetOpcode(messageType);
                if (opcode == 0)
                {
                    Log.Error($"消息opcode为0: {messageType.Name}");
                    continue;
                }
                self.RegisterHandler(opcode, iMHandler);
            }
        }
コード例 #3
0
        public static Dictionary <string, NodeMeta> ExportToDict()
        {
            Dictionary <string, NodeMeta> name2NodeProtoDict = new Dictionary <string, NodeMeta>();

            Type[] types = DllHelper.GetMonoTypes();
            foreach (Type type in types)
            {
                NodeMeta proto = GetNodeTypeProtoFromType(type);
                if (proto == null)
                {
                    continue;
                }
                name2NodeProtoDict.Add(proto.name, proto);
            }
            return(name2NodeProtoDict);
        }