public void Awake <P1, P2, P3, P4>(Entity component, P1 p1, P2 p2, P3 p3, P4 p4) { List <object> iAwakeSystems = this.typeSystems.GetSystems(component.GetType(), typeof(IAwakeSystem <P1, P2, P3, P4>)); if (iAwakeSystems == null) { return; } for (int i = 0; i < iAwakeSystems.Count; ++i) { IAwakeSystem <P1, P2, P3, P4> aAwakeSystem = iAwakeSystems[i] as IAwakeSystem <P1, P2, P3, P4>; if (aAwakeSystem == null) { continue; } try { aAwakeSystem.Run(component, p1, p2, p3, p4); } catch (Exception e) { Log.Error(e); } } }
public void Awake(Entity component) { List <object> iAwakeSystems = this.typeSystems.GetSystems(component.GetType(), typeof(IAwakeSystem)); if (iAwakeSystems == null) { return; } for (int i = 0; i < iAwakeSystems.Count; ++i) { IAwakeSystem aAwakeSystem = iAwakeSystems[i] as IAwakeSystem; if (aAwakeSystem == null) { continue; } try { aAwakeSystem.Run(component); } catch (Exception e) { Log.Error(e); } } }
public void Add(DLLType dllType, Assembly assembly) { this.assemblies[dllType] = assembly; this.types.Clear(); foreach (Assembly value in this.assemblies.Values) { foreach (Type type in value.GetTypes()) { object[] objects = type.GetCustomAttributes(typeof(BaseAttribute), false); if (objects.Length == 0) { continue; } BaseAttribute baseAttribute = (BaseAttribute)objects[0]; this.types.Add(baseAttribute.AttributeType, type); } } this.awakeSystems.Clear(); this.lateUpdateSystems.Clear(); this.updateSystems.Clear(); this.startSystems.Clear(); this.loadSystems.Clear(); this.changeSystems.Clear(); foreach (Type type in types[typeof(ObjectSystemAttribute)]) { 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.Load(); }
public EventSystem() { Type[] types = ETModel.Game.Hotfix.GetHotfixTypes(); 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.awakeEvents.Add(objectSystem.Type(), objectSystem); } IUpdateSystem updateSystem = obj as IUpdateSystem; if (updateSystem != null) { this.updateEvents.Add(updateSystem.Type(), updateSystem); } ILateUpdateSystem lateUpdateSystem = obj as ILateUpdateSystem; if (lateUpdateSystem != null) { this.lateUpdateEvents.Add(lateUpdateSystem.Type(), lateUpdateSystem); } IStartSystem startSystem = obj as IStartSystem; if (startSystem != null) { this.startEvents.Add(startSystem.Type(), startSystem); } IDestroySystem destroySystem = obj as IDestroySystem; if (destroySystem != null) { this.desdroyEvents.Add(destroySystem.Type(), destroySystem); } ILoadSystem loadSystem = obj as ILoadSystem; if (loadSystem != null) { this.loadEvents.Add(loadSystem.Type(), loadSystem); } } 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); // hotfix的事件也要注册到mono层,hotfix可以订阅mono层的事件 Action <List <object> > action = list => { Handle(aEventAttribute.Type, list); }; ETModel.Game.EventSystem.RegisterEvent(aEventAttribute.Type, new EventProxy(action)); } } this.Load(); }
private readonly Queue <long> starts = new Queue <long>(); //这个只需要一个 因为starts只会执行一次 /// <summary> /// 加载程序集 /// </summary> /// <param name="dllType"></param> /// <param name="assembly"></param> public void Add(DLLType dllType, Assembly assembly) { this.assemblies[dllType] = assembly; this.types.Clear(); //清空 foreach (Assembly value in this.assemblies.Values) { foreach (Type type in value.GetTypes()) { object[] objects = type.GetCustomAttributes(typeof(BaseAttribute), false); //有BaseAttribute特性的类 if (objects.Length == 0) { continue; } BaseAttribute baseAttribute = (BaseAttribute)objects[0]; this.types.Add(baseAttribute.AttributeType, type); //把类根据其特性的类型 加入到不同的字典中 } } this.awakeSystems.Clear(); this.lateUpdateSystems.Clear(); this.updateSystems.Clear(); this.startSystems.Clear(); this.loadSystems.Clear(); this.changeSystems.Clear(); foreach (Type type in types[typeof(ObjectSystemAttribute)]) //遍历有ObjectSystem特性的类 { object[] attrs = type.GetCustomAttributes(typeof(ObjectSystemAttribute), false); //再次检查 if (attrs.Length == 0) { continue; } object obj = Activator.CreateInstance(type); //实例化 //比如 public class TimerComponentUpdateSystem : UpdateSystem<TimerComponent> // 我们写的功能都在 TimerComponent 中 它里面有 start update 等方法 但是不用我们来调用 // TimerComponentUpdateSystem 类会自动帮我们调用 其中的 update 方法 // updateSystems 字典中会保存 TimerComponent类名 和 TimerComponentUpdateSystem 这个类 // 当 TimerComponent 这个类生成的时候 updateSystems 字典中检索到了 有这个类名 就会调用TimerComponentUpdateSystem // 而 TimerComponentUpdateSystem 的传参是 TimerComponent 他会自动调用 TimerComponent 中的方法 IAwakeSystem objectSystem = obj as IAwakeSystem; if (objectSystem != null) { this.awakeSystems.Add(objectSystem.Type(), objectSystem); //!!!这里的objectSystem.Type()其实就是需要执行的类的类型 所以他能收集对应的类的方法 } 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[typeof(EventAttribute)]) { 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) //判断类是否继承IEvent接口 { Log.Error($"{obj.GetType().Name} 没有继承IEvent"); } this.RegisterEvent(aEventAttribute.Type, iEvent); //加入字典中 } } this.Load(); }
public EventSystem() { this.types.Clear(); //获取所有热更新层类的Type List <Type> ts = GameEntry.ILRuntime.GetHotfixTypes(); foreach (Type type in ts) { // ILRuntime无法判断是否有Attribute //if (type.GetCustomAttributes(typeof (Attribute), false).Length == 0) //{ // continue; //} this.types.Add(type); } 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.Load(); }
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); IAwakeSystem objectSystem = obj as IAwakeSystem; if (objectSystem != null) { this.awakeEvents.Add(objectSystem.Type(), objectSystem); } IUpdateSystem updateSystem = obj as IUpdateSystem; if (updateSystem != null) { this.updateEvents.Add(updateSystem.Type(), updateSystem); } ILateUpdateSystem lateUpdateSystem = obj as ILateUpdateSystem; if (lateUpdateSystem != null) { this.lateUpdateEvents.Add(lateUpdateSystem.Type(), lateUpdateSystem); } IStartSystem startSystem = obj as IStartSystem; if (startSystem != null) { this.startEvents.Add(startSystem.Type(), startSystem); } IDestroySystem destroySystem = obj as IDestroySystem; if (destroySystem != null) { this.desdroyEvents.Add(destroySystem.Type(), destroySystem); } ILoadSystem loadSystem = obj as ILoadSystem; if (loadSystem != null) { this.loadEvents.Add(loadSystem.Type(), loadSystem); } } 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.types.Clear(); foreach (Assembly value in this.assemblies.Values) { foreach (Type type in value.GetTypes()) { object[] objects = type.GetCustomAttributes(typeof(BaseAttribute), false); if (objects.Length == 0) { continue; } BaseAttribute baseAttribute = (BaseAttribute)objects[0]; this.types.Add(baseAttribute.AttributeType, type); } } this.awakeSystems.Clear(); this.lateUpdateSystems.Clear(); this.fixUpdateSystems.Clear(); this.updateSystems.Clear(); this.startSystems.Clear(); this.loadSystems.Clear(); this.changeSystems.Clear(); this.frameSystems.Clear(); foreach (Type type in types[typeof(ObjectSystemAttribute)]) { 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); } IFrameUpdateSystem frameSystem = obj as IFrameUpdateSystem; if (frameSystem != null) { this.frameSystems.Add(frameSystem.Type(), frameSystem); } ILateUpdateSystem lateUpdateSystem = obj as ILateUpdateSystem; if (lateUpdateSystem != null) { this.lateUpdateSystems.Add(lateUpdateSystem.Type(), lateUpdateSystem); } IFixUpdateSystem fixUpdateSystem = obj as IFixUpdateSystem; if (fixUpdateSystem != null) { this.fixUpdateSystems.Add(fixUpdateSystem.Type(), fixUpdateSystem); } 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[typeof(ObjectSystemAttribute)]) { 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(); }