diff --git a/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs b/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs index bc0078197..d2bbae906 100644 --- a/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs +++ b/Assets/UniGLTF/Runtime/UniHumanoid/AvatarDescription.cs @@ -91,8 +91,13 @@ namespace UniHumanoid public bool hasTranslationDoF; public BoneLimit[] human; - public HumanDescription ToHumanDescription(Transform root) + public HumanDescription ToHumanDescription(Transform root, bool forceRename) { + if (forceRename) + { + ForceTransformUniqueName.Process(root); + } + var transforms = root.GetComponentsInChildren(); var skeletonBones = new SkeletonBone[transforms.Length]; var index = 0; @@ -128,9 +133,7 @@ namespace UniHumanoid public Avatar CreateAvatar(Transform root) { - // force unique name - ForceTransformUniqueName.Validate(root); - return AvatarBuilder.BuildHumanAvatar(root.gameObject, ToHumanDescription(root)); + return AvatarBuilder.BuildHumanAvatar(root.gameObject, ToHumanDescription(root, true)); } public Avatar CreateAvatarAndSetup(Transform root) diff --git a/Assets/UniGLTF/Runtime/Utils/ForceTransformUniqueName.cs b/Assets/UniGLTF/Runtime/Utils/ForceTransformUniqueName.cs index 31e184f58..d3832b0f9 100644 --- a/Assets/UniGLTF/Runtime/Utils/ForceTransformUniqueName.cs +++ b/Assets/UniGLTF/Runtime/Utils/ForceTransformUniqueName.cs @@ -9,24 +9,6 @@ namespace UniGLTF.Utils HashSet m_uniqueNameSet = new HashSet(); int m_counter = 1; - public static bool Validate(Transform root) - { - HashSet uniqueNameSet = new HashSet(); - var transforms = root.GetComponentsInChildren(); - foreach (var t in transforms) - { - if (uniqueNameSet.Contains(t.name)) - { - UniGLTFLogger.Warning($"duplicate name: {t.name}"); - } - else - { - uniqueNameSet.Add(t.name); - } - } - return uniqueNameSet.Count == transforms.Length; - } - public static void Process(Transform root) { var uniqueName = new ForceTransformUniqueName(); @@ -37,6 +19,13 @@ namespace UniGLTF.Utils } } + private void DoRename(Transform t, string newName) + { + UniGLTFLogger.Warning($"force rename !!: {t.name} => {newName}"); + t.name = newName; + m_uniqueNameSet.Add(newName); + } + public void RenameIfDupName(Transform t) { if (!m_uniqueNameSet.Contains(t.name)) @@ -58,9 +47,7 @@ namespace UniGLTF.Utils var newName = $"{t.parent.name}-{t.name}"; if (!m_uniqueNameSet.Contains(newName)) { - UniGLTFLogger.Warning($"force rename !!: {t.name} => {newName}"); - t.name = newName; - m_uniqueNameSet.Add(newName); + DoRename(t, newName); return; } } @@ -72,9 +59,7 @@ namespace UniGLTF.Utils var newName = $"{t.name}{m_counter++}"; if (!m_uniqueNameSet.Contains(newName)) { - UniGLTFLogger.Warning($"force rename: {t.name} => {newName}", t); - t.name = newName; - m_uniqueNameSet.Add(newName); + DoRename(t, newName); return; } }