Ejemplo n.º 1
0
        public static void LoadEvent(List <Type> types)
        {
            allEvents.Clear();
            foreach (Type type in types)
            {
                object[] attrs = type.GetCustomAttributes(typeof(AnnotationEventAttribute), false);

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

                object obj = Activator.CreateInstance(type);

                Log.Info("HotfixEvent type" + type.FullName);

                IEventMethod iEvent = Activator.CreateInstance(type) as IEventMethod;
                if (iEvent == null)
                {
                    throw new Exception($"type not is AEvent: {iEvent.GetType().Name}");
                }

                RegisterEvent(iEvent.GetEventType(), iEvent);

                // hotfix的事件也要注册到mono层,hotfix可以订阅mono层的事件
                Action <List <object> > action = list => { Handle(iEvent, list); };

                if (EventComponent.This != null)
                {
                    Log.Info(iEvent.GetEventType());

                    EventComponent.This.RegisterEvent(iEvent.GetEventType(), new EventProxy(action));
                }
            }
        }
Ejemplo n.º 2
0
 public void RegisterEvent(int eventType, IEventMethod obj)
 {
     if (!allEvents.ContainsKey(eventType))
     {
         allEvents.Add(eventType, new List <object>());
     }
     allEvents[eventType].Add(obj);
 }
Ejemplo n.º 3
0
        public static void UploadEvent(HashSet <Type> types)
        {
            allEvents.Clear();
            foreach (Type type in types)
            {
                //Log.Info("RunEvent type" + type.FullName);

                IEventMethod iEvent = Activator.CreateInstance(type) as IEventMethod;
                if (iEvent == null)
                {
                    throw new Exception($"type not is AEvent: {iEvent.GetType().Name}");
                }

                RegisterEvent(iEvent.GetEventType(), iEvent);
            }
        }
Ejemplo n.º 4
0
        public static void Handle(IEventMethod iEvent, List <object> param)
        {
            switch (param.Count)
            {
            case 0:
                iEvent.Handle();
                break;

            case 1:
                iEvent.Handle(param[0]);
                break;

            case 2:
                iEvent.Handle(param[0], param[1]);
                break;

            case 3:
                iEvent.Handle(param[0], param[1], param[2]);
                break;
            }
        }