From 962a75f2279e3bd38beacf1d36a97dff9e9dfca8 Mon Sep 17 00:00:00 2001 From: bd_ Date: Sun, 3 Mar 2024 00:16:28 -0800 Subject: [PATCH] fix: parameter order is shuffled (#722) Closes: #713 --- Editor/RenameParametersHook.cs | 2 +- .../RenameParametersTests.cs | 43 ++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Editor/RenameParametersHook.cs b/Editor/RenameParametersHook.cs index bc38d4d8..b1a57e5d 100644 --- a/Editor/RenameParametersHook.cs +++ b/Editor/RenameParametersHook.cs @@ -166,7 +166,7 @@ namespace nadena.dev.modular_avatar.core.editor .Select(p => ResolveParameter(p, syncParams)) .ToList(); - foreach (var kvp in syncParams) + foreach (var kvp in syncParams.OrderBy(kvp => kvp.Value.encounterOrder)) { var name = kvp.Key; var param = kvp.Value; diff --git a/UnitTests~/RenameParametersTests/RenameParametersTests.cs b/UnitTests~/RenameParametersTests/RenameParametersTests.cs index 8a0f6005..d72db7ae 100644 --- a/UnitTests~/RenameParametersTests/RenameParametersTests.cs +++ b/UnitTests~/RenameParametersTests/RenameParametersTests.cs @@ -6,7 +6,6 @@ using System.Collections.Immutable; using System.Linq; using nadena.dev.modular_avatar.core; using nadena.dev.modular_avatar.core.editor; -using nadena.dev.modular_avatar.editor.ErrorReporting; using nadena.dev.ndmf; using NUnit.Framework; using UnityEditor.Animations; @@ -249,6 +248,48 @@ namespace modular_avatar_tests.RenameParametersTests Assert.IsNotEmpty(errors); } + + [Test] + public void ParameterOrderTest() + { + var av = CreateRoot("avatar"); + + var rootMenu = ScriptableObject.CreateInstance(); + var paramsAsset = ScriptableObject.CreateInstance(); + + var desc = av.GetComponent(); + desc.expressionsMenu = rootMenu; + desc.expressionParameters = paramsAsset; + + var c1 = CreateChild(av, "a"); + var c2 = CreateChild(av, "b"); + var c3 = CreateChild(av, "c"); + var c4 = CreateChild(av, "d"); + + AddParam(c1, "A"); + AddParam(c2, "B"); + AddParam(c3, "C"); + AddParam(c4, "D"); + + AvatarProcessor.ProcessAvatar(av); + + paramsAsset = desc.expressionParameters; + + Assert.AreEqual("A", paramsAsset.parameters[0].name); + Assert.AreEqual("B", paramsAsset.parameters[1].name); + Assert.AreEqual("C", paramsAsset.parameters[2].name); + Assert.AreEqual("D", paramsAsset.parameters[3].name); + + void AddParam(GameObject child, String name) + { + var param = child.AddComponent(); + param.parameters.Add(new ParameterConfig() + { + nameOrPrefix = name, + syncType = ParameterSyncType.Float + }); + } + } } }