ForceUniqueName before create AvatarDescription

This commit is contained in:
ousttrue
2025-02-12 14:56:20 +09:00
parent be9dde69f4
commit c27c4b6153
4 changed files with 22 additions and 5 deletions

View File

@@ -129,7 +129,7 @@ namespace UniHumanoid
public Avatar CreateAvatar(Transform root)
{
// force unique name
ForceUniqueName.Process(root);
ForceUniqueName.Validate(root);
return AvatarBuilder.BuildHumanAvatar(root.gameObject, ToHumanDescription(root));
}

View File

@@ -9,7 +9,7 @@ namespace UniHumanoid
{
public static Avatar LoadHumanoidAvatar(Transform root, IEnumerable<(Transform, HumanBodyBones)> boneMap)
{
ForceUniqueName.Process(root);
UniGLTF.Utils.ForceUniqueName.Process(root);
var description = new HumanDescription
{

View File

@@ -1,15 +1,32 @@
using System;
using System.Collections.Generic;
using UniGLTF;
using UnityEngine;
namespace UniHumanoid
namespace UniGLTF.Utils
{
class ForceUniqueName
public class ForceUniqueName
{
HashSet<string> m_uniqueNameSet = new HashSet<string>();
int m_counter = 1;
public static bool Validate(Transform root)
{
HashSet<string> uniqueNameSet = new HashSet<string>();
var transforms = root.GetComponentsInChildren<Transform>();
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 ForceUniqueName();