- Home /
layout serializable objects in unity
I want to have my ModifierInfo object to show up in the inspector like a Vector3 object.
So if I have field:
[SerializeField]
private Vector3 vector;
it show up as
vector X [Textfield] Y [Textfield] Z [Textfield]
But if I do the same with my ModifierInfo:
[System.Serializable]
public class ModifierInfo {
[SerializeField]
public float percentOnBase;
[SerializeField]
public float onStack;
[SerializeField]
public float percentOnStack;
}
Shows up as:
▼ modifierInfo
Percent On Base [Textfield]
On Stack [Textfield]
Percent On Stack [Textfield]
Is it possible to change the way my object is shown in unity?
I would like to be able to use it with a list
Answer by MacDx · Oct 18, 2017 at 03:27 PM
Is it possible to change the way my object is shown in unity?
Yes it is possible. What you need is called a custom PropertyDrawer. Which is a class that you can derive from and that unity uses to draw any custom serializable class you want, (not for monobehaviours tho, for those you use a custom Editor instead since that redraws all of the properties in the script). When you've done it, Unity will draw your custom class the same way in every script.
Here are some links that will tell you exactly how to do it:
https://docs.unity3d.com/ScriptReference/PropertyDrawer.html
https://docs.unity3d.com/Manual/editor-PropertyDrawers.html
https://unity3d.com/learn/tutorials/topics/interface-essentials/property-drawers-custom-inspectors
Your answer
Follow this Question
Related Questions
How to allocate layout region inside the inspector? 1 Answer
Expanding a custom property drawer of a list item forces further items in the list to disappear. 2 Answers
Change editor play/stop button positions for dual monitor layout 0 Answers
Undo.Record: Recording variables within array elements 0 Answers