Ejemplo n.º 1
0
        public ObjectManager()
        {
            this.disposerEvents.Clear();

            Type[] types = HotFixHelper.GetHotfixTypes();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(ObjectEventFacadeAttribute), false);

                if (attrs.Length == 0)
                {
                    continue;
                }

                object             obj          = Activator.CreateInstance(type);
                IObjectEventFacade objectSystem = obj as IObjectEventFacade;
                if (objectSystem == null)
                {
                    Logger.LogError($"组件事件没有继承IObjectEvent: {type.Name}");

                    continue;
                }
                this.disposerEvents[objectSystem.Type()] = objectSystem;
            }

            this.Load();
        }
Ejemplo n.º 2
0
        public static void Init()
        {
            Type[] tmpTypes = HotFixHelper.GetHotfixTypes();

            Type tmpCommandAttributeType        = typeof(CommandAttribute);
            Type tmpCommandHandlerAttributeType = typeof(CommandHandlerAttribute);
            Type tmpCommandHandleAttributeType  = typeof(CommandHandleAttribute);

            foreach (Type typeElem in tmpTypes)
            {
                //协议信息
                var tmpCommandAttributes    = typeElem.GetCustomAttributes(tmpCommandAttributeType, false);
                CommandAttribute tmpCommand = tmpCommandAttributes.Length > 0 ? tmpCommandAttributes[0] as CommandAttribute : null;

                if (null != tmpCommand)
                {
                    if (!sCommandOpcode2TypeDict.ContainsKey(tmpCommand.Opcode))
                    {
                        sCommandOpcode2TypeDict.Add(tmpCommand.Opcode, typeElem);
                    }

                    if (!sCommandType2FieldInfoDict.ContainsKey(typeElem))
                    {
                        FieldInfo tmpFieldInfo = typeElem.GetField("Data");
                        if (null == tmpFieldInfo)
                        {
                            Logger.LogError("消息中不包含data数据");
                        }
                        else
                        {
                            sCommandType2FieldInfoDict.Add(typeElem, tmpFieldInfo);
                        }
                    }
                }

                //协议观察者信息
                var tmpCommandHandlerAttris = typeElem.GetCustomAttributes(tmpCommandHandlerAttributeType, false);
                CommandHandlerAttribute tmpCommandHandler = null;

                if (tmpCommandHandlerAttris.Length > 0)
                {
                    tmpCommandHandler = tmpCommandHandlerAttris[0] as CommandHandlerAttribute;
                }

                if (null == tmpCommandHandler)
                {
                    continue;
                }

                MethodInfo[] tmpMethods = typeElem.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

                foreach (MethodInfo methodInfoElem in tmpMethods)
                {
                    var tmpCommandHandleAttris = methodInfoElem.GetCustomAttributes(tmpCommandHandleAttributeType, false);
                    CommandHandleAttribute tmpCommandHandle = null;

                    if (tmpCommandHandleAttris.Length > 0)
                    {
                        tmpCommandHandle = tmpCommandHandleAttris[0] as CommandHandleAttribute;
                    }

                    if (null == tmpCommandHandle)
                    {
                        continue;
                    }
                    //ILRT暂不支持GetParameters
                    //ParameterInfo[] tmpParameters = methodInfoElem.GetParameters();

                    //if (tmpParameters.Length > 0 && tmpParameters[0].ParameterType != tmpCommandHandle.CommandType)
                    //{
                    //    Logger.LogError("消息处理方法形参类型错误 " + typeElem + " -> " + methodInfoElem.Name);
                    //    continue;
                    //}

                    List <MethodInfo> tmpMethodInfoList = null;
                    if (!sOpcode2MethodInfosDict.TryGetValue(tmpCommandHandle.Opcode, out tmpMethodInfoList))
                    {
                        tmpMethodInfoList = new List <MethodInfo>();
                        sOpcode2MethodInfosDict.Add(tmpCommandHandle.Opcode, tmpMethodInfoList);
                    }

                    tmpMethodInfoList.Add(methodInfoElem);
                }
            }
        }