mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-30 18:22:52 +08:00
fix: always-on toggles fail to animate objects to off (#1300)
Closes: #1285
This commit is contained in:
parent
ae975506d7
commit
9dc342e81e
@ -59,6 +59,21 @@ namespace nadena.dev.modular_avatar.animation
|
||||
defaultWeight = 1,
|
||||
blendingMode = AnimatorLayerBlendingMode.Override
|
||||
}).ToArray();
|
||||
|
||||
// Ensure the initial state of readable props matches the actual state of the gameobject
|
||||
var parameters = fx.parameters;
|
||||
var paramToIndex = parameters.Select((p, i) => (p, i)).ToDictionary(x => x.p.name, x => x.i);
|
||||
foreach (var (binding, prop) in asc.BoundReadableProperties)
|
||||
{
|
||||
var obj = asc.PathMappings.PathToObject(binding.path);
|
||||
|
||||
if (obj != null && paramToIndex.TryGetValue(prop, out var index))
|
||||
{
|
||||
parameters[index].defaultFloat = obj.activeSelf ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
fx.parameters = parameters;
|
||||
}
|
||||
|
||||
private ChildMotion GenerateDelayChild(Motion nullMotion, (EditorCurveBinding, string) binding)
|
||||
|
50
UnitTests~/ReactiveComponent/ObjectToggleTests.cs
Normal file
50
UnitTests~/ReactiveComponent/ObjectToggleTests.cs
Normal file
@ -0,0 +1,50 @@
|
||||
using System.Linq;
|
||||
using modular_avatar_tests;
|
||||
using nadena.dev.modular_avatar.core;
|
||||
using nadena.dev.modular_avatar.core.editor;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Animations;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnitTests.ReactiveComponent
|
||||
{
|
||||
internal class ObjectToggleTests : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void WhenObjectIsAlwaysOn_CorrectProxyParameterIsGenerated()
|
||||
{
|
||||
var root = CreateRoot("root");
|
||||
var obj = CreateChild(root, "obj");
|
||||
var toggle = CreateChild(root, "toggle");
|
||||
|
||||
// Prevent obj from being removed by the GC game objects pass
|
||||
obj.AddComponent<MeshRenderer>();
|
||||
|
||||
var toggleComponent = toggle.AddComponent<ModularAvatarObjectToggle>();
|
||||
var aor = new AvatarObjectReference();
|
||||
aor.Set(obj);
|
||||
|
||||
toggleComponent.Objects = new()
|
||||
{
|
||||
new()
|
||||
{
|
||||
Active = false,
|
||||
Object = aor
|
||||
}
|
||||
};
|
||||
|
||||
AvatarProcessor.ProcessAvatar(root);
|
||||
|
||||
// TODO: Ideally we should start using play mode testing for these things...
|
||||
var fx = (AnimatorController)FindFxController(root).animatorController;
|
||||
var readableProp = fx.parameters.FirstOrDefault(
|
||||
p => p.name.StartsWith("__MA/ReadableProp/obj/UnityEngine.GameObject/m_IsActive")
|
||||
);
|
||||
|
||||
Assert.IsNotNull(readableProp);
|
||||
Assert.AreEqual(readableProp.defaultFloat, 0);
|
||||
|
||||
Assert.IsFalse(obj.activeSelf);
|
||||
}
|
||||
}
|
||||
}
|
3
UnitTests~/ReactiveComponent/ObjectToggleTests.cs.meta
Normal file
3
UnitTests~/ReactiveComponent/ObjectToggleTests.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c68d69f7b4a46c5b2ce3d8f26b0fa76
|
||||
timeCreated: 1729376563
|
Loading…
Reference in New Issue
Block a user