StyledPopupArrayDrawer.cs 1016 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. namespace Boxophobic.StyledGUI
  5. {
  6. [CustomPropertyDrawer(typeof(StyledPopupArray))]
  7. public class StyledPopupArrayAttributeDrawer : PropertyDrawer
  8. {
  9. StyledPopupArray a;
  10. private int index = 0;
  11. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  12. {
  13. a = (StyledPopupArray)attribute;
  14. var arrProp = property.serializedObject.FindProperty(a.array);
  15. var arr = new string[arrProp.arraySize];
  16. for (int i = 0; i < arrProp.arraySize; i++)
  17. {
  18. arr[i] = arrProp.GetArrayElementAtIndex(i).stringValue;
  19. }
  20. index = EditorGUILayout.Popup(property.displayName, index, arr);
  21. property.intValue = index;
  22. }
  23. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  24. {
  25. return -2;
  26. }
  27. }
  28. }