Skip to content

Commit

Permalink
test: preserve proxy animation
Browse files Browse the repository at this point in the history
  • Loading branch information
anatawa12 committed Nov 3, 2023
1 parent 1465119 commit e4a61f6
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Test~/ApplyObjectMappingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,49 @@ public void PreserveAnimationLength()
Assert.That(AnimationUtility.GetCurveBindings(mappedClip)[0].path,
Contains.Substring("AvatarOptimizerClipLengthDummy"));
}

[Test]
public void PreserveProxyAnimation()
{
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;

var proxyMotion =
AssetDatabase.LoadAssetAtPath<AnimationClip>(
AssetDatabase.GUIDToAssetPath("806c242c97b686d4bac4ad50defd1fdb"));
state = layer.stateMachine.AddState("afk");
state.motion = proxyMotion;

animatorController.AddLayer(layer);

var mappedController = rootMapper.MapAnimatorController(animatorController);
Assert.That(mappedController, Is.Not.EqualTo(animatorController));

// ensure non-proxy mapped
var mappedClip = mappedController.layers[0].stateMachine.states[0].state.motion as AnimationClip;
Assert.That(mappedClip, Is.Not.EqualTo(clip));

mappedClip = mappedController.layers[0].stateMachine.states[1].state.motion as AnimationClip;
Assert.That(mappedClip, Is.EqualTo(proxyMotion));
}
}
}

0 comments on commit e4a61f6

Please sign in to comment.