ReorderableListField.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEditor;
  4. using UnityEditorInternal;
  5. using UnityEngine;
  6. using UnityEngine.UIElements;
  7. namespace Unity.RenderStreaming.Editor
  8. {
  9. // todo(kazuki): workaround.
  10. // ListView.reorderMode is not supported on Unity 2020.3.
  11. internal class ReorderableListField : IMGUIContainer
  12. {
  13. private readonly ReorderableList reorderable;
  14. public ReorderableListField(SerializedProperty property, string label)
  15. {
  16. reorderable = new ReorderableList(property.serializedObject, property)
  17. {
  18. drawElementCallback = (rect, index, isActive, isFocused) => EditorGUI.PropertyField(rect, property.GetArrayElementAtIndex(index)),
  19. drawHeaderCallback = rect => EditorGUI.LabelField(rect, label)
  20. };
  21. onGUIHandler = OnGUIHandler;
  22. }
  23. void OnGUIHandler()
  24. {
  25. reorderable.DoLayoutList();
  26. reorderable.serializedProperty.serializedObject.ApplyModifiedProperties();
  27. }
  28. }
  29. }