I’m trying to create a custom inspector but I when try to display a Serializable class it doesn’t show up.
It does show the serializable class name as a label with the small foldable arrow next to it but when I try to unfold it, its empty.
At this point I am only trying to replicate the behaviour of the Unity editor, nothing fancy yet.
What do I do wrong? How do I get the current behaviour of the editor with serializable classes?
The MonoBehaviour for which I am building a custom inspector
public class SomeComponent : MonoBehaviour
{
public ChangeColor SomeColor;
public ChangeScore SomeScore;
}
The serializable classes
[System.Serializable]
public class ChangeColor
{
public Material Mat;
public Color To;
}
[System.Serializable]
public class ChangeScore
{
public int Points;
public Transform Position;
}
The custom inspector
[CustomEditor(typeof(SomeComponent))]
public class SomeComponentEditor : Editor
{
private SerializedObject m_object;
public void OnEnable()
{
m_object = new SerializedObject(target);
}
public override void OnInspectorGUI()
{
m_object.Update();
GUILayout.Label("Some label", EditorStyles.boldLabel);
var prop = m_object.FindProperty("SomeColor");
EditorGUILayout.PropertyField(prop);
prop = m_object.FindProperty("SomeScore");
EditorGUILayout.PropertyField(prop);
m_object.ApplyModifiedProperties();
}
}