EnumProperyDrawer.cs 996 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace UnityEditor.Recorder
  5. {
  6. abstract class EnumProperyDrawer<T> : PropertyDrawer
  7. {
  8. GUIContent[] m_DisplayNames;
  9. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  10. {
  11. if (m_DisplayNames == null)
  12. {
  13. var displayNames = new List<GUIContent>();
  14. foreach (T frameRate in Enum.GetValues(typeof(T)))
  15. {
  16. displayNames.Add(new GUIContent(ToLabel(frameRate)));
  17. }
  18. m_DisplayNames = displayNames.ToArray();
  19. }
  20. EditorGUI.BeginProperty(position, label, property);
  21. property.intValue = EditorGUI.Popup(position, label, property.intValue, m_DisplayNames);
  22. EditorGUI.EndProperty();
  23. }
  24. protected abstract string ToLabel(T value);
  25. }
  26. }