RouteDrawer.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Routes;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. // ReSharper disable once CheckNamespace
  6. public static class RouteDrawer
  7. {
  8. private static bool showListContent = true;
  9. public static void PropertyField(SerializedProperty route)
  10. {
  11. Debug.Log("route = "+route);
  12. ListField(route.FindPropertyRelative("items"));
  13. }
  14. private static void ListField(SerializedProperty list)
  15. {
  16. //EditorGUILayout.BeginHorizontal();
  17. showListContent = EditorGUILayout.Foldout(showListContent, $"{list.displayName} (Length = {0/*list.arraySize*/})");
  18. EditorGUILayout.EndHorizontal();
  19. //EditorGUILayout.PropertyField(list.displayName);
  20. if (showListContent) {
  21. EditorGUI.indentLevel += 1;
  22. for (var i = 0; i < list.arraySize; i++) {
  23. EditorGUILayout.BeginHorizontal();
  24. EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i));
  25. if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.Width(32)))
  26. {
  27. list.DeleteArrayElementAtIndex(i);
  28. }
  29. EditorGUILayout.EndHorizontal();
  30. }
  31. EditorGUI.indentLevel -= 1;
  32. }
  33. //EditorGUILayout.EndHorizontal();
  34. //EditorGUILayout.EndFoldoutHeaderGroup();
  35. /*if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(128)))
  36. {
  37. list.InsertArrayElementAtIndex(0);
  38. }*/
  39. }
  40. }