Hi lets first look at what i have :
I have a serializable class that has different type of fields (SerializeField), lets call this InlineValue, then I have another class that is serializable and has a List as public field lets call this one NodeValue.
Now, i will use NodeValue as field in other classes like public NodeValue value;
[Serializable]
public class InlineValue : ICopy<InlineValue>
{
[SerializeField] public string name;
[SerializeField] public bool boolValue;
[SerializeField] public int intValue;
[SerializeField] public float floatValue;
[SerializeField] public string stringValue;
[SerializeField] public Rect rectValue;
[SerializeField] public Vector2 vector2Value;
[SerializeField] public Vector3 vector3Value;
[SerializeField] public Vector4 vector4Value;
[SerializeField] public Quaternion quaternionValue;
[SerializeField] public Color colorValue;
[SerializeField] public AnimationCurve animationCurveValue;
[SerializeField] public DataType dataType;
}
[Serializable]
public class Values
{
public List<InlineValue> Value = new List<InlineValue>();
}
public class Test : MonoBehaviour
{
public Values value = new Values();
}
I would like to draw this list inside the class as a ReorderableList for that test script’s inspector (later on inside another editor window, just using the inspector for faster feedback on when i am tweaking stuff.)
I tried making a custom editor for the Values class, that didn’t show up at all, well, i can understand it because i am adding the test class to game object not the Values class.
so then i tried the property drawer, but i faild because i got tons of errors when i used the property.serializedObject as the first element of the ReorderableList constructor and property as the second param :
[CustomPropertyDrawer(typeof(Values))]
public class PropertyDrawer : UnityEditor.PropertyDrawer
{
private ReorderableList list;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var serializedObject = property.serializedObject;
list = new ReorderableList(serializedObject, property, true, true, true, true);
serializedObject.Update();
list.DoLayoutList();
serializedObject.ApplyModifiedProperties();
}
}
Am i derping here or did i miss something? how to make the list of a class used as a field inside another class use the reorderable editor?
Actually I know what is the mess all about in property drawer take a look at the first error :
Error
Input elements should be an Array SerializedProperty
UnityEngine.Debug:LogError(Object)
UnityEditorInternal.ReorderableList:InitList(SerializedObject, SerializedProperty, IList, Boolean, Boolean, Boolean, Boolean) (at C:/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:259)
UnityEditorInternal.ReorderableList:.ctor(SerializedObject, SerializedProperty, Boolean, Boolean, Boolean, Boolean) (at C:/buildslave/unity/build/Editor/Mono/GUI/ReorderableList.cs:241)
PropertyDrawer:OnGUI(Rect, SerializedProperty, GUIContent) (at Assets/TNP/Common/Editor/PropertyDrawer.cs:15)
UnityEditor.DockArea:OnGUI()
It’s clear as day that the property in the method call for drawer’s OnGUI is not an array and the reorderable list needs obviously, an array or a list.
so how to approach this?
Edit : Now I am really confused, when i say the type of property drawer is Values, or InlineValue (in both cases) , when i look into the available options in intellisense for property inside OnGUI, i see the fields for InlineValue !!! when i say the type of is Value, shouldn’t i see the list instead of a single instance of the base class?