Skip to content

Commit 89f3054

Browse files
committed
Fix Append/Remove List operations if multi-selection is active
1 parent be4f104 commit 89f3054

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-9
lines changed

Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelf/ReferencePickerAttributeDrawer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ private static Type GetCurrentManagedReferenceType(SerializedProperty property,
5656
using (var tempSerializedObject = new SerializedObject(target))
5757
{
5858
var tempProperty = tempSerializedObject.FindProperty(property.propertyPath);
59+
if (tempProperty == null)
60+
{
61+
break;
62+
}
63+
5964
if (tempProperty.managedReferenceFullTypename != fullTypeName)
6065
{
6166
hasMixedValues = true;

Assets/Editor Toolbox/Editor/Internal/ReorderableListBase.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,10 @@ public void CutKeyboardFocus()
457457

458458
public void AppendElement()
459459
{
460-
Index = (List.arraySize += 1) - 1;
460+
var newSize = Size.intValue + 1;
461+
Size.intValue = newSize;
462+
Index = newSize - 1;
463+
461464
if (overrideNewElementCallback == null)
462465
{
463466
return;
@@ -522,6 +525,7 @@ public virtual void DrawStandardFooter(Rect rect)
522525
//set button area rect
523526
rect = new Rect(rect.xMax - Style.footerWidth, rect.y, Style.footerWidth, rect.height);
524527

528+
var actionPerformed = false;
525529
//set rect properties from style
526530
var buttonWidth = Style.footerButtonWidth;
527531
var buttonHeight = Style.footerButtonHeight;
@@ -531,7 +535,7 @@ public virtual void DrawStandardFooter(Rect rect)
531535
//set proper rect for each button
532536
var appendButtonRect = new Rect(rect.xMin + margin, rect.y - padding, buttonWidth, buttonHeight);
533537

534-
EditorGUI.BeginDisabledGroup(List.hasMultipleDifferentValues);
538+
EditorGUI.BeginDisabledGroup(Size.hasMultipleDifferentValues);
535539
EditorGUI.BeginDisabledGroup(onCanAppendCallback != null && !onCanAppendCallback(this));
536540
if (GUI.Button(appendButtonRect, onAppendDropdownCallback != null
537541
? Style.iconToolbarDropContent
@@ -551,9 +555,10 @@ public virtual void DrawStandardFooter(Rect rect)
551555
}
552556

553557
onChangedCallback?.Invoke(this);
558+
actionPerformed = true;
554559
}
555-
EditorGUI.EndDisabledGroup();
556560

561+
EditorGUI.EndDisabledGroup();
557562
var removeButtonRect = new Rect(rect.xMax - buttonWidth - margin, rect.y - padding, buttonWidth, buttonHeight);
558563

559564
EditorGUI.BeginDisabledGroup((onCanRemoveCallback != null && !onCanRemoveCallback(this) || Index < 0 || Index >= Count));
@@ -569,9 +574,17 @@ public virtual void DrawStandardFooter(Rect rect)
569574
}
570575

571576
onChangedCallback?.Invoke(this);
577+
actionPerformed = true;
572578
}
579+
573580
EditorGUI.EndDisabledGroup();
574581
EditorGUI.EndDisabledGroup();
582+
583+
if (actionPerformed)
584+
{
585+
SerializedObject.ApplyModifiedProperties();
586+
GUIUtility.ExitGUI();
587+
}
575588
}
576589

577590
/// <summary>

Assets/Examples/Scriptables/Sample Scriptable Object.asset

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,9 @@ MonoBehaviour:
1414
m_EditorClassIdentifier:
1515
var1: 1
1616
var2: 32
17-
vars:
18-
- abc
17+
vars1: []
18+
vars2: 00000000
19+
var3:
20+
var1: 0
21+
vars: 0000000000000000
22+
var2: 0

Assets/Examples/Scripts/SampleBehaviour3.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using UnityEngine;
1+
using Toolbox.Editor.Drawers;
2+
using UnityEditor;
3+
using UnityEngine;
24

35
[ExecuteAlways]
46
[AddComponentMenu("Editor Toolbox/Cheat Sheet 3 (Toolbox Conditions)")]
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
using UnityEngine;
2-
1+
using System;
32
using Toolbox.Attributes;
3+
using UnityEngine;
44

55
[CreateInWizard]
66
public class SampleScriptableObject : ScriptableObject
77
{
8+
[Serializable]
9+
public class NestedClass
10+
{
11+
public bool var1;
12+
[ReorderableList]
13+
public int[] vars;
14+
public bool var2;
15+
}
16+
817
public bool var1;
918
[EnableIf(nameof(var1), true)]
1019
public int var2;
11-
public string[] vars;
20+
public string[] vars1;
21+
[ReorderableList]
22+
public int[] vars2;
23+
public NestedClass var3;
1224
}

0 commit comments

Comments
 (0)