Exemple #1
0
        public void Load()
        {
            this.opcodeTypes.Clear();
            this.typeMessages.Clear();

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

            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);
                this.typeMessages.Add(messageAttribute.Opcode, Activator.CreateInstance(type));
            }
        }
        //加载
        public void Load()
        {
            //数据结构的初始化
            this.opcodeTypes.Clear();
            this.typeMessages.Clear();

            //找到所有MessageAttribute特性的class
            List <Type> types = Game.EventSystem.GetTypes(typeof(MessageAttribute));

            foreach (Type type in types)
            {
                //找到非继承的 加了MessageAttribute为特性的类
                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);
                //加入的时候 并且通过它的类型创建实例
                this.typeMessages.Add(messageAttribute.Opcode, Activator.CreateInstance(type));
            }
        }
Exemple #3
0
        public virtual void Load(ComponentNetworkOuter outer, ComponentNetworkInner inner)
        {
            networkOuter = outer;
            networkInner = inner;

            Handlers.Clear();
            // 网络消息绑定数据结构
            List <Type> types = AssemblyHelper.GetTypes();

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

                Handlers.Add(messageAttribute.Opcode, messageAttribute.appType);
            }
        }
Exemple #4
0
        public override void Awake(JToken jd = null)
        {
            this.opcodeTypes.Clear();
            this.typeMessages.Clear();

            // 网络消息绑定数据结构
            List <Type> types = AssemblyHelper.GetTypes();

            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);
                this.typeMessages.Add(messageAttribute.Opcode, Activator.CreateInstance(type));
            }

            foreach (Type type in types)
            {
                object[] attrs = type.GetMethods();
                if (attrs.Length == 0)
                {
                    continue;
                }
                foreach (MethodInfo methodInfo in attrs)
                {
                    object[] attrs2 = methodInfo.GetCustomAttributes(typeof(MessageMethodAttribute), false);
                    if (attrs2.Length == 0)
                    {
                        continue;
                    }
                    MessageMethodAttribute attribute = attrs2[0] as MessageMethodAttribute;
                    if (attribute == null)
                    {
                        continue;
                    }

                    if (!methodInfo.IsStatic)
                    {
                        Log.Debug($"MessageMethod {type.Name}.{methodInfo.Name} 不是静态函数,将被忽略!");
                        continue;
                    }

                    Action <Session, int, object> dd = (Action <Session, int, object>)Delegate.CreateDelegate(typeof(Action <Session, int, object>), null, methodInfo);
                    this.registerMsg(attribute.Opcode, dd);
                }
            }
        }
        public void Awake()
        {
            Type[] types = DllHelper.GetMonoTypes();
            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);
            }
        }
        public void Awake()
        {
            List <Type> types = Game.EventSystem.GetTypes();

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