RouteDrawer.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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) //TODO: onDelete
  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. if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.Width(32)))
  19. {
  20. //list.DeleteArrayElementAtIndex(i); TODO: onDelete
  21. }
  22. EditorGUILayout.EndHorizontal();
  23. //EditorGUILayout.PropertyField(list.displayName);
  24. if (showListContent) {
  25. EditorGUI.indentLevel += 1;
  26. for (var i = 0; i < list.arraySize; i++) {
  27. EditorGUILayout.BeginHorizontal();
  28. EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i));
  29. if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.Width(32)))
  30. {
  31. list.DeleteArrayElementAtIndex(i);
  32. }
  33. EditorGUILayout.EndHorizontal();
  34. }
  35. EditorGUI.indentLevel -= 1;
  36. }
  37. //EditorGUILayout.EndHorizontal();
  38. //EditorGUILayout.EndFoldoutHeaderGroup();
  39. /*if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(128)))
  40. {
  41. list.InsertArrayElementAtIndex(0);
  42. }*/
  43. }
  44. }