Skip to content

Commit

Permalink
Added traversal of base types for function finding
Browse files Browse the repository at this point in the history
Made the function finding traverse base types for components in addition to the component type. This gives access to stuff like LateUpdate on inherited classes where it previously may not have been shown. If you were missing some functions before when using EEE instead of the Unity event editor, this is probably why.
  • Loading branch information
MerlinVR committed Jun 17, 2019
1 parent 87af47e commit 7f802dd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions EasyEventEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,7 @@ string GetFunctionDisplayName(SerializedProperty objectProperty, SerializedPrope
break;
}
}

//if (componentID > 1)

objectTypeName += string.Format("({0})", componentID);
}
}
Expand Down Expand Up @@ -820,15 +819,25 @@ void FindValidMethods(Object targetObject, PersistentListenerMode listenerMode,
else
argTypes = GetTypeForListenerMode(listenerMode);

MethodInfo[] foundMethods = objectType.GetMethods(BindingFlags.Public | (cachedSettings.showPrivateMembers ? BindingFlags.NonPublic : BindingFlags.Default) | BindingFlags.Instance);
List<MethodInfo> foundMethods = new List<MethodInfo>();

// For some reason BindingFlags.FlattenHierarchy does not seem to work, so we manually traverse the base types instead
while (objectType != null)
{
MethodInfo[] foundMethodsOnType = objectType.GetMethods(BindingFlags.Public | (cachedSettings.showPrivateMembers ? BindingFlags.NonPublic : BindingFlags.Default) | BindingFlags.Instance);

foundMethods.AddRange(foundMethodsOnType);

objectType = objectType.BaseType;
}

foreach (MethodInfo methodInfo in foundMethods)
{
// Sadly we can only use functions with void return type since C# throws an error
if (methodInfo.ReturnType != typeof(void))
continue;

ParameterInfo[] methodParams = methodInfo.GetParameters()/*.Where(method => !method.ParameterType.IsSpecialName).ToArray()*/;
ParameterInfo[] methodParams = methodInfo.GetParameters();
if (methodParams.Length != argTypes.Length)
continue;

Expand Down

0 comments on commit 7f802dd

Please sign in to comment.