mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2024-12-29 02:35:06 +08:00
fix: name collisions with Bone Proxies break animation mappings (#542)
Closes: #540
This commit is contained in:
parent
7b309f391b
commit
1dacdc4b37
@ -1,18 +1,18 @@
|
|||||||
/*
|
/*
|
||||||
* MIT License
|
* MIT License
|
||||||
*
|
*
|
||||||
* Copyright (c) 2022 bd_
|
* Copyright (c) 2022 bd_
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
* copies or substantial portions of the Software.
|
* copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -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);
|
||||||
|
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user