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.