Skip to content

Commit e749e56

Browse files
committed
Fix Copy/Paste context menu operations for serialized references
1 parent 86ccf55 commit e749e56

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

Assets/Editor Toolbox/Editor/ContextMenu/Operations/SerializeReference/CopySerializeReferenceCache.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ namespace Toolbox.Editor.ContextMenu.Operations
99
/// </summary>
1010
internal class CopySerializeReferenceCache
1111
{
12-
public CopySerializeReferenceCache(Type referenceType, IReadOnlyList<CopySerializeReferenceEntry> entires)
12+
public CopySerializeReferenceCache(Type referenceType, IReadOnlyList<CopySerializeReferenceEntry> entires, bool isArrayCopy)
1313
{
1414
ReferenceType = referenceType;
1515
Entries = entires;
16+
IsArrayCopy = isArrayCopy;
1617
}
1718

1819
/// <summary>
1920
/// Base managed reference type of the source <see cref="UnityEditor.SerializedProperty"/>.
2021
/// </summary>
2122
public Type ReferenceType { get; }
2223
public IReadOnlyList<CopySerializeReferenceEntry> Entries { get; }
23-
public bool IsArrayCopy => Entries != null && Entries.Count > 1;
24+
public bool IsArrayCopy { get; }
2425
}
2526
}

Assets/Editor Toolbox/Editor/ContextMenu/Operations/SerializeReference/CopySerializeReferenceOperation.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public bool IsEnabled(SerializedProperty property)
5151

5252
public void Perform(SerializedProperty property)
5353
{
54+
var isArrayCopy = false;
5455
var entries = new List<CopySerializeReferenceEntry>();
5556
if (property.propertyType == SerializedPropertyType.ManagedReference)
5657
{
@@ -59,6 +60,7 @@ public void Perform(SerializedProperty property)
5960
}
6061
else if (property.isArray)
6162
{
63+
isArrayCopy = true;
6264
var propertiesCount = property.arraySize;
6365
for (var i = 0; i < propertiesCount; i++)
6466
{
@@ -69,7 +71,7 @@ public void Perform(SerializedProperty property)
6971
}
7072

7173
PropertyUtility.TryGetSerializeReferenceType(property, out var referenceType);
72-
Cache = new CopySerializeReferenceCache(referenceType, entries);
74+
Cache = new CopySerializeReferenceCache(referenceType, entries, isArrayCopy);
7375
}
7476

7577
public GUIContent Label => new GUIContent("Copy Serialized References");

Assets/Editor Toolbox/Editor/ContextMenu/Operations/SerializeReference/PasteSerializeReferenceOperation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private bool IsAssignmentValid(Type targetType, CopySerializeReferenceEntry entr
3636
return true;
3737
}
3838

39-
return TypeUtility.IsTypeAssignableFrom(targetType, entry.ReferenceType);
39+
return TypeUtility.IsTypeAssignableFrom(targetType, entryType);
4040
}
4141

4242
private bool IsOperationSupported(SerializedProperty targetProperty, CopySerializeReferenceCache cache)

Assets/Editor Toolbox/Editor/Utilities/PropertyUtility.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -672,20 +672,21 @@ internal static bool IsSerializeReferenceProperty(SerializedProperty property)
672672

673673
internal static bool TryGetSerializeReferenceType(SerializedProperty property, out Type referenceType)
674674
{
675-
var fieldInfo = GetFieldInfo(property, out var propertyType);
675+
var fieldInfo = GetFieldInfo(property, propertyType: out _);
676676
if (fieldInfo == null)
677677
{
678678
referenceType = null;
679679
return false;
680680
}
681681

682-
if (property.isArray)
682+
var fieldType = fieldInfo.FieldType;
683+
if (property.isArray || IsSerializableArrayElement(property))
683684
{
684-
referenceType = GetElementTypeFromArrayType(propertyType);
685+
referenceType = GetElementTypeFromArrayType(fieldType);
685686
}
686687
else
687688
{
688-
referenceType = fieldInfo.FieldType;
689+
referenceType = fieldType;
689690
}
690691

691692
return true;

0 commit comments

Comments
 (0)