暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

NoFoldOutPropertyDrawer.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. base.OnGUI(position, property, label);
  21. else
  22. {
  23. SerializedProperty iter = property.Copy();
  24. property.Next(true);
  25. do
  26. {
  27. float height = EditorGUI.GetPropertyHeight(property, property.hasVisibleChildren);
  28. position.height = height;
  29. EditorGUI.PropertyField(position, property, property.hasVisibleChildren);
  30. position.y = position.y + height;
  31. }
  32. while (property.NextVisible(false));
  33. }
  34. }
  35. }
  36. }