- Home /
Custom Display for system.object Editor
I have a data type called Action
in my game, which has three attributes:
public class Action
{
public string methodName = "";
public object parameter = null;
public int frame;
}
I want to be able to edit the values of these from the inspector to help speed up my development process. I can freely edit methodName
and frame
. However, because the parameter
field is an object, it can't be displayed in the inspector. All I would like the inspector to do for Action
is to go down a list of types ( int
, string
, another Action
, etc.) and display it based on if it matches anything, otherwise, not display at all. (If it's an int
, use Unity's default behavior for drawing an int
.)
I've done some digging around and things like CustomEditor and PropertyDrawer look promising, but I haven't been able to get anything figured out yet. Has anyone been able to work through this? Thanks in advance.
Answer by Paolofix21 · Mar 10 at 11:06 PM
What you need is the System Serializable attribute on your class.
[System.Serializable]
public class Action {...}
This will be used by Unity to know that your class needs to be saved and loaded, and therefore it will draw it in any inspector if it is public or marked as a SerializedField.
,