- Home /
Custom Editors : EnumFields, Proper Use Of
Hi all, I've been experimenting with Custom Editors, and no matter how much work I put into making this script, I always get some crazy nullreference exception. :/
My question is: How can I implement an editor that shows/hides inspector variables based on the value selected from the enum box?
Here is some code I've been working on...
[CustomEditor(typeof(ContentWindow))]
public class ContentWindowEditor : Editor
{
public ContentWindow CW;
void Awake()
{
CW = (ContentWindow)target;
}
public override void OnInspectorGUI()
{
serializedObject.Update();
CW.WT = (ContentWindow.WindowType)EditorGUILayout.EnumMaskField("Window Type", CW.WT);
serializedObject.ApplyModifiedProperties();
}
}
Here's the Enum
public WindowType WT;
public enum WindowType
{
ImageWindow = 0,
TextWindow = 1,
MiscWindow = 2
}
This Editor script is supposed to show/hide selected Inspector elements depending on what is selected from the Enum. This is passed through a switch/case and then the relevent elements are drawn. Instead I get a NullReferenceException when loading the script or navigating to it's Inspector.
As Always, I appreciate all the help you have.
--CausticLasagne.
Your answer
Follow this Question
Related Questions
How to create a new SerializedProperty? 0 Answers
drawdefaultinspector except of one variable?? 2 Answers
Question About EditorGUILayout.BeginFadeGroup 1 Answer
How to create enum out of array of string? 2 Answers
What is the efficient way of showing variables depend on enum in custom inspector? 2 Answers