fix: worldUpObject of AimConstraint and LookAtConstraint is not fixed up

This commit is contained in:
anatawa12 2022-12-09 13:19:15 +09:00 committed by bd_
parent 622ea7d387
commit 27bb7b6312

View File

@ -91,6 +91,22 @@ namespace nadena.dev.modular_avatar.core.editor
}
}
foreach (var c in avatarGameObject.transform.GetComponentsInChildren<AimConstraint>(true))
{
if (!AddedConstraints.Contains(c))
{
FixupAimConstraint(c);
}
}
foreach (var c in avatarGameObject.transform.GetComponentsInChildren<LookAtConstraint>(true))
{
if (!AddedConstraints.Contains(c))
{
FixupLookAtConstraint(c);
}
}
foreach (var bone in ToDelete) UnityEngine.Object.DestroyImmediate(bone);
return true;
@ -119,6 +135,38 @@ namespace nadena.dev.modular_avatar.core.editor
}
}
private void FixupAimConstraint(AimConstraint constraint)
{
if (constraint.worldUpObject == null) return;
if (!BoneRemappings.TryGetValue(constraint.worldUpObject, out var remap)) return;
var retarget = BoneDatabase.GetRetargetedBone(remap);
if (retarget != null)
{
constraint.worldUpObject = retarget;
}
else
{
constraint.worldUpObject = remap;
}
}
private void FixupLookAtConstraint(LookAtConstraint constraint)
{
if (constraint.worldUpObject == null) return;
if (!BoneRemappings.TryGetValue(constraint.worldUpObject, out var remap)) return;
var retarget = BoneDatabase.GetRetargetedBone(remap);
if (retarget != null)
{
constraint.worldUpObject = retarget;
}
else
{
constraint.worldUpObject = remap;
}
}
private void UpdateBoneReferences(Component c, Retargetable retargetable = Retargetable.Disable)
{
SerializedObject so = new SerializedObject(c);