Skip to content

Commit

Permalink
test: test animation length preserved
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Oct 30, 2023
1 parent 8f708ff commit 4a2d76d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Test~/ApplyObjectMappingTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;

Expand Down Expand Up @@ -41,5 +42,41 @@ public void AvatarMask()
Assert.That(avatarMask.GetHumanoidBodyPartActive(AvatarMaskBodyPart.Head), Is.True);
Assert.That(avatarMask.GetHumanoidBodyPartActive(AvatarMaskBodyPart.LeftLeg), Is.False);
}

[Test]
public void PreserveAnimationLength()
{
var root = new GameObject();
var child1 = Utils.NewGameObject("child1", root.transform);
var child11 = Utils.NewGameObject("child11", child1.transform);
var builder = new ObjectMappingBuilder(root);

Object.DestroyImmediate(child11);

var built = builder.BuildObjectMapping();

var rootMapper = new AnimatorControllerMapper(built.CreateAnimationMapper(root));

var animatorController = new AnimatorController();
var layer = new AnimatorControllerLayer()
{
name = "layer",
stateMachine = new AnimatorStateMachine() { name = "layer" },
};
var state = layer.stateMachine.AddState("theState");
var clip = new AnimationClip();
clip.SetCurve("child1/child11", typeof(GameObject), "m_IsActive", AnimationCurve.Constant(0, 0.3f, 1));
state.motion = clip;
animatorController.AddLayer(layer);

var mappedController = rootMapper.MapAnimatorController(animatorController);
Assert.That(mappedController, Is.Not.EqualTo(animatorController));
var mappedClip = mappedController.layers[0].stateMachine.states[0].state.motion as AnimationClip;
Assert.That(mappedClip, Is.Not.Null);

Assert.That(mappedClip.length, Is.EqualTo(0.3f));
Assert.That(AnimationUtility.GetCurveBindings(mappedClip)[0].path,
Contains.Substring("AvatarOptimizerClipLengthDummy"));
}
}
}

0 comments on commit 4a2d76d

Please sign in to comment.