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

@ -1,18 +1,18 @@
/*
* MIT License
*
*
* Copyright (c) 2022 bd_
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@ -23,6 +23,7 @@
*/
using nadena.dev.modular_avatar.editor.ErrorReporting;
using UnityEditor;
using UnityEngine;
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)
{
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.SetParent(proxy.target, true);

View File

@ -41,6 +41,30 @@ namespace modular_avatar_tests
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,
bool expectSnapRot)
{