mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-05-24 11:56:58 +08:00
61 lines
2.3 KiB
C#
61 lines
2.3 KiB
C#
using nadena.dev.modular_avatar.core;
|
|
using nadena.dev.modular_avatar.core.editor;
|
|
using NUnit.Framework;
|
|
using NUnit.Framework.Internal;
|
|
using UnityEngine;
|
|
|
|
namespace modular_avatar_tests
|
|
{
|
|
public class BoneProxyTest : TestBase
|
|
{
|
|
[Test]
|
|
public void TestBoneProxy()
|
|
{
|
|
AssertAttachmentMode(BoneProxyAttachmentMode.AsChildAtRoot, expectSnapPos: true, expectSnapRot: true);
|
|
AssertAttachmentMode(BoneProxyAttachmentMode.Unset, expectSnapPos: true, expectSnapRot: true);
|
|
AssertAttachmentMode(BoneProxyAttachmentMode.AsChildKeepPosition, expectSnapPos: false,
|
|
expectSnapRot: true);
|
|
AssertAttachmentMode(BoneProxyAttachmentMode.AsChildKeepRotation, expectSnapPos: true,
|
|
expectSnapRot: false);
|
|
AssertAttachmentMode(BoneProxyAttachmentMode.AsChildKeepWorldPose, expectSnapPos: false,
|
|
expectSnapRot: false);
|
|
}
|
|
|
|
private void AssertAttachmentMode(BoneProxyAttachmentMode attachmentMode, bool expectSnapPos,
|
|
bool expectSnapRot)
|
|
{
|
|
var root = CreateRoot("root");
|
|
var bone = CreateChild(root, "bone");
|
|
var proxy = CreateChild(root, "proxy");
|
|
|
|
var boneProxy = proxy.AddComponent<ModularAvatarBoneProxy>();
|
|
boneProxy.target = bone.transform;
|
|
boneProxy.attachmentMode = attachmentMode;
|
|
|
|
bone.transform.localPosition = Vector3.one;
|
|
bone.transform.localRotation = Quaternion.Euler(123, 45, 6);
|
|
|
|
AvatarProcessor.ProcessAvatar(root);
|
|
|
|
Assert.AreEqual(proxy.transform.parent, bone.transform);
|
|
|
|
if (expectSnapPos)
|
|
{
|
|
Assert.LessOrEqual(Vector3.Distance(proxy.transform.localPosition, Vector3.zero), 0.0001f);
|
|
}
|
|
else
|
|
{
|
|
Assert.LessOrEqual(Vector3.Distance(proxy.transform.position, Vector3.zero), 0.0001f);
|
|
}
|
|
|
|
if (expectSnapRot)
|
|
{
|
|
Assert.LessOrEqual(Quaternion.Angle(proxy.transform.localRotation, Quaternion.identity), 0.0001f);
|
|
}
|
|
else
|
|
{
|
|
Assert.LessOrEqual(Quaternion.Angle(proxy.transform.rotation, Quaternion.identity), 0.0001f);
|
|
}
|
|
}
|
|
}
|
|
} |