public virtual void OnEnable() { MethodInfo[] methods = GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); foreach (MethodInfo m in methods) { System.Attribute[] attributes = (System.Attribute[])m.GetCustomAttributes(true); foreach (System.Attribute attribute in attributes) { if (attribute is OnEvent) { OnEvent onEventMethod = (OnEvent)attribute; if (m.GetParameters().Length == 2) { PMEvent del = (PMEvent)Delegate.CreateDelegate(typeof(PMEvent), this, m); events.Add(new PairEventString(onEventMethod.Name, del)); } else { PMEventLite del = (PMEventLite)Delegate.CreateDelegate(typeof(PMEventLite), this, m); eventsLite.Add(new PairEventLiteString(onEventMethod.Name, del)); } } } } RegisterAll(); }
public void Unregister(string id, PMEventLite eventMethod) { if (id != "") { eventsLite [id] -= eventMethod; } else { allEventsLite -= eventMethod; } }
public void Initialize() { StateController.AddPieka(this); System.Attribute[] att = (System.Attribute[])GetType().GetCustomAttributes(true); foreach (System.Attribute attribute in att) { if (attribute is AllowedState) { AllowedState allowedState = (AllowedState)attribute; isInActiveState = false; allowedStates.Add(allowedState.Name); } } MethodInfo[] methods = GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); foreach (MethodInfo m in methods) { System.Attribute[] attributes = (System.Attribute[])m.GetCustomAttributes(true); foreach (System.Attribute attribute in attributes) { if (attribute is OnEvent) { OnEvent onEventMethod = (OnEvent)attribute; if (m.GetParameters().Length == 2) { PMEvent del = (PMEvent)Delegate.CreateDelegate(typeof(PMEvent), this, m); events.Add(new PairEventString(onEventMethod.Name, del)); } else { PMEventLite del = (PMEventLite)Delegate.CreateDelegate(typeof(PMEventLite), this, m); eventsLite.Add(new PairEventLiteString(onEventMethod.Name, del)); } // SEventSystem.Register ( onEventMethod.Name, (PMEvent)PMEvent.CreateDelegate( typeof(PMEvent), m ) ); } } } RegisterAll(); OnStateChange(StateController.GetActiveState()); }
public void Register(string id, PMEventLite eventMethod) { if (id != "") { if (!eventsLite.ContainsKey(id)) { eventsLite [id] = eventMethod; } else { eventsLite [id] += eventMethod; } } else { allEventsLite += eventMethod; } }
public static void Unregister(string id, PMEventLite eventMethod) { eventSystem.Unregister(id, eventMethod); }
public PairEventLiteString(string name, PMEventLite @event) { this.Name = name; this.Event = @event; }