Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

NoFoldOutPropertyDrawer.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using UnityEditor;
  2. using UnityEngine;
  3. namespace Timeline.Samples
  4. {
  5. // Custom property drawer that draws all child properties inline
  6. [CustomPropertyDrawer(typeof(NoFoldOutAttribute))]
  7. public class NoFoldOutPropertyDrawer : PropertyDrawer
  8. {
  9. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  10. {
  11. if (!property.hasChildren)
  12. return base.GetPropertyHeight(property, label);
  13. property.isExpanded = true;
  14. return EditorGUI.GetPropertyHeight(property, label, true) -
  15. EditorGUI.GetPropertyHeight(property, label, false);
  16. }
  17. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  18. {
  19. if (!property.hasChildren)
  20. EditorGUI.PropertyField(position, property, label);
  21. else
  22. {
  23. SerializedProperty iter = property.Copy();
  24. var nextSibling = property.Copy();
  25. nextSibling.Next(false);
  26. property.Next(true);
  27. do
  28. {
  29. // We need to check against nextSibling to properly stop
  30. // otherwise we will draw properties that are not child of this
  31. // foldout.
  32. if (SerializedProperty.EqualContents(property, nextSibling))
  33. break;
  34. float height = EditorGUI.GetPropertyHeight(property, property.hasVisibleChildren);
  35. position.height = height;
  36. EditorGUI.PropertyField(position, property, property.hasVisibleChildren);
  37. position.y = position.y + height;
  38. }
  39. while (property.NextVisible(false));
  40. }
  41. }
  42. }
  43. }