Exemplo n.º 1
0
 public void Add(Assembly assembly)
 {
     Type[] types = assembly.GetTypes();
     foreach (Type type in types)
     {
         object[] attrs = type.GetCustomAttributes(typeof(BaseEventAttribute), false);
         foreach (object attr in attrs)
         {
             if (!(attr is BaseEventAttribute))
             {
                 continue;
             }
             BaseEventAttribute Attribute = (BaseEventAttribute)attr;
             if (!Dic.ContainsKey(Attribute.Id))
             {
                 iEventDispatcher BaseEventDispather = Activator.CreateInstance(type) as iEventDispatcher;
                 Game.Instance.EventSystem.AddDispatcher(BaseEventDispather);
                 Dic.Add(Attribute.Id, BaseEventDispather);
                 Log.Debug($"添加了规则类{BaseEventDispather.GetType().ToString()}");
             }
             else
             {
                 Model.Log.Error($"存在Config有相同ID:{Dic[Attribute.Id].GetType().ToString()},{type.Name}");
             }
             //Game.EventSystem.AddDispatcher(Activator.CreateInstance[]);
         }
     }
 }
Exemplo n.º 2
0
 public void RemoveDispatcher(iEventDispatcher dispatcher)
 {
     object[] attrs = dispatcher.GetType().GetCustomAttributes(typeof(EventDispatcherAttribute), false);
     foreach (EventDispatcherAttribute e in attrs)
     {
         foreach (var a in e.ids)
         {
             SortedSet <SortEvent> eventDispatchers;
             dic.TryGetValue(a, out eventDispatchers);
             eventDispatchers.RemoveWhere(x => x.action == dispatcher.Handle);
         }
     }
 }
Exemplo n.º 3
0
 public void AddDispatcher(iEventDispatcher dispatcher)
 {
     object[] attrs = dispatcher.GetType().GetCustomAttributes(typeof(EventDispatcherAttribute), false);
     foreach (EventDispatcherAttribute e in attrs)
     {
         //Model.Log.Debug(e.ToString());
         foreach (var a in e.ids)
         {
             SortedSet <SortEvent> eventDispatchers;
             dic.TryGetValue(a, out eventDispatchers);
             if (eventDispatchers == null)
             {
                 eventDispatchers = new SortedSet <SortEvent>();
                 dic.Add(a, eventDispatchers);
             }
             eventDispatchers.Add(new SortEvent(dispatcher.SortIndex, dispatcher.Handle));
         }
     }
 }