modular-avatar/UnitTests~/ActiveAnimationRetargeterTests/ActiveAnimationRetargeterTests.cs
bd_ 57fe84548c
feat: shape changer can respond to multiple parent objects being animated (#916)
* refactor: generalize the shape changer implementation a bit

* feat: shape changer can respond to multiple parent objects being animated

Closes: #865
2024-07-06 21:39:42 -07:00

47 lines
1.6 KiB
C#

#if MA_VRCSDK3_AVATARS
using modular_avatar_tests;
using nadena.dev.modular_avatar.animation;
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
using EditorCurveBinding = UnityEditor.EditorCurveBinding;
public class ActiveAnimationRetargeterTests : TestBase
{
[Test]
public void SimpleRetarget()
{
var avatar = CreatePrefab("SimpleRetarget.prefab");
// initialize context
var buildContext = new BuildContext(avatar);
var pathMappings = buildContext.PluginBuildContext.ActivateExtensionContext<AnimationServicesContext>()
.PathMappings;
// get game objects
var changedChild = avatar.transform.Find("Toggled/Child");
var newParent = avatar.transform.Find("NewParent");
// do retargeting
var retargeter = new ActiveAnimationRetargeter(buildContext, new BoneDatabase(), changedChild);
var created = retargeter.CreateIntermediateObjects(newParent.gameObject);
retargeter.FixupAnimations();
// commit
buildContext.AnimationDatabase.Commit();
var clip = findFxClip(avatar, layerName: "retarget");
var curveBindings = AnimationUtility.GetCurveBindings(clip);
// Intermediate object must be created
Assert.That(created, Is.Not.EqualTo(newParent.gameObject));
// The created animation must have m_IsActive of intermediate object
Assert.That(curveBindings, Does.Contain(EditorCurveBinding.FloatCurve(
pathMappings.GetObjectIdentifier(created), typeof(GameObject), "m_IsActive")));
}
}
#endif