PlayableBehaviourDrawer.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace UnityUIPlayables.Editor
  4. {
  5. public class PlayableBehaviourDrawer : PropertyDrawer
  6. {
  7. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  8. {
  9. EditorGUI.indentLevel--;
  10. // Draw default GUI without property name.
  11. property = property.serializedObject.FindProperty(property.propertyPath);
  12. var fieldRect = position;
  13. fieldRect.height = EditorGUIUtility.singleLineHeight;
  14. using (new EditorGUI.PropertyScope(fieldRect, label, property))
  15. {
  16. using (new EditorGUI.IndentLevelScope())
  17. {
  18. property.NextVisible(true);
  19. var depth = property.depth;
  20. EditorGUI.PropertyField(fieldRect, property, true);
  21. fieldRect.y += EditorGUI.GetPropertyHeight(property, true);
  22. fieldRect.y += EditorGUIUtility.standardVerticalSpacing;
  23. while (property.NextVisible(false))
  24. {
  25. if (property.depth != depth)
  26. {
  27. break;
  28. }
  29. EditorGUI.PropertyField(fieldRect, property, true);
  30. fieldRect.y += EditorGUI.GetPropertyHeight(property, true);
  31. fieldRect.y += EditorGUIUtility.standardVerticalSpacing;
  32. }
  33. }
  34. }
  35. EditorGUI.indentLevel++;
  36. }
  37. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  38. {
  39. property = property.serializedObject.FindProperty(property.propertyPath);
  40. var height = 0.0f;
  41. property.NextVisible(true);
  42. var depth = property.depth;
  43. height += EditorGUI.GetPropertyHeight(property, true);
  44. height += EditorGUIUtility.standardVerticalSpacing;
  45. while (property.NextVisible(false))
  46. {
  47. if (property.depth != depth)
  48. {
  49. break;
  50. }
  51. height += EditorGUI.GetPropertyHeight(property, true);
  52. height += EditorGUIUtility.standardVerticalSpacing;
  53. }
  54. height -= EditorGUIUtility.standardVerticalSpacing;
  55. return height;
  56. }
  57. }
  58. }