StyledPopupLayersDrawer.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Cristian Pop - https://boxophobic.com/
  2. using UnityEngine;
  3. using UnityEditor;
  4. namespace Boxophobic.StyledGUI
  5. {
  6. [CustomPropertyDrawer(typeof(StyledPopupLayers))]
  7. public class StyledPopupLayersAttributeDrawer : PropertyDrawer
  8. {
  9. private int index;
  10. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  11. {
  12. index = property.intValue;
  13. string[] allLayers = new string[32];
  14. for (int i = 0; i < 32; i++)
  15. {
  16. if (LayerMask.LayerToName(i).Length < 1)
  17. {
  18. allLayers[i] = "Missing";
  19. }
  20. else
  21. {
  22. allLayers[i] = LayerMask.LayerToName(i);
  23. }
  24. }
  25. index = EditorGUILayout.Popup(property.displayName, index, allLayers);
  26. property.intValue = index;
  27. }
  28. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  29. {
  30. return -2;
  31. }
  32. }
  33. }