mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2024-12-29 02:35:06 +08:00
fix: keep position/keep rotation modes not applied in editor
This commit is contained in:
parent
231ae585bb
commit
55827868f9
@ -44,6 +44,52 @@ namespace modular_avatar_tests
|
||||
|
||||
private void AssertAttachmentMode(BoneProxyAttachmentMode attachmentMode, bool expectSnapPos,
|
||||
bool expectSnapRot)
|
||||
{
|
||||
AssertAttachmentModeAtBuild(attachmentMode, expectSnapPos, expectSnapRot);
|
||||
AssertAttachmentModeInEditor(attachmentMode, expectSnapPos, expectSnapRot);
|
||||
}
|
||||
|
||||
private void AssertAttachmentModeInEditor(BoneProxyAttachmentMode attachmentMode, bool expectSnapPos,
|
||||
bool expectSnapRot)
|
||||
{
|
||||
// Unset gets converted in the custom inspector; until it is, we don't snap (since we need to know the
|
||||
// position to heuristically set the snapping mode).
|
||||
if (attachmentMode == BoneProxyAttachmentMode.Unset) return;
|
||||
|
||||
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);
|
||||
|
||||
boneProxy.Update();
|
||||
|
||||
if (expectSnapPos)
|
||||
{
|
||||
Assert.LessOrEqual(Vector3.Distance(proxy.transform.position, bone.transform.position), 0.0001f);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.GreaterOrEqual(Vector3.Distance(proxy.transform.position, bone.transform.position), 0.0001f);
|
||||
}
|
||||
|
||||
if (expectSnapRot)
|
||||
{
|
||||
Assert.LessOrEqual(Quaternion.Angle(proxy.transform.rotation, bone.transform.rotation), 0.0001f);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.GreaterOrEqual(Quaternion.Angle(proxy.transform.rotation, bone.transform.rotation), 0.0001f);
|
||||
}
|
||||
}
|
||||
|
||||
private void AssertAttachmentModeAtBuild(BoneProxyAttachmentMode attachmentMode, bool expectSnapPos,
|
||||
bool expectSnapRot)
|
||||
{
|
||||
var root = CreateRoot("root");
|
||||
var bone = CreateChild(root, "bone");
|
||||
|
@ -106,14 +106,25 @@ namespace nadena.dev.modular_avatar.core
|
||||
RuntimeUtil.OnHierarchyChanged -= ClearCache;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
internal void Update()
|
||||
{
|
||||
if (!RuntimeUtil.isPlaying && target != null && attachmentMode == BoneProxyAttachmentMode.AsChildAtRoot)
|
||||
if (!RuntimeUtil.isPlaying && target != null)
|
||||
{
|
||||
var targetTransform = target.transform;
|
||||
var myTransform = transform;
|
||||
myTransform.position = targetTransform.position;
|
||||
myTransform.rotation = targetTransform.rotation;
|
||||
switch (attachmentMode)
|
||||
{
|
||||
case BoneProxyAttachmentMode.AsChildAtRoot:
|
||||
myTransform.position = targetTransform.position;
|
||||
myTransform.rotation = targetTransform.rotation;
|
||||
break;
|
||||
case BoneProxyAttachmentMode.AsChildKeepPosition:
|
||||
myTransform.rotation = targetTransform.rotation;
|
||||
break;
|
||||
case BoneProxyAttachmentMode.AsChildKeepRotation:
|
||||
myTransform.position = targetTransform.position;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user