Custom Inspector : Select a script

Hi, iā€™m trying to write a custom inspector that has an option for the user to select a class or class/method combination.

For example I have a default jump method but the user may already have their own class with a jump method that has been customized to how their game will work. How do i provide a selector for them to choose their component that has the jump method on it? If you can give me a way to select the actual jump method too that would be amazing :smiley:

I appreciate they will need to have their script as a component on the object in question and i could just get the user to type the name of the script but that is prone to user error and it would be nice to be able to do this drag and drop or via the selector window.



Well to get an object picker for a class file all you would need is this.

customObject.customProperty = (MonoBehaviour)EditorGUILayout.ObjectField(customObject.customProperty, typeof(MonoBehaviour), false);

This will let them universally pick a mono script, or if you have a specific class name for it, then you can use that classes name instead of MonoBehaviour.

An example would be to make them have a Jump class and a standard Jump method in their class so that your script can just call out to it, regardless of it being different from another jump class.

1 Like