Skip to content

Commit 39d9821

Browse files
BugFix: "Duplicate Array Element" in the context menu of LitMotionAnimation caused shared references annulusgames#233
1 parent 8f2d5c1 commit 39d9821

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/LitMotion/Assets/LitMotion.Animation/Editor/LitMotionAnimationEditor.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using UnityEditor.UIElements;
44
using System.Collections.Generic;
55
using UnityEngine;
6-
using UnityEditor.SceneManagement;
76

87
namespace LitMotion.Animation.Editor
98
{
@@ -146,6 +145,24 @@ VisualElement CreateComponentsPanel()
146145
{
147146
if (componentsProperty.arraySize != prevArraySize)
148147
{
148+
if (prevArraySize < componentsProperty.arraySize)
149+
{
150+
var seen = new HashSet<object>();
151+
bool dirty = false;
152+
for (int i = 0; i < componentsProperty.arraySize; ++i)
153+
{
154+
var element = componentsProperty.GetArrayElementAtIndex(i);
155+
var value = element.managedReferenceValue;
156+
if (value != null && !seen.Add(value))
157+
{
158+
var cloned = JsonUtility.FromJson(JsonUtility.ToJson(value), value.GetType());
159+
element.managedReferenceValue = cloned;
160+
dirty = true;
161+
}
162+
}
163+
if (dirty)
164+
serializedObject.ApplyModifiedProperties();
165+
}
149166
RefleshComponentsView(true);
150167
prevArraySize = componentsProperty.arraySize;
151168
}

0 commit comments

Comments
 (0)