From 4405d7aa5640d9837a9ee2234b17b2e5b2a7f18f Mon Sep 17 00:00:00 2001 From: bd_ Date: Sat, 16 Nov 2024 19:02:24 -0800 Subject: [PATCH] fix: MA Parameters bool items + MA Menu Item auto value is broken (#1345) Closes: #1331 --- .../ReactiveObjects/ParameterAssignerPass.cs | 11 +++++- .../AutoValueAssignmentTests.cs | 37 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Editor/ReactiveObjects/ParameterAssignerPass.cs b/Editor/ReactiveObjects/ParameterAssignerPass.cs index e62b3ff5..f7512050 100644 --- a/Editor/ReactiveObjects/ParameterAssignerPass.cs +++ b/Editor/ReactiveObjects/ParameterAssignerPass.cs @@ -2,8 +2,8 @@ using System.Collections.Generic; using System.Linq; using nadena.dev.ndmf; -using UnityEngine; using UnityEditor.Animations; +using UnityEngine; using VRC.SDK3.Avatars.Components; using VRC.SDK3.Avatars.ScriptableObjects; @@ -144,6 +144,12 @@ namespace nadena.dev.modular_avatar.core.editor { mami.Control.value = defaultValue.GetValueOrDefault(); } + else if (p != null && p.valueType != VRCExpressionParameters.ValueType.Int) + { + // For a float or bool value, we don't really have a lot of good choices, so just set it to + // 1 + mami.Control.value = 1; + } else { while (usedValues.Contains(nextValue)) nextValue++; @@ -228,7 +234,8 @@ namespace nadena.dev.modular_avatar.core.editor if (simulationInitialStates != null) { var isDefault = mami.isDefault; - if (isDefaultOverrides?.TryGetValue(paramName, out var target) == true) + ModularAvatarMenuItem target = null; + if (isDefaultOverrides?.TryGetValue(paramName, out target) == true) isDefault = ReferenceEquals(mami, target); if (isDefault) diff --git a/UnitTests~/ReactiveComponent/ParameterAssignment/AutoValueAssignmentTests.cs b/UnitTests~/ReactiveComponent/ParameterAssignment/AutoValueAssignmentTests.cs index a2c9b5b8..75492c37 100644 --- a/UnitTests~/ReactiveComponent/ParameterAssignment/AutoValueAssignmentTests.cs +++ b/UnitTests~/ReactiveComponent/ParameterAssignment/AutoValueAssignmentTests.cs @@ -15,6 +15,43 @@ namespace UnitTests.ReactiveComponent.ParameterAssignment { public class AutoValueAssignmentTests : TestBase { + [Test] + public void AutoValueWithMAParameters() + { + var root = CreateRoot("root"); + var child = CreateChild(root, "child"); + + var parameters = child.AddComponent(); + parameters.parameters = new() + { + new ParameterConfig() + { + defaultValue = 1.0f, + hasExplicitDefaultValue = true, + nameOrPrefix = "foo", + syncType = ParameterSyncType.Bool + } + }; + + var mami = child.AddComponent(); + mami.Control = new() + { + parameter = new() + { + name = "foo" + }, + name = "x" + }; + mami.automaticValue = true; + + child.AddComponent(); + + AvatarProcessor.ProcessAvatar(root); + var menu = root.GetComponent().expressionsMenu + .controls.First(c => c.name == "child"); + Assert.AreEqual(1, menu.value); + } + [Test] public void ManuallyAssignedParametersAreNotReplaced() {