Is there a way to get all of the custom public Methods (functions), that are in a certain MonoScript? (NOT MonoBehaviour)
Lets say i have a EditorWindow and a field, where i can assign certain MonoScript…So i want to get a list of, only the Public Methods, that i have declared, not all possible methods…
Then you’re looking for GetClass() not GetType(), MonoScripts are just representations of the script assets not the actual classes. Change that and it should give you the public methods.
I’m not sure why can’t you achieve what you want with just the type.GetMethods(flags) function, where flags = public | instance | declared only. That should give you the methods you need, if you want to get methods up the hierarchy, take out the declared only flag. Keep in mind public alone won’t work, you need ‘instance’ flag along with it. If you want to get very specific methods, you could just annotate those methods with an attribute you create, and then go type.GetMethods(flags).Where(m => m.IsDefined(typeof(MyAttribute)).ToArray();
If you want to invoke a method on an instance created from CreateInstance, you need to get a MethodInfo reference and then use your object on its Invoke function. i.e.