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 MvcMiddleware(RequestDelegate next, HttpComponent httpComponent) { _next = next; _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(httpComponent.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); LoadMethod(type, httpHandlerAttribute, ihttpHandler); } }
public void Load() { this.allConfig.Clear(); 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); ACategory iCategory = obj as ACategory; if (iCategory == null) { throw new Exception($"class: {type.Name} not inherit from ACategory"); } iCategory.BeginInit(); iCategory.EndInit(); this.allConfig[iCategory.ConfigType] = iCategory; } }
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); } }
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); } }
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); } }
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); }); } }
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 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); } } }
public static void Load(this MessageDispatherComponent self) { self.Handlers.Clear(); AppType appType = Game.Scene.GetComponent <StartConfigComponent>().StartConfig.AppType; Type[] types = DllHelper.GetMonoTypes(); foreach (Type type in types) { object[] attrs = type.GetCustomAttributes(typeof(MessageHandlerAttribute), false); if (attrs.Length == 0) { continue; } MessageHandlerAttribute messageHandlerAttribute = attrs[0] as MessageHandlerAttribute; if (!messageHandlerAttribute.Type.Is(appType)) { 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); } }
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); } } this.Load(); }
public void Add(DLLType dllType, Assembly assembly) { this.assemblies[dllType] = assembly; this.awakeSystems.Clear(); this.lateUpdateSystems.Clear(); this.updateSystems.Clear(); this.startSystems.Clear(); this.loadSystems.Clear(); this.changeSystems.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); IAwakeSystem objectSystem = obj as IAwakeSystem; if (objectSystem != null) { this.awakeSystems.Add(objectSystem.Type(), objectSystem); } IUpdateSystem updateSystem = obj as IUpdateSystem; if (updateSystem != null) { this.updateSystems.Add(updateSystem.Type(), updateSystem); } ILateUpdateSystem lateUpdateSystem = obj as ILateUpdateSystem; if (lateUpdateSystem != null) { this.lateUpdateSystems.Add(lateUpdateSystem.Type(), lateUpdateSystem); } IStartSystem startSystem = obj as IStartSystem; if (startSystem != null) { this.startSystems.Add(startSystem.Type(), startSystem); } IDestroySystem destroySystem = obj as IDestroySystem; if (destroySystem != null) { this.destroySystems.Add(destroySystem.Type(), destroySystem); } ILoadSystem loadSystem = obj as ILoadSystem; if (loadSystem != null) { this.loadSystems.Add(loadSystem.Type(), loadSystem); } IChangeSystem changeSystem = obj as IChangeSystem; if (changeSystem != null) { this.changeSystems.Add(changeSystem.Type(), changeSystem); } } 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); } } this.Load(); }