Hi everyone, I’ve found number of posts the threads regarding this subject, and I and I have tried to implement the answers from those posts. But after a full day I’m still at square one and cant get an Enum to work within a custom inspector script.
This is my Enum Class: - It is not fixed within another class so all classes have access to it.
public enum TileTypes {
Normal = 0,
Turn = 1,
Mirror = 2,
Invert = 3,
Switch = 4
};
This is the Object Class I am trying to write an inspector for:
using UnityEngine;
using System.Collections;
public class Tile : MonoBehaviour {
public TileTypes tileType;
}
And this is my custom inspector class:
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(Tile))]
[CanEditMultipleObjects]
public class Tile_Editor : Editor {
public override void OnInspectorGUI ()
{
Tile myScript = (Tile) target;
myScript.tileType= (TileTypes )EditorGUILayout.EnumPopup ("Tile Type", myScript.tileType);
}
That is the closest I have got to getting it working, and it allows me to change the enum value within the inspector. But when I play the game the value reverts back to its default value. I am aware of seized field, But can’t find an example of how to make one for an Enum field “At least not one that works for me”.
This was my attempt at serializing an Enum:
using UnityEngine;
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(Tile))]
[CanEditMultipleObjects]
public class Tile_Editor : Editor {
SerializedProperty typeProp;
private void OnEnable(){
typeProp = serializedObject.FindProperty("tileType");
}
public override void OnInspectorGUI (){
serializedObject.Update ();
typeProp = (TileTypes) EditorGUILayout.EnumPopup(TileTypes);
serializedObject.ApplyModifiedProperties ();
}
}
I really struggle with writing Custom GUI Inspectors, but if I could just get this working it would hugely reduce my development time.
Thank guys.