- Home /
How can I display another enum?
Hey guys, i'm learning about Custom Editor and I need some help. Im trying to display another enum depending the option of the first enum. The code below "works", the second enum appears in the inspector but I can not change him.
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(RoomFeatures)), CanEditMultipleObjects]
public class PropertyHolderEditor : Editor {
public SerializedProperty
roomType_Prop,
corridorType_Prop,
roomExit_Prop,
entrance_Prop,
exit_Prop;
void OnEnable () {
// Setup the SerializedProperties
roomType_Prop = serializedObject.FindProperty ("roomType");
corridorType_Prop = serializedObject.FindProperty ("corridorType");
roomExit_Prop = serializedObject.FindProperty ("roomExit");
entrance_Prop = serializedObject.FindProperty ("entrance");
exit_Prop = serializedObject.FindProperty ("exit");
}
public override void OnInspectorGUI() {
serializedObject.Update ();
EditorGUILayout.PropertyField(roomType_Prop);
RoomFeatures.RoomType rt = (RoomFeatures.RoomType)roomType_Prop.enumValueIndex;
RoomFeatures.CorridorType ct = (RoomFeatures.CorridorType)corridorType_Prop.enumValueIndex;
switch( rt ) {
case RoomFeatures.RoomType.Corridor:
ct = (RoomFeatures.CorridorType)EditorGUILayout.EnumPopup ("Corridor Type:", ct);
break;
case RoomFeatures.RoomType.Room:
EditorGUILayout.PropertyField( roomExit_Prop, new GUIContent("Exit") );
break;
}
serializedObject.ApplyModifiedProperties ();
}
}
And this is the RoomFeatures script:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class RoomFeatures : MonoBehaviour
{
public enum RoomType {Corridor, Room, BossRoom};
public RoomType roomType;
public enum CorridorType {Small, Long, VeryLong}
public CorridorType corridorType;
public bool roomExit = false;
[System.Serializable]
public class entrance
{
public enum Vertical {Left, Middle, Right};
public enum Horizontal {Top, Center, Bot};
}
[System.Serializable]
public class exit
{
public enum Vertical {Left, Middle, Right};
public enum Horizontal {Top, Center, Bot};
}
}
Any help will be welcome, sorry if my english is not very good.
Iago C.
Answer by GameVortex · Dec 17, 2014 at 03:09 PM
You need to display the second enum (corridorType_Prop) in the same way you display the first enum (roomType_Prop); with the EditorGUILayout.PropertyField. Right now you are just changing the local variable ct which will fall out of scope after the OnInspectorGUI function.
Your answer
![](https://koobas.hobune.stream/wayback/20220613174226im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Custom PropertyDrawer to support the Flag is not change value. 0 Answers
Custom Editors : EnumFields, Proper Use Of 0 Answers
How to create a new SerializedProperty? 0 Answers
Custom editors, enums and arrays 0 Answers
Custom editor enum resets on play 1 Answer