/// <summary> /// Queue an event. /// </summary> /// <param name="target">The target to queue an event with.</param> /// <param name="ev">The event to queue.</param> /// <typeparam name="T_Event">The event type.</typeparam> public void QueueEvent <T_Event>(EventTarget target, T_Event ev) where T_Event : struct { EventHandlerStandard <T_Event> system = GetSystem <T_Event>(); system.QueueEvent(target, ev); List <IEventSystem> list = GetJobSystemsForEvent <T_Event>(); int count = list.Count; for (int i = 0; i < count; i++) { IJobEventSystem <T_Event> typedSystem = (IJobEventSystem <T_Event>)list[i]; typedSystem.QueueEvent(target, ev); } }
private EventHandlerStandard <T_Event> GetSystem <T_Event>() where T_Event : struct { Type evType = typeof(T_Event); if (evType == _cachedSystemEventType) { return((EventHandlerStandard <T_Event>)_cacheSystem); } IEventSystem system; if (!_systemsCache.TryGetValue(evType, out system)) { system = new EventHandlerStandard <T_Event>(); _systems.Add(system); _systemsCache[evType] = system; } _cachedSystemEventType = evType; _cacheSystem = system; return((EventHandlerStandard <T_Event>)system); }
/// <summary> /// Unsubscribe a listener from an event. /// </summary> /// <param name="target">The target to unsubscribe from.</param> /// <param name="eventCallback">The event callback</param> /// <typeparam name="T_Event">The event</typeparam> public void Unsubscribe <T_Event>(EventTarget target, Action <T_Event> eventCallback) where T_Event : struct { EventHandlerStandard <T_Event> system = GetSystem <T_Event>(); system.Unsubscribe(target, eventCallback); }