GlobalPropSettingsDrawer.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using DunGen.Graph;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace DunGen.Editor.Drawers
  5. {
  6. [CustomPropertyDrawer(typeof(DungeonFlow.GlobalPropSettings))]
  7. sealed class GlobalPropSettingsDrawer : PropertyDrawer
  8. {
  9. private const float Margin = 5f;
  10. private const float PaddingBetweenElements = 2f;
  11. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  12. {
  13. var idProperty = property.FindPropertyRelative("ID");
  14. var countProperty = property.FindPropertyRelative("Count");
  15. return EditorGUI.GetPropertyHeight(idProperty) +
  16. EditorGUI.GetPropertyHeight(countProperty) +
  17. EditorGUIUtility.standardVerticalSpacing * 2 +
  18. Margin * 2 +
  19. PaddingBetweenElements;
  20. }
  21. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  22. {
  23. position.height = GetPropertyHeight(property, label);
  24. var idProperty = property.FindPropertyRelative("ID");
  25. var countProperty = property.FindPropertyRelative("Count");
  26. EditorGUI.BeginProperty(position, label, property);
  27. position.position += new Vector2(0, Margin);
  28. position.height -= Margin * 2;
  29. var idPosition = position;
  30. idPosition.height = EditorGUI.GetPropertyHeight(idProperty) + EditorGUIUtility.standardVerticalSpacing;
  31. var countPosition = position;
  32. countPosition.height = EditorGUI.GetPropertyHeight(countProperty) + EditorGUIUtility.standardVerticalSpacing;
  33. countPosition.position += new Vector2(0f, idPosition.height + PaddingBetweenElements);
  34. EditorGUI.PropertyField(idPosition, idProperty);
  35. EditorGUI.PropertyField(countPosition, countProperty);
  36. EditorGUI.EndProperty();
  37. }
  38. }
  39. }