I’m started to work with custom editors for a class called StoryEvent. each StoryEvent needs to have a Category. As the Editor intro ( Unite 2011 - Intro to Editor Scripting - YouTube) advised, I use SerializedObject. However, the script doesn’t work. I know have a custom editor with only a category field. but when I drag my category it will not be added. what do I do wrong?
using UnityEditor;
using System.Collections;
[CustomEditor(typeof(StoryEvent))]
public class StoryEventEditor : Editor
{
private SerializedObject _object;
private SerializedProperty _category;
void OnEnable ()
{
_object = new SerializedObject (target);
_category = _object.FindProperty ("category");
}
// Update is called once per frame
public override void OnInspectorGUI ()
{
_object.Update ();
Category c = (Category)_category.objectReferenceValue;
EditorGUILayout.ObjectField ("Category", c, typeof(Category), false);
if (GUI.changed) {
_category.objectReferenceValue = c;
}
//EditorUtility.SetDirty (_object);
_object.ApplyModifiedProperties ();
}
}