Team Size - Solo
〰️
Engine - Unity
〰️
Developement Time - 9 Weeks
〰️
Team Size - Solo 〰️ Engine - Unity 〰️ Developement Time - 9 Weeks 〰️
Method Invoker
The idea behind the method invoker is for the developer to easily test a function by simply pressing a button to call it. I aimed to achieve this using C# reflection.
When the Unity editor renders the custom inspector, it invokes OnInspectorGUI of the ComponentFilter class.
Inside OnInspectorGUI, the "Method Invoker" section is rendered. When the user selects a target component, OnValidate is called.
In OnValidate, an instance of InvokerService is created with the selected component, and all methods are retrieved using reflection.
The DisplayMethods method then renders a foldout for each method, displaying the method name and its parameters.
When the user clicks the "Invoke" button, the corresponding method of InvokerService is called, which, in turn, uses reflection to invoke the selected method on the target component with the specified parameters.
GetMethods Method:
Takes an array of
Typeparameters.Uses reflection to get methods of the target component.
Filters methods based on parameter types using
IStructuralEquatable.Returns an array of
MethodInfoobjects.
Invoke Method:
Takes a method name and an array of parameters.
Uses reflection to get the target method from the component type.
Invokes the method on the target component with the provided parameters.
Returns the result of the method invocation.
MethodHasParameters Method:
Checks if a given
MethodInfoobject has parameters.
GetUnderlyingParameterTypes Method:
Takes a
MethodInfoobject.Uses reflection to get the parameter types of the method.
Returns an enumerable collection of parameter types.