AttachmentAnchorDrawer.cs 1.3 KB

1234567891011121314151617181920212223242526272829
  1. #if UNITY_EDITOR
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace GpuEcsAnimationBaker.Engine.Data
  5. {
  6. [CustomPropertyDrawer(typeof(AttachmentAnchor))]
  7. public class AttachmentAnchorDrawer : PropertyDrawer
  8. {
  9. private Rect GetLineRect(Rect position, int line, float indent)
  10. {
  11. return new Rect(position.x + indent, position.y + line * EditorGUIUtility.singleLineHeight,
  12. position.width - indent, EditorGUIUtility.singleLineHeight);
  13. }
  14. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  15. {
  16. EditorGUI.BeginProperty(position, label, property);
  17. SerializedProperty attachmentAnchorIDProperty = property.FindPropertyRelative("attachmentAnchorID");
  18. SerializedProperty attachmentAnchorTransformProperty = property.FindPropertyRelative("attachmentAnchorTransform");
  19. int line = 0;
  20. EditorGUI.PropertyField(GetLineRect(position, line, 0), attachmentAnchorIDProperty, new GUIContent("Anchor ID"));
  21. line++;
  22. EditorGUI.PropertyField(GetLineRect(position, line, 0), attachmentAnchorTransformProperty, new GUIContent("Anchor Transform reference"));
  23. EditorGUI.EndProperty();
  24. }
  25. }
  26. }
  27. #endif