Skip to content

Commit 835f04e

Browse files
committed
https://github.com/annulusgames/LitMotion/pull/233
BugFix: "Duplicate Array Element" in the context menu of LitMotionAnimation caused shared references annulusgames#233
1 parent 33cb25e commit 835f04e

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,24 @@ VisualElement CreateComponentsPanel()
146146
{
147147
if (componentsProperty.arraySize != prevArraySize)
148148
{
149+
if (prevArraySize < componentsProperty.arraySize)
150+
{
151+
var seen = new HashSet<object>();
152+
bool dirty = false;
153+
for (int i = 0; i < componentsProperty.arraySize; ++i)
154+
{
155+
var element = componentsProperty.GetArrayElementAtIndex(i);
156+
var value = element.managedReferenceValue;
157+
if (value != null && !seen.Add(value))
158+
{
159+
var cloned = JsonUtility.FromJson(JsonUtility.ToJson(value), value.GetType());
160+
element.managedReferenceValue = cloned;
161+
dirty = true;
162+
}
163+
}
164+
if (dirty)
165+
serializedObject.ApplyModifiedProperties();
166+
}
149167
RefleshComponentsView(true);
150168
prevArraySize = componentsProperty.arraySize;
151169
}

0 commit comments

Comments
 (0)