IconDrawer.cs 809 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using UnityEngine;
  3. using UnityEditor;
  4. namespace HQFPSWeapons
  5. {
  6. [CustomPropertyDrawer(typeof(Icon))]
  7. public class IconDrawer : PropertyDrawer
  8. {
  9. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  10. {
  11. position = EditorGUI.IndentedRect(position);
  12. var attr = attribute as Icon;
  13. position.height = EditorGUIUtility.singleLineHeight;
  14. GUI.Label(position, label);
  15. position.xMin += EditorGUIUtility.labelWidth;
  16. position.height = attr.Size;
  17. position.width = attr.Size;
  18. property.objectReferenceValue = EditorGUI.ObjectField(position, property.objectReferenceValue, typeof(Sprite), false);
  19. }
  20. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  21. {
  22. return (attribute as Icon).Size;
  23. }
  24. }
  25. }