chore: reduce # of GetComponentsInChildren

This commit is contained in:
anatawa12 2022-12-10 14:14:52 +09:00 committed by bd_
parent 664a6c3081
commit 42d83304ab

View File

@ -91,22 +91,6 @@ 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); foreach (var bone in ToDelete) UnityEngine.Object.DestroyImmediate(bone);
return true; return true;
@ -121,16 +105,16 @@ namespace nadena.dev.modular_avatar.core.editor
source.sourceTransform = MapConstraintSource(source.sourceTransform); source.sourceTransform = MapConstraintSource(source.sourceTransform);
constraint.SetSource(i, source); constraint.SetSource(i, source);
} }
}
private void FixupAimConstraint(AimConstraint constraint) if (constraint is AimConstraint aimConstraint)
{ {
constraint.worldUpObject = MapConstraintSource(constraint.worldUpObject); aimConstraint.worldUpObject = MapConstraintSource(aimConstraint.worldUpObject);
} }
private void FixupLookAtConstraint(LookAtConstraint constraint) if (constraint is LookAtConstraint lookAtConstraint)
{ {
constraint.worldUpObject = MapConstraintSource(constraint.worldUpObject); lookAtConstraint.worldUpObject = MapConstraintSource(lookAtConstraint.worldUpObject);
}
} }
private Transform MapConstraintSource(Transform transform) private Transform MapConstraintSource(Transform transform)