mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-08-27 05:14:27 -05:00
ForceUniqueName before create AvatarDescription
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
Reference in New Issue
Block a user