Open perrauo opened 1 year ago
I know this is stale, but there are 2 built-in ways to make this work with serializable classes (and structs) without creating a custom property drawer. This package also works with arrays and lists without doing anything
MyComponent.cs
using UnityEngine;
using MarkupAttributes;
using System.Collections.Generic;
public class MyComponent : MonoBehaviour
{
[Box("Group")]
public MyClass1 _myClass1;
[MarkedUpField(indentChildren:false, showControl: false)]
public MyClass2 _myClass2;
public float[] _myArr;
public List<float> _myList = new List<float>();
}
[MarkedUpType(indentChildren: false, showControl: false)]
[System.Serializable]
public class MyClass1
{
public float _myFloat1 = 1f;
}
[System.Serializable]
public class MyClass2
{
public float _myFloat2 = 1f;
}
MyEditor.cs
using UnityEditor;
using MarkupAttributes.Editor;
[CustomEditor(typeof(MyComponent))]
public class MyEditor : MarkedUpEditor
{
}
This gives the following result
You can also modify the way serializable types are shown in the inspector using the attribute parameters (both of them default to true
)
Hope this answers your question
Unity Editors do not work with Serializable class. I assume we would need a PropertyDrawer. Also a custom base class of some kind in order to make it work with arrays.