private void ExecuteEvent <T>(EventFunction <T> func, object arg, bool includeDisabled = false) where T : IControllerEventHandler { for (int i = 0; i < this.m_ControllerEvents.Length; i++) { IControllerEventHandler handler = this.m_ControllerEvents[i]; if (ShouldSendEvent <T>(handler, includeDisabled)) { func.Invoke((T)handler, arg); } } }
//Check if we should execute the event on that handler protected bool ShouldSendEvent <T>(IControllerEventHandler handler, bool includeDisabled) { var valid = handler is T; if (!valid) { return(false); } var behaviour = handler as Behaviour; if (behaviour != null && !includeDisabled) { return(behaviour.isActiveAndEnabled); } return(true); }