From 9900a6025a76fcb43b89ba8ab8b71b7f2fe6e532 Mon Sep 17 00:00:00 2001 From: Gregory Labute Date: Mon, 10 Jun 2024 12:09:50 -0400 Subject: [PATCH] More reduction of excess containers --- .../Obsolete/ObsoletePropertyDrawers.cs | 2 +- .../InputAxisPropertyDrawer.cs | 14 ++++++----- .../Editor/Utility/InspectorUtility.cs | 25 +++++++++++++------ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/com.unity.cinemachine/Editor/Obsolete/ObsoletePropertyDrawers.cs b/com.unity.cinemachine/Editor/Obsolete/ObsoletePropertyDrawers.cs index da6b405fa..64063cabf 100644 --- a/com.unity.cinemachine/Editor/Obsolete/ObsoletePropertyDrawers.cs +++ b/com.unity.cinemachine/Editor/Obsolete/ObsoletePropertyDrawers.cs @@ -158,7 +158,7 @@ public override void OnGUI(Rect rect, SerializedProperty property, GUIContent la } } - partial class InputAxisWithNamePropertyDrawer : PropertyDrawer + partial class InputAxisPropertyDrawer : PropertyDrawer { public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label) { diff --git a/com.unity.cinemachine/Editor/PropertyDrawers/InputAxisPropertyDrawer.cs b/com.unity.cinemachine/Editor/PropertyDrawers/InputAxisPropertyDrawer.cs index 39a99b348..049c14940 100644 --- a/com.unity.cinemachine/Editor/PropertyDrawers/InputAxisPropertyDrawer.cs +++ b/com.unity.cinemachine/Editor/PropertyDrawers/InputAxisPropertyDrawer.cs @@ -5,7 +5,7 @@ namespace Unity.Cinemachine.Editor { [CustomPropertyDrawer(typeof(InputAxis))] - partial class InputAxisWithNamePropertyDrawer : PropertyDrawer + partial class InputAxisPropertyDrawer : PropertyDrawer { InputAxis def = new (); // to access name strings @@ -24,17 +24,19 @@ public override VisualElement CreatePropertyGUI(SerializedProperty property) var ux = new InspectorUtility.FoldoutWithOverlay(foldout, valueField, valueLabel); // We want dynamic dragging on the value, even if isDelayed is set - var valueFieldRow = foldout.AddChild(new InspectorUtility.LabeledRow( - valueProp.displayName, valueProp.tooltip, new PropertyField(valueProp, "") { style = { marginLeft = 0 }})); - valueFieldRow.Contents.OnInitialGeometry(() => valueFieldRow.Contents.SafeSetIsDelayed()); - valueFieldRow.Label.AddDelayedFriendlyPropertyDragger(valueProp, valueFieldRow.Contents, (d) => d.CancelDelayedWhenDragging = true); + var valueField2 = new FloatField("") { isDelayed = true }; + var valueFieldRow = foldout.AddChild(new InspectorUtility.LabeledRow(valueProp.displayName, valueProp.tooltip, valueField2)); + valueFieldRow.Label.AddDelayedFriendlyPropertyDragger(valueProp, valueField2, (d) => d.CancelDelayedWhenDragging = true); + valueField2.BindProperty(valueProp); + valueField2.style.marginLeft = 5; + valueField2.style.marginRight = -2; var centerField = foldout.AddChild(new PropertyField(property.FindPropertyRelative(() => def.Center))); var rangeContainer = foldout.AddChild(new VisualElement() { style = { flexDirection = FlexDirection.Row }}); rangeContainer.Add(new PropertyField(property.FindPropertyRelative(() => def.Range)) { style = { flexGrow = 1 }}); var wrapProp = property.FindPropertyRelative(() => def.Wrap); var wrap = rangeContainer.AddChild(new PropertyField(wrapProp, "") - { style = { alignSelf = Align.Center, marginLeft = 5, marginRight = 5 }}); + { style = { alignSelf = Align.Center, marginLeft = 5, marginRight = 5, marginTop = 2 }}); var wrapLabel = rangeContainer.AddChild(new Label(wrapProp.displayName) { tooltip = wrapProp.tooltip, style = { alignSelf = Align.Center }}); var recentering = foldout.AddChild(new PropertyField(property.FindPropertyRelative(() => def.Recentering))); diff --git a/com.unity.cinemachine/Editor/Utility/InspectorUtility.cs b/com.unity.cinemachine/Editor/Utility/InspectorUtility.cs index f9ee51b92..4c54d12a8 100644 --- a/com.unity.cinemachine/Editor/Utility/InspectorUtility.cs +++ b/com.unity.cinemachine/Editor/Utility/InspectorUtility.cs @@ -417,7 +417,7 @@ public class LeftRightRow : VisualElement /// public bool KillLeftMargin; - public LeftRightRow() + public LeftRightRow(VisualElement left = null, VisualElement right = null) { // This is to peek at the resolved label width Add(new AlignFieldSizer { OnLabelWidthChanged = (w) => @@ -427,10 +427,20 @@ public LeftRightRow() Left.style.width = w + DivisionOffset; }}); - style.marginLeft = 3; + // Actual contents will live in this row var row = AddChild(this, new VisualElement { style = { flexDirection = FlexDirection.Row }}); - Left = row.AddChild(new VisualElement { style = { flexDirection = FlexDirection.Row, flexGrow = 0 }}); - Right = row.AddChild(new VisualElement { style = { flexDirection = FlexDirection.Row, flexGrow = 1, marginLeft = 2 }}); + style.marginLeft = 3; + + left ??= new VisualElement(); + Left = row.AddChild(left); + Left.style.flexDirection = FlexDirection.Row; + Left.style.flexGrow = 0; + + right ??= new VisualElement(); + Right = row.AddChild(right); + Right.style.flexDirection = FlexDirection.Row; + Right.style.flexGrow = 1; + Right.style.marginLeft = 2; } // This is a hacky thing to create custom inspector rows with labels that are the correct size @@ -460,10 +470,11 @@ public class LabeledRow : LeftRightRow public Label Label { get; private set; } public VisualElement Contents { get; private set; } - public LabeledRow(string label, string tooltip, VisualElement contents) + public LabeledRow(string label, string tooltip, VisualElement contents = null) + : base(new Label(label) { tooltip = tooltip, style = { alignSelf = Align.Center, flexGrow = 1 }}, contents) { - Label = Left.AddChild(new Label(label) { tooltip = tooltip, style = { alignSelf = Align.Center, flexGrow = 1 }}); - Contents = Right.AddChild(contents); + Label = Left as Label; + Contents = Right; style.marginRight = 0; style.flexGrow = 1; Contents.tooltip = tooltip;