- Home /
Custom editor not editing?
Hi all,
I've been trying to get a script of mine to only display some variables in the inspector if an enum is at a particular value. I see I have to use a Custom Editor to do this. I've been fiddling with one for a while now, but it doesn't seem to work at all - I don't think it's registering what script it's supposed to be editing?
Here's the PanelCustomInspector.js in the Editor folder:
@CustomEditor(PanelController)
var types : panelTypes;
var directions : pathDirections;
class PanelCustomInspector extends Editor
{
function OnInspectorGUI()
{
EditorGUILayout.LabelField("This is" , "a test.");
target.panelType = EditorGUILayout.EnumPopup(types);
var workaround : panelTypes = target.panelType; //[necessary][1]
if(workaround == panelTypes.Path)
{
target.pathDirection = EditorGUILayout.EnumPopup(directions);
}
}
}
And here's the PanelController.js in a different folder:
var panelType = panelTypes.Buildable;
var pathDirection = pathDirections.Right;
function OnDrawGizmos()
{
//Draw a particular gizmo, depending on what direction the path is
}
The editor just shows the panelType and pathDirection variables of the PanelController.js script and the test label doesn't show up. Any help would be appreciated!
[1]: http://answers.unity3d.com/questions/25453/comparing-enum-from-a-class-in-an-editor-script-do.html
Answer by Waz · Jun 22, 2011 at 05:40 AM
Move the variables "types" and "directions" to Inside the class.
A JS files with anything but a single class declaration is magically wrapped into a class named by the file, so your code would be a class nested inside a class of the same name, or something weird like that.
Though I don't understand what on earth it was about, it worked, so I'm happy, thanks! Only thing is, the variables won't edit. Probably something silly I've done in the coding. Can't for the life of me see what though