- Home /
Enum Dropdown in JS Using Custom Editor?
I've been practicing with the Unity Custom Editor and using both C# and JS. I'm doing a simple editor script that uses an enum to have a dropdown menu to change the value of an int. I got it to work in C# but not JS. Is there something I'm doing wrong? Here's what I have, any help would be appreciated.
In JS:
I get 3 of these errors:
';' expected. Insert a semicolon at the end
class EditorTest extends Editor {
enum ValueDropDown {Value1 = 1, Value2 = 2, Value3 = 3, Value4 = 4};
var ValueDropDown : editorChangeValue = ValueDropDown.Value1;
function OnInspectorGUI () {
editorChangeValue = (ValueDropDown)target.valueToChange;
editorChangeValue = (ValueDropDown)EditorGUILayout.EnumPopup("Change Value:", editorChangeValue);
target.valueToChange = (int)editorChangeValue;
}
}
Answer by BHS · May 11, 2013 at 10:27 PM
I ended up figuring it out.
The syntax is different than C# so I tried a few things and got it working great. I searched for about a day straight looking for a solution but found none. So if you're like me looking for an answer, here it is. I hope it helps whoever is looking for the same thing.
In JS, this allows you to edit an int from another script using a fancy enum pulldown menu in the Inspector using the Custom Editor in Unity.
class EditorTest extends Editor {
enum ValueDropDown {Value1 = 1, Value2 = 2, Value3 = 3, Value4 = 4};
var ValueDropDownEditor = ValueDropDown.Value1;
function OnInspectorGUI () {
ValueDropDownEditor = target.valueToChange;
ValueDropDownEditor = EditorGUILayout.EnumPopup("Change Number:", ValueDropDownEditor);
target.valueToChange = ValueDropDownEditor;
}
}
Answer by trs9556 · May 11, 2013 at 06:51 PM
take away the ; on
enum StartTimeDropDown {Value1 = 1, Value2 = 2, Value3 = 3, Value4 = 4};
So it should be:
enum StartTimeDropDown {Value1 = 1, Value2 = 2, Value3 = 3, Value4 = 4}
See what errors that might leave.
Thanks, I did, but I'm getting the same error on the last 3 lines.
editorChangeValue = (ValueDropDown)target.valueToChange;
editorChangeValue = (ValueDropDown)EditorGUILayout.EnumPopup("Change Value:", editorChangeValue);
target.valueToChange = (int)editorChangeValue;
Your answer
Follow this Question
Related Questions
Empty space at the top of a custom property drawer layout? 2 Answers
Custom inspector for AnimatorStateTransition 0 Answers
Custom Editor for Monobehavior with custom property not retaining Gameobject references 0 Answers
Custom Inspector: Using SeralizedProperty changes the prefab values! 0 Answers
Custom editor not editing? 1 Answer