Skip to content

Commit

Permalink
Merge pull request #37 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.34
  • Loading branch information
uurha authored Aug 4, 2024
2 parents 459a46f + 930c29e commit f81d606
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
38 changes: 22 additions & 16 deletions Assets/BetterCommons/Editor/Drawers/SerializeReferenceField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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<SerializeReferenceField>().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;
Expand Down
2 changes: 1 addition & 1 deletion Assets/BetterCommons/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit f81d606

Please sign in to comment.