Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 0.0.34 #37

Merged
merged 2 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading