fix: name collisions with Bone Proxies break animation mappings (#542)

Closes: #540
This commit is contained in:
bd_ 2023-11-26 20:48:16 +09:00 committed by GitHub
parent 7b309f391b
commit 1dacdc4b37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 5 deletions

View File

@ -23,6 +23,7 @@
*/ */
using nadena.dev.modular_avatar.editor.ErrorReporting; using nadena.dev.modular_avatar.editor.ErrorReporting;
using UnityEditor;
using UnityEngine; using UnityEngine;
namespace nadena.dev.modular_avatar.core.editor namespace nadena.dev.modular_avatar.core.editor
@ -50,7 +51,15 @@ namespace nadena.dev.modular_avatar.core.editor
{ {
if (proxy.target != null && ValidateTarget(avatarGameObject, proxy.target) == ValidationResult.OK) if (proxy.target != null && ValidateTarget(avatarGameObject, proxy.target) == ValidationResult.OK)
{ {
var oldPath = RuntimeUtil.AvatarRootPath(proxy.gameObject); string suffix = "";
int i = 1;
while (proxy.target.Find(proxy.gameObject.name + suffix) != null)
{
suffix = $" ({i++})";
}
proxy.gameObject.name += suffix;
Transform transform = proxy.transform; Transform transform = proxy.transform;
transform.SetParent(proxy.target, true); transform.SetParent(proxy.target, true);

View File

@ -41,6 +41,30 @@ namespace modular_avatar_tests
Assert.IsNull(boneProxy.target); Assert.IsNull(boneProxy.target);
} }
[Test]
public void TestNameCollision()
{
var root = CreateRoot("root");
var target = CreateChild(root, "target");
var src1 = CreateChild(root, "src1");
var src_child1 = CreateChild(src1, "child");
var src2 = CreateChild(root, "src2");
var src_child2 = CreateChild(src2, "child");
var bp1 = src_child1.AddComponent<ModularAvatarBoneProxy>();
bp1.target = target.transform;
var bp2 = src_child2.AddComponent<ModularAvatarBoneProxy>();
bp2.target = target.transform;
bp1.ClearCache(true);
bp2.ClearCache(true);
new BoneProxyProcessor().OnPreprocessAvatar(root);
Assert.AreNotEqual(src_child1.name, src_child2.name);
}
private void AssertAttachmentMode(BoneProxyAttachmentMode attachmentMode, bool expectSnapPos, private void AssertAttachmentMode(BoneProxyAttachmentMode attachmentMode, bool expectSnapPos,
bool expectSnapRot) bool expectSnapRot)
{ {