Merge pull request #2580 from ousttrue/fix/ForceUniqueName_timing

[Vrma] ForceUniqueName before create AvatarDescription
This commit is contained in:
ousttrue
2025-02-12 15:24:05 +09:00
committed by GitHub
4 changed files with 23 additions and 6 deletions

View File

@@ -129,7 +129,7 @@ namespace UniHumanoid
public Avatar CreateAvatar(Transform root)
{
// force unique name
ForceUniqueName.Process(root);
ForceTransformUniqueName.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.ForceTransformUniqueName.Process(root);
var description = new HumanDescription
{

View File

@@ -1,18 +1,35 @@
using System;
using System.Collections.Generic;
using UniGLTF;
using UnityEngine;
namespace UniHumanoid
namespace UniGLTF.Utils
{
class ForceUniqueName
public class ForceTransformUniqueName
{
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();
var uniqueName = new ForceTransformUniqueName();
var transforms = root.GetComponentsInChildren<Transform>();
foreach (var t in transforms)
{