Hello everyone
I have a question about displaying a List or an Array
After creating a List, I can add, remove or assign List items.
The problem starts when I create the Custom Editor. I cannot assign a value to the list.
MonoBehaviour: RootTest.cs
using System.Collections.Generic;
using UnityEngine;
public class RootTest : MonoBehaviour
{
[SerializeField] private List<GameObject> card = new List<GameObject>();
}
… and Editor: RootTestEditor.cs
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(RootTest))]
public class RootTestEditor : Editor
{
private RootTest myTarget;
private SerializedObject soTarget;
private SerializedProperty card;
public override void OnInspectorGUI()
{
myTarget = (RootTest)target;
soTarget = new SerializedObject(target);
card = soTarget.FindProperty("card");
soTarget.Update();
ExecuteMenu();
soTarget.ApplyModifiedProperties();
}
private void ExecuteMenu()
{
EditorGUILayout.PropertyField(card, new GUIContent("Card"));
}
}
I understand the problem is the Editor file which
does not refresh the values. And the new item cannot be assigned.
Does anyone know how to do it ?