diff --git a/Assets/BetterCommons/Editor/Drawers/SerializeReferenceField.cs b/Assets/BetterCommons/Editor/Drawers/SerializeReferenceField.cs index aa67289..d459512 100644 --- a/Assets/BetterCommons/Editor/Drawers/SerializeReferenceField.cs +++ b/Assets/BetterCommons/Editor/Drawers/SerializeReferenceField.cs @@ -59,7 +59,7 @@ public SerializeReferenceField(SerializedProperty property, string label) PropertyField = CreatePropertyField(property, label); #if !UNITY_2022_2_OR_NEWER - if (TryCreateBufferLabel(property, out var bufferLabel)) + if (IsLastSerializeField() && TryCreateBufferLabel(property, out var bufferLabel)) { _bufferLabel = bufferLabel; Insert(0, _bufferLabel); @@ -98,6 +98,15 @@ private void Update() return; } +#if !UNITY_2022_2_OR_NEWER + var isLast = IsLastSerializeField(); + if (!isLast && _bufferLabel != null) + { + _bufferLabel.RemoveFromHierarchy(); + _bufferLabel = null; + } +#endif + var newType = property.managedReferenceFullTypename; if (_referenceType != newType) @@ -114,13 +123,7 @@ private void Update() finally { #if !UNITY_2022_2_OR_NEWER - if (_bufferLabel != null) - { - _bufferLabel.RemoveFromHierarchy(); - _bufferLabel = null; - } - - if (TryCreateBufferLabel(property, out var label)) + if (isLast && TryCreateBufferLabel(property, out var label)) { _bufferLabel = label; Insert(0, _bufferLabel); @@ -142,17 +145,20 @@ private void Update() #if !UNITY_2022_2_OR_NEWER - private bool TryCreateBufferLabel(SerializedProperty property, out Label label) + + private bool IsLastSerializeField() { var query = this.Query().Last(); - if (query == this) + return query == this; + } + + private bool TryCreateBufferLabel(SerializedProperty property, out Label label) + { + if (property.managedReferenceFullTypename.IsNullOrEmpty() || !property.hasVisibleChildren) { - if (property.managedReferenceFullTypename.IsNullOrEmpty() || !property.hasVisibleChildren) - { - label = VisualElementUtility.CreateLabel(PropertyField.label); - label.AddToClassList(StyleDefinition.CombineSubState(nameof(SerializeReferenceField), "dummy-label")); - return true; - } + label = VisualElementUtility.CreateLabel(PropertyField.label); + label.AddToClassList(StyleDefinition.CombineSubState(nameof(SerializeReferenceField), "dummy-label")); + return true; } label = null; diff --git a/Assets/BetterCommons/package.json b/Assets/BetterCommons/package.json index 60c54cd..3401f8b 100644 --- a/Assets/BetterCommons/package.json +++ b/Assets/BetterCommons/package.json @@ -1,7 +1,7 @@ { "name": "com.tdw.better.commons", "displayName": "Better Commons", - "version": "0.0.33", + "version": "0.0.34", "unity": "2021.3", "description": " ", "dependencies": {