diff --git a/Editor/HeuristicBoneMapper.cs b/Editor/HeuristicBoneMapper.cs index cb89ed20..83d63c69 100644 --- a/Editor/HeuristicBoneMapper.cs +++ b/Editor/HeuristicBoneMapper.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Collections.Immutable; +using System.Linq; using System.Text.RegularExpressions; using UnityEditor; using UnityEngine; @@ -236,13 +237,13 @@ namespace nadena.dev.modular_avatar.core.editor return PAT_END_NUMBER.Replace(name, ""); } - internal static readonly ImmutableDictionary NameToBoneMap; + internal static readonly ImmutableDictionary> NameToBoneMap; internal static readonly ImmutableDictionary> BoneToNameMap; static HeuristicBoneMapper() { var pat_end_side = new Regex(@"[_\.]([LR])$"); - var nameToBoneMap = new Dictionary(); + var nameToBoneMap = new Dictionary>(); var boneToNameMap = new Dictionary>(); for (int i = 0; i < boneNamePatterns.Length; i++) @@ -263,7 +264,13 @@ namespace nadena.dev.modular_avatar.core.editor void RegisterNameForBone(string name, HumanBodyBones bone) { - nameToBoneMap[name] = bone; + if (!nameToBoneMap.TryGetValue(name, out var list)) + { + list = new List(); + nameToBoneMap[name] = list; + } + list.Add(bone); + if (!boneToNameMap.TryGetValue(bone, out var names)) { names = ImmutableList.Empty; @@ -334,12 +341,12 @@ namespace nadena.dev.modular_avatar.core.editor childName.Length - config.prefix.Length - config.suffix.Length); if (!NameToBoneMap.TryGetValue( - NormalizeName(targetObjectName.ToLowerInvariant()), out var bodyBone)) + NormalizeName(targetObjectName.ToLowerInvariant()), out var bodyBones)) { continue; } - foreach (var otherName in BoneToNameMap[bodyBone]) + foreach (var otherName in bodyBones.SelectMany(bone => BoneToNameMap[bone])) { if (lcNameToXform.TryGetValue(otherName, out var targetObject)) {