Custom inspector Question

hey

I need to make a custom inspector for a script that uses a enum list variable. This simple example shows want I want to be done:

//PlayerNames.js

enum List {Name1, Name2, Name3}

var name : List;

public var name1 : String = "Bob";
public var name2 : String = "Sam";
public var name3 : String = "Tim";

I want to make a custom inspector script for this java script that when Name1 is select on the list variable it only shows the name 1 variable “Bob” in the inspector (hides the other variables). When Name2 is select it shows “Sam” etc…

I can’t seem to find out how to do this. I think there is a lack of tutorials and information on custom inspectors/editors. If someone could take the time to tell me how to do this it would be greatly appreciated as I know this may not be a simple task.

I’ve worked out now to do it now. This is the normal script:

//PlayerNames.js

enum List {name1, name2, name3}

var names : List;

public var person1 : String = "Bob";
public var person2 : String = "Sam";
public var person3 : String = "Tim";

And this is the editor script placed in a folder named “Editor”:

//PlayerNamesEditor.js

@CustomEditor (PlayerNames)
class PlayerNamesEditor extends Editor {

    function OnInspectorGUI () {

	target.names =  EditorGUILayout.EnumPopup("Names of people:", target.names);
	
	if (target.names == 0)
		target.person1 = EditorGUILayout.TextField("You chose: ", target.person1);
	if (target.names == 1)
		target.person2 = EditorGUILayout.TextField("You chose: ", target.person2);
	if (target.names == 2)
		target.person3 = EditorGUILayout.TextField("You chose: ", target.person3);
    }
}

You don’t show or hide properties in inspector. They will be visible or hidden according to the class visibility (all public variables will appear, and all private variables won’t).

If you want to make your own inspector, you need to tell Editor which fields you want to show (and which values they will have). Having fields doesn’t necessarily means having a correspondent property. Take the manual example:

@CustomEditor (LookAtPoint)
class LookAtPointEditor extends Editor {
    function OnInspectorGUI () {
        target.lookAtPoint = EditorGUILayout.Vector3Field ("Look At Point", target.lookAtPoint);
        if (GUI.changed)
            EditorUtility.SetDirty (target);
    }
}

The “Look At Point” field could have any value other than the selected GameObject facing direction. This thing just makes properties values easier to handle.

Just an additional note: you will need another class to handle custom inspector (custom inspector class derives from “Editor” class).