2023-09-17 17:16:27 +08:00
|
|
|
|
using System.Linq;
|
2023-09-24 13:37:10 +08:00
|
|
|
|
using nadena.dev.modular_avatar.animation;
|
2023-09-17 17:16:27 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEditor.Animations;
|
|
|
|
|
using UnityEngine;
|
2023-11-10 14:37:56 +08:00
|
|
|
|
|
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2023-09-17 17:16:27 +08:00
|
|
|
|
using VRC.SDK3.Avatars.Components;
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#endif
|
2023-09-17 17:16:27 +08:00
|
|
|
|
|
|
|
|
|
namespace modular_avatar_tests
|
|
|
|
|
{
|
|
|
|
|
using UnityObject = UnityEngine.Object;
|
|
|
|
|
|
|
|
|
|
public class TrackObjectRenamesContextTests : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void testBasicContextInitialization()
|
|
|
|
|
{
|
|
|
|
|
var av = CreateRoot("root");
|
|
|
|
|
|
|
|
|
|
var bc = CreateContext(av);
|
2023-09-30 23:09:43 +08:00
|
|
|
|
var toc = new AnimationServicesContext();
|
2023-09-17 17:16:27 +08:00
|
|
|
|
|
|
|
|
|
toc.OnActivate(bc);
|
|
|
|
|
toc.OnDeactivate(bc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TracksSimpleRenames()
|
|
|
|
|
{
|
|
|
|
|
var root = CreateRoot("root");
|
|
|
|
|
var a = CreateChild(root, "a");
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
var toc = new AnimationServicesContext();
|
2023-09-17 17:16:27 +08:00
|
|
|
|
toc.OnActivate(CreateContext(root));
|
2023-09-30 23:09:43 +08:00
|
|
|
|
Assert.AreEqual("a", toc.PathMappings.MapPath("a"));
|
2023-09-17 17:16:27 +08:00
|
|
|
|
a.name = "b";
|
2023-09-30 23:09:43 +08:00
|
|
|
|
toc.PathMappings.ClearCache();
|
|
|
|
|
Assert.AreEqual("b", toc.PathMappings.MapPath("a"));
|
2023-09-17 17:16:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TracksObjectMoves()
|
|
|
|
|
{
|
|
|
|
|
var root = CreateRoot("root");
|
|
|
|
|
var a = CreateChild(root, "a");
|
|
|
|
|
var b = CreateChild(root, "b");
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
var toc = new AnimationServicesContext();
|
2023-09-17 17:16:27 +08:00
|
|
|
|
toc.OnActivate(CreateContext(root));
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
Assert.AreEqual("a", toc.PathMappings.MapPath("a"));
|
2023-09-17 17:16:27 +08:00
|
|
|
|
a.transform.parent = b.transform;
|
2023-09-30 23:09:43 +08:00
|
|
|
|
toc.PathMappings.ClearCache();
|
|
|
|
|
Assert.AreEqual("b/a", toc.PathMappings.MapPath("a"));
|
2023-09-17 17:16:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TracksCollapses()
|
|
|
|
|
{
|
|
|
|
|
var root = CreateRoot("root");
|
|
|
|
|
var a = CreateChild(root, "a");
|
|
|
|
|
var b = CreateChild(a, "b");
|
|
|
|
|
var c = CreateChild(b, "c");
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
var toc = new AnimationServicesContext();
|
2023-09-17 17:16:27 +08:00
|
|
|
|
toc.OnActivate(CreateContext(root));
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
toc.PathMappings.MarkRemoved(b);
|
2023-09-17 17:16:27 +08:00
|
|
|
|
c.transform.parent = a.transform;
|
|
|
|
|
UnityObject.DestroyImmediate(b);
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
Assert.AreEqual("a/c", toc.PathMappings.MapPath("a/b/c"));
|
2023-09-17 17:16:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TransformLookthrough()
|
|
|
|
|
{
|
|
|
|
|
var root = CreateRoot("root");
|
|
|
|
|
var a = CreateChild(root, "a");
|
|
|
|
|
var b = CreateChild(a, "b");
|
|
|
|
|
var c = CreateChild(b, "c");
|
|
|
|
|
var d = CreateChild(c, "d");
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
var toc = new AnimationServicesContext();
|
2023-09-17 17:16:27 +08:00
|
|
|
|
toc.OnActivate(CreateContext(root));
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
toc.PathMappings.MarkTransformLookthrough(b);
|
|
|
|
|
toc.PathMappings.MarkTransformLookthrough(c);
|
|
|
|
|
Assert.AreEqual("a/b/c", toc.PathMappings.MapPath("a/b/c"));
|
|
|
|
|
Assert.AreEqual("a", toc.PathMappings.MapPath("a/b/c", true));
|
|
|
|
|
Assert.AreEqual("a/b/c/d", toc.PathMappings.MapPath("a/b/c/d", true));
|
2023-09-17 17:16:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
2023-09-17 17:16:27 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestAnimatorControllerUpdates()
|
|
|
|
|
{
|
|
|
|
|
var root = CreatePrefab("BasicObjectReferenceTest.prefab");
|
|
|
|
|
var parent = root.transform.Find("parent").gameObject;
|
|
|
|
|
var child = parent.transform.Find("child").gameObject;
|
|
|
|
|
|
|
|
|
|
var descriptor = root.GetComponent<VRCAvatarDescriptor>();
|
|
|
|
|
var oldFx = descriptor.baseAnimationLayers.First(l =>
|
|
|
|
|
l.type == VRCAvatarDescriptor.AnimLayerType.FX);
|
|
|
|
|
var oldIk = descriptor.specialAnimationLayers.First(l =>
|
|
|
|
|
l.type == VRCAvatarDescriptor.AnimLayerType.IKPose);
|
|
|
|
|
|
2023-09-30 23:09:43 +08:00
|
|
|
|
var toc = new AnimationServicesContext();
|
2023-09-17 17:16:27 +08:00
|
|
|
|
var buildContext = CreateContext(root);
|
|
|
|
|
toc.OnActivate(buildContext);
|
2023-09-30 23:09:43 +08:00
|
|
|
|
toc.PathMappings.MarkTransformLookthrough(child);
|
2023-09-17 17:16:27 +08:00
|
|
|
|
|
|
|
|
|
parent.name = "p2";
|
|
|
|
|
|
|
|
|
|
toc.OnDeactivate(buildContext);
|
|
|
|
|
|
|
|
|
|
var newFx = buildContext.AvatarDescriptor.baseAnimationLayers.First(l =>
|
|
|
|
|
l.type == VRCAvatarDescriptor.AnimLayerType.FX);
|
|
|
|
|
var newIk = buildContext.AvatarDescriptor.specialAnimationLayers.First(l =>
|
|
|
|
|
l.type == VRCAvatarDescriptor.AnimLayerType.IKPose);
|
|
|
|
|
|
|
|
|
|
Assert.AreNotEqual(oldFx.animatorController, newFx.animatorController);
|
|
|
|
|
Assert.AreNotEqual(oldIk.animatorController, newIk.animatorController);
|
|
|
|
|
|
|
|
|
|
CheckClips(newFx.animatorController as AnimatorController);
|
|
|
|
|
CheckClips(newIk.animatorController as AnimatorController);
|
|
|
|
|
|
|
|
|
|
void CheckClips(AnimatorController controller)
|
|
|
|
|
{
|
|
|
|
|
var clip = controller.layers[0].stateMachine.states[0].state.motion
|
|
|
|
|
as AnimationClip;
|
|
|
|
|
|
|
|
|
|
foreach (var binding in AnimationUtility.GetCurveBindings(clip))
|
|
|
|
|
{
|
|
|
|
|
if (binding.type == typeof(Transform))
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual("p2", binding.path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Assert.AreEqual("p2/child", binding.path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-11-10 14:37:56 +08:00
|
|
|
|
#endif
|
2023-09-17 17:16:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|