public void TransmitEvent(object evnt) { int count = _listedDependencies.Count; for (int i = 0; i < count; i++) { _listedDependencies[i].AlreadyNotified = false; } Type eventType = evnt.GetType(); for (int i = 0; i < _listedDependencies.Count; i++) { IDependency dependency = _listedDependencies[i]; if (dependency.IsSingle && ReflectionCache.GetEventHandlersFor(dependency.DependencyType).Length > 0 && !dependency.AlreadyNotified) { object target = dependency.Resolve(this, 0); InjectEventTo(target, eventType, evnt); dependency.AlreadyNotified = true; } } for (int i = 0; i < _commands.Count; i++) { CommandEntry commandEntry = _commands[i]; bool isSuitable = commandEntry.EventType.IsAssignableFrom(eventType); if (isSuitable) { ExecuteCommands(commandEntry.CommandTypes, evnt); } } }
private void OnBlindEventHandler(object evnt) { Type eventType = evnt.GetType(); for (int i = 0; i < _listedDependencies.Count; i++) { object dependency = _listedDependencies[i]; Type dependencyType = dependency.GetType(); BlindEventHandler[] handlers = ReflectionCache.GetEventHandlersFor(dependencyType); foreach (BlindEventHandler handler in handlers) { if (handler.IsSuitableForEvent(eventType)) { handler.Invoke(dependency, evnt); } } } }
private void InjectEventTo(object recipient, Type eventType, object evt) { Type recipientType = recipient.GetType(); IEventHandler[] handlers = ReflectionCache.GetEventHandlersFor(recipientType); for (int i = 0; i < handlers.Length; i++) { IEventHandler handler = handlers[i]; try { if (handler.IsSuitableForEvent(eventType)) { handler.Invoke(recipient, evt); } } catch (Exception e) { UnityEngine.Debug.LogException(e); } } }
public void TransmitEvent(object blindEvent) { Type eventType = blindEvent.GetType(); if (_componentsCache == null) { _componentsCache = gameObject.GetComponents <MonoBehaviour>(); } foreach (MonoBehaviour component in _componentsCache) { if (component == null || this == component) { continue; } if (DetachedFromEvents.Count > 0 && DetachedFromEvents.Contains(component)) { continue; } Type componentType = component.GetType(); IEventHandler[] handlers = ReflectionCache.GetEventHandlersFor(componentType); foreach (IEventHandler handler in handlers) { try { if (handler.IsSuitableForEvent(eventType)) { handler.Invoke(component, blindEvent); } } catch (Exception e) { Debug.LogException(e); } } } }
private void InjectBlindEvent(object blindEvent) { Type eventType = blindEvent.GetType(); MonoBehaviour[] components = gameObject.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour component in components) { if (component == this) { continue; } Type componentType = component.GetType(); BlindEventHandler[] handlers = ReflectionCache.GetEventHandlersFor(componentType); foreach (BlindEventHandler handler in handlers) { if (handler.IsSuitableForEvent(eventType)) { handler.Invoke(component, blindEvent); } } } }