From 664a6c3081305b20733eb149f6161a860f7866a6 Mon Sep 17 00:00:00 2001 From: anatawa12 Date: Sat, 10 Dec 2022 14:11:06 +0900 Subject: [PATCH] chore: extract mapping constraint source to one method --- .../Editor/MergeArmatureHook.cs | 46 ++++--------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs b/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs index 0c792dff..e5eae966 100644 --- a/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs +++ b/Packages/nadena.dev.modular-avatar/Editor/MergeArmatureHook.cs @@ -118,53 +118,27 @@ namespace nadena.dev.modular_avatar.core.editor for (int i = 0; i < nSources; i++) { var source = constraint.GetSource(i); - if (source.sourceTransform == null) continue; - if (!BoneRemappings.TryGetValue(source.sourceTransform, out var remap)) continue; - var retarget = BoneDatabase.GetRetargetedBone(remap); - - if (retarget != null) - { - source.sourceTransform = retarget; - } - else - { - source.sourceTransform = remap; - } - + source.sourceTransform = MapConstraintSource(source.sourceTransform); constraint.SetSource(i, source); } } 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; - } + constraint.worldUpObject = MapConstraintSource(constraint.worldUpObject); } private void FixupLookAtConstraint(LookAtConstraint constraint) { - if (constraint.worldUpObject == null) return; - if (!BoneRemappings.TryGetValue(constraint.worldUpObject, out var remap)) return; - var retarget = BoneDatabase.GetRetargetedBone(remap); + constraint.worldUpObject = MapConstraintSource(constraint.worldUpObject); + } - if (retarget != null) - { - constraint.worldUpObject = retarget; - } - else - { - constraint.worldUpObject = remap; - } + private Transform MapConstraintSource(Transform transform) + { + if (transform == null) return null; + if (!BoneRemappings.TryGetValue(transform, out var remap)) return transform; + var retarget = BoneDatabase.GetRetargetedBone(remap); + return retarget != null ? retarget : remap; } private void UpdateBoneReferences(Component c, Retargetable retargetable = Retargetable.Disable)