OptionalDrawer.cs 775 B

1234567891011121314151617181920212223242526
  1. using UnityEngine;
  2. using UnityEditor;
  3. using Rokid.UXR.Interaction;
  4. namespace Rokid.UXR.Editor
  5. {
  6. /// <summary>
  7. /// Adds an [Optional] label in the inspector over any SerializedField with this attribute.
  8. /// </summary>
  9. [CustomPropertyDrawer(typeof(OptionalAttribute))]
  10. public class OptionalDrawer : DecoratorDrawer
  11. {
  12. private static readonly float HEADER_SIZE_AS_PERCENT = 0.25f;
  13. public override float GetHeight()
  14. {
  15. return base.GetHeight() * (1f + HEADER_SIZE_AS_PERCENT);
  16. }
  17. public override void OnGUI(Rect position)
  18. {
  19. position.y += GetHeight() * HEADER_SIZE_AS_PERCENT / (1f + HEADER_SIZE_AS_PERCENT);
  20. EditorGUI.LabelField(position, "[Optional]");
  21. }
  22. }
  23. }