--- a/src/AtomAnimations/Serialization/AtomAnimationSerializer.cs
+++ b/src/AtomAnimations/Serialization/AtomAnimationSerializer.cs
@@ -43,2 +43,7 @@
private readonly List<PendingFloatParamTarget> _pendingFloatParams = new List<PendingFloatParamTarget>();
+
+ // Controller row order: remember the order of the Controllers array while loading, then
+ // re-apply it once loading finishes. Add() calls list.Sort(comparer) on every insert, which
+ // otherwise throws away the order produced by "Drag to reorder".
+ private readonly Dictionary<AtomAnimationClip, List<FreeControllerV3AnimationTarget>> _controllerOrder = new Dictionary<AtomAnimationClip, List<FreeControllerV3AnimationTarget>>();
@@ -399,2 +404,6 @@
clip.ResolveReactiveMembers();
+
+ // Controller row order: on the non-scene-loading path (import/restore) all controllers
+ // are already added, so restore the saved order here.
+ if (!SuperController.singleton.isLoading) ApplyControllerOrder(clip);
}
@@ -518,2 +527,4 @@
}
+
+ RecordControllerOrder(clip, target);
@@ -671,2 +682,56 @@
}
+
+ // Controller row order: every controller (including the deferred ones) is in place now,
+ // so re-apply the order saved in the scene.
+ if (_controllerOrder.Count > 0)
+ {
+ var orderedClips = _controllerOrder.Keys.ToArray();
+ for (var i = 0; i < orderedClips.Length; i++) ApplyControllerOrder(orderedClips[i]);
+ }
+ }
+
+ private void RecordControllerOrder(AtomAnimationClip clip, FreeControllerV3AnimationTarget target)
+ {
+ if (clip == null || target == null) return;
+ List<FreeControllerV3AnimationTarget> order;
+ if (!_controllerOrder.TryGetValue(clip, out order))
+ {
+ order = new List<FreeControllerV3AnimationTarget>();
+ _controllerOrder[clip] = order;
+ }
+ order.Add(target);
+ }
+
+ // Restores the controller order saved in the scene (Add()'s Sort would otherwise win).
+ private void ApplyControllerOrder(AtomAnimationClip clip)
+ {
+ if (clip == null) return;
+ List<FreeControllerV3AnimationTarget> order;
+ if (!_controllerOrder.TryGetValue(clip, out order)) return;
+ _controllerOrder.Remove(clip);
+ if (order.Count == 0) return;
+
+ var list = clip.targetControllers;
+ if (list.Count <= 1) return;
+
+ var reordered = list.OrderBy(t =>
+ {
+ var index = order.IndexOf(t);
+ return index < 0 ? int.MaxValue : index;
+ }).ToList();
+
+ var changed = false;
+ for (var i = 0; i < reordered.Count; i++)
+ {
+ if (!ReferenceEquals(reordered[i], list[i]))
+ {
+ changed = true;
+ break;
+ }
+ }
+ if (!changed) return;
+
+ list.Clear();
+ list.AddRange(reordered);
+ clip.NotifyTargetsListChanged();
}