CherepeninDYu CherepeninDYu - 1 year ago 198
C# Question

Show members of a class in Unity3D inspector

I need to edit this structure in object inspector just like on screenshot:


I have a script attached to my main object. it has a member named TestData which itself has two other members I and F.

How can I enable the Unity Inspector to edit TestData by its members (I, F) instead of the reference to TestData, When I click my main object?

Answer Source

Create a script in Unity and attach it to a GameObject. The script must be derived from MonoBehaviour

You can add public variables to the script and see them in the inspector.


public Vector3 StartPoint;

You can add [System.Serializable] to the class:

public class TestData
     public int I;
     public int F;

Or if you want the inspector to show something other than the default editor panel you can define a CustomPropertyDrawer for your type.

public class MyScriptDrawer : PropertyDrawer
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)

        EditorGUI.BeginProperty(position, label, property);
        EditorGUI.LabelField(new Rect(x, y, w, h), "title");
        EditorGUI.PropertyField(rect, I, GUIContent.none);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download