Exemple #1
0
        public void Load()
        {
            AppType appType = this.Entity.GetComponent <StartConfigComponent>().StartConfig.AppType;

            Log.Info("apptype: " + appType);
            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(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);
            }
        }
        public static void Load(this ActorMessageDispatcherComponent self)
        {
            AppType appType = StartConfigComponent.Instance.StartConfig.AppType;

            self.ActorMessageHandlers.Clear();

            HashSet <Type> types = Game.EventSystem.GetTypes(typeof(ActorMessageHandlerAttribute));

            types = Game.EventSystem.GetTypes(typeof(ActorMessageHandlerAttribute));
            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(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);
            }
        }
Exemple #3
0
        public static void Load(this ActorMessageDispatcherComponent self)
        {
            self.ActorMessageHandlers.Clear();

            var types = Game.EventSystem.GetTypes(typeof(ActorMessageHandlerAttribute));

            foreach (Type type in types)
            {
                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.GetRequestType();

                Type handleResponseType = imHandler.GetResponseType();
                if (handleResponseType != null)
                {
                    Type responseType = OpcodeTypeComponent.Instance.GetResponseType(messageType);
                    if (handleResponseType != responseType)
                    {
                        throw new Exception($"message handler response type error: {messageType.FullName}");
                    }
                }

                self.ActorMessageHandlers.Add(messageType, imHandler);
            }
        }
Exemple #4
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);
            }
        }
Exemple #5
0
		public static void Load(this ActorMessageDispatcherComponent self)
		{
			self.ActorMessageHandlers.Clear();

			HashSet<Type> types = Game.EventSystem.GetTypes(typeof (ActorMessageHandlerAttribute));
			foreach (Type type in types)
			{
				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);
			}
		}
Exemple #6
0
        public static void Load(this ActorMessageDispatcherComponent self)
        {
            self.ActorMessageHandlers.Clear();

            var types = Game.EventSystem.GetTypes(typeof(ActorMessageHandlerAttribute));

            foreach (Type type in types)
            {
                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}");
                }

                object[] attrs = type.GetCustomAttributes(typeof(ActorMessageHandlerAttribute), false);

                foreach (object attr in attrs)
                {
                    ActorMessageHandlerAttribute actorMessageHandlerAttribute = attr as ActorMessageHandlerAttribute;

                    Type messageType = imHandler.GetRequestType();

                    Type handleResponseType = imHandler.GetResponseType();
                    if (handleResponseType != null)
                    {
                        Type responseType = OpcodeTypeComponent.Instance.GetResponseType(messageType);
                        if (handleResponseType != responseType)
                        {
                            throw new Exception($"message handler response type error: {messageType.FullName}");
                        }
                    }

                    ActorMessageDispatcherInfo actorMessageDispatcherInfo = new ActorMessageDispatcherInfo(actorMessageHandlerAttribute.SceneType, imHandler);

                    self.RegisterHandler(messageType, actorMessageDispatcherInfo);
                }
            }
        }
Exemple #7
0
 public static bool TryGetHandler(this ActorMessageDispatcherComponent self, Type type, out IMActorHandler actorHandler)
 {
     return(self.ActorMessageHandlers.TryGetValue(type, out actorHandler));
 }
Exemple #8
0
 public ActorMessageDispatcherInfo(SceneType sceneType, IMActorHandler imActorHandler)
 {
     this.SceneType      = sceneType;
     this.IMActorHandler = imActorHandler;
 }
Exemple #9
0
        /// <summary>
        /// Awake()时候会被执行
        /// </summary>
        /// <param name="self"></param>
        public static void Load(this ActorMessageDispatherComponent self)
        {
            //得到服务器类型
            AppType appType = StartConfigComponent.Instance.StartConfig.AppType;

            self.ActorMessageHandlers.Clear(); //清空ActorMessage
            self.ActorTypeHandlers.Clear();    //清空Actor处理函数

            List <Type> types = Game.EventSystem.GetTypes(typeof(ActorInterceptTypeHandlerAttribute));

            foreach (Type type in types)             //加载所有的Actor处理函数到字典中
            {
                object[] attrs = type.GetCustomAttributes(typeof(ActorInterceptTypeHandlerAttribute), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                ActorInterceptTypeHandlerAttribute actorInterceptTypeHandlerAttribute = (ActorInterceptTypeHandlerAttribute)attrs[0];
                if (!actorInterceptTypeHandlerAttribute.Type.Is(appType))                    //每个服务器只会加载自身的actor相关类 方法
                {
                    continue;
                }

                object obj = Activator.CreateInstance(type);

                IActorInterceptTypeHandler iActorInterceptTypeHandler = obj as IActorInterceptTypeHandler;
                if (iActorInterceptTypeHandler == null)
                {
                    throw new Exception($"actor handler not inherit IEntityActorHandler: {obj.GetType().FullName}");
                }
                //直接把传参ActorType作为key使用
                self.ActorTypeHandlers.Add(actorInterceptTypeHandlerAttribute.ActorType, iActorInterceptTypeHandler);
            }

            types = Game.EventSystem.GetTypes(typeof(ActorMessageHandlerAttribute));
            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(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();                  //获取消息的类型作为key
                self.ActorMessageHandlers.Add(messageType, imHandler);
            }
        }