SelectableLabelAttribute.cs 936 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using UnityEngine;
  2. #if UNITY_EDITOR
  3. using UnityEditor;
  4. #endif
  5. public class SelectableLabelAttribute : PropertyAttribute
  6. {
  7. public string text;
  8. public SelectableLabelAttribute(string text)
  9. {
  10. this.text = text;
  11. }
  12. }
  13. #if UNITY_EDITOR
  14. [CustomPropertyDrawer(typeof(SelectableLabelAttribute))]
  15. public class SelectableLabelDrawer : PropertyDrawer
  16. {
  17. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  18. {
  19. EditorGUI.SelectableLabel(position, selectableLabelAttribute.text);
  20. }
  21. private SelectableLabelAttribute selectableLabelAttribute
  22. {
  23. get
  24. {
  25. return (SelectableLabelAttribute)attribute;
  26. }
  27. }
  28. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  29. {
  30. return selectableLabelAttribute.text.Split('\n').Length * base.GetPropertyHeight(property, label);
  31. }
  32. }
  33. #endif