Skip to content

Commit 718d916

Browse files
committed
Fix compilation issues in Unity 6.5 for the Tab functionality; make sure to create 'empty' instance when using + button in the ReordableList
1 parent 94d4810 commit 718d916

4 files changed

Lines changed: 178 additions & 62 deletions

File tree

Assets/Editor Toolbox/Editor/Drawers/Toolbox/Decorator/BeginTabGroupAttributeDrawer.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,18 +506,38 @@ private struct GroupData
506506

507507
private struct ContextKey : IEquatable<ContextKey>
508508
{
509-
public int InstanceId;
510509
public string GroupId;
510+
#if UNITY_6000_4_OR_NEWER
511+
public EntityId InstanceId;
512+
#else
513+
public int InstanceId;
514+
#endif
511515

512-
public bool Equals(ContextKey other) =>
516+
#if UNITY_6000_4_OR_NEWER
517+
public readonly bool Equals(ContextKey other)
518+
{
519+
return InstanceId == other.InstanceId && GroupId == other.GroupId;
520+
}
521+
522+
public override readonly int GetHashCode()
523+
{
524+
return HashCode.Combine(GroupId, InstanceId);
525+
}
526+
#else
527+
public readonly bool Equals(ContextKey other) =>
513528
InstanceId == other.InstanceId && GroupId == other.GroupId;
514529

515-
public override int GetHashCode() =>
530+
public override readonly int GetHashCode() =>
516531
(InstanceId * 397) ^ (GroupId != null ? GroupId.GetHashCode() : 0);
532+
#endif
517533
}
518534

519535
private static readonly Dictionary<ContextKey, Type> ContextCache = new();
536+
#if UNITY_6000_4_OR_NEWER
537+
private static EntityId _lastSelectionId = EntityId.None;
538+
#else
520539
private static int _lastSelectionId = -1;
540+
#endif
521541

522542
static TabDiscovery()
523543
{
@@ -527,7 +547,11 @@ static TabDiscovery()
527547
private static void ClearContextCache()
528548
{
529549
ContextCache.Clear();
550+
#if UNITY_6000_4_OR_NEWER
551+
_lastSelectionId = EntityId.None;
552+
#else
530553
_lastSelectionId = -1;
554+
#endif
531555
}
532556

533557
public static Type GetContextType(string groupId)
@@ -536,7 +560,11 @@ public static Type GetContextType(string groupId)
536560
if (target == null)
537561
return null;
538562

563+
#if UNITY_6000_4_OR_NEWER
564+
EntityId instanceId = target.GetEntityId();
565+
#else
539566
int instanceId = target.GetInstanceID();
567+
#endif
540568

541569
if (_lastSelectionId != instanceId)
542570
{

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,23 @@ public void AppendElement()
461461
Size.intValue = newSize;
462462
Index = newSize - 1;
463463

464-
if (overrideNewElementCallback == null)
464+
List.serializedObject.ApplyModifiedProperties();
465+
var property = List.GetArrayElementAtIndex(Index);
466+
var fieldInfo = property.GetFieldInfo();
467+
if (fieldInfo == null)
465468
{
466469
return;
467470
}
468471

469-
//make sure serialized data is up-to-date
470-
List.serializedObject.ApplyModifiedProperties();
471-
var property = List.GetArrayElementAtIndex(Index);
472-
var newValue = overrideNewElementCallback(Index);
473-
//update property directly by the reflection
474-
var fieldInfo = property.GetFieldInfo();
475-
property.SetProperValue(fieldInfo, newValue, false);
472+
if (overrideNewElementCallback != null)
473+
{
474+
var newValue = overrideNewElementCallback(Index);
475+
property.SetProperValue(fieldInfo, newValue, false);
476+
}
477+
else
478+
{
479+
property.SetProperValue(fieldInfo, null, false);
480+
}
476481
}
477482

478483
public void RemoveElement()

0 commit comments

Comments
 (0)