fix: MA Parameters bool items + MA Menu Item auto value is broken (#1345)

Closes: #1331
This commit is contained in:
bd_ 2024-11-16 19:02:24 -08:00 committed by GitHub
parent a984cf8673
commit 4405d7aa56
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 2 deletions

View File

@ -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)

View File

@ -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<ModularAvatarParameters>();
parameters.parameters = new()
{
new ParameterConfig()
{
defaultValue = 1.0f,
hasExplicitDefaultValue = true,
nameOrPrefix = "foo",
syncType = ParameterSyncType.Bool
}
};
var mami = child.AddComponent<ModularAvatarMenuItem>();
mami.Control = new()
{
parameter = new()
{
name = "foo"
},
name = "x"
};
mami.automaticValue = true;
child.AddComponent<ModularAvatarMenuInstaller>();
AvatarProcessor.ProcessAvatar(root);
var menu = root.GetComponent<VRCAvatarDescriptor>().expressionsMenu
.controls.First(c => c.name == "child");
Assert.AreEqual(1, menu.value);
}
[Test]
public void ManuallyAssignedParametersAreNotReplaced()
{