private void UpdateDelegates() { bool enableByMode = Application.isPlaying || InvokeEventsInEditMode; invocationInfo = GetInvocationInfo(enableByMode, HandlerKey, invocationInfo, IsMethodWithParam); }
/// <summary> /// Given the method key and target, constructs event invocation info which can be used for later invoking /// the method on the target. Also updates the key to reduce the amount of instantiations. /// </summary> /// <param name="isEnabled"></param> /// <param name="methodKey"></param> /// <param name="currentInfo"></param> /// <param name="methodWitharg"></param> /// <returns></returns> private EventInvocationInfo GetInvocationInfo(bool isEnabled, string methodKey, EventInvocationInfo currentInfo, bool methodWitharg) { if (currentInfo != null && currentInfo.Key == methodKey && !(string.IsNullOrEmpty(methodKey) || (methodKey.ToLower() == "none"))) { return(currentInfo); } Behaviour targetBehaviour = null; string methodName = null; GetBehaviourAndMethod(isEnabled, methodKey, ref targetBehaviour, ref methodName); if (targetBehaviour != null) { //get the method info var methodInfo = targetBehaviour .GetType() .GetMethods(BindingFlags.Public | BindingFlags.Instance) .FirstOrDefault(m => m.Name == methodName && m.ReturnType == typeof(void) && m.GetParameters().Length == (methodWitharg ? 1 : 0)); return(new EventInvocationInfo(methodKey, targetBehaviour, methodInfo)); } return(null); }