fix: name collision issues with World Fixed Object (#525)

Closes: #519
This commit is contained in:
bd_ 2023-11-11 20:29:46 +09:00 committed by GitHub
parent 3667dc319a
commit ed84e22910
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 1 deletions

View File

@ -37,7 +37,7 @@ namespace nadena.dev.modular_avatar.core.editor
);
var proxy = CreateProxy();
var parent = retargeter.CreateIntermediateObjects(proxy.gameObject);
var xform = target.transform;
@ -46,6 +46,11 @@ namespace nadena.dev.modular_avatar.core.editor
var oscale = xform.lossyScale;
xform.localScale = new Vector3(oscale.x / pscale.x, oscale.y / pscale.y, oscale.z / pscale.z);
if (parent.transform.Find(target.gameObject.name) != null)
{
target.gameObject.name = target.gameObject.name + "$" + GUID.Generate();
}
target.transform.SetParent(parent.transform, true);
retargeter.FixupAnimations();

View File

@ -1,5 +1,6 @@
using modular_avatar_tests;
using nadena.dev.modular_avatar.animation;
using nadena.dev.modular_avatar.core;
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
using UnityEngine.Animations;
@ -61,4 +62,25 @@ public class WorldFixedObjectTest : TestBase
Assert.That(nestedFixedObject, Is.Not.Null);
Assert.That(nestedFixedObject, Is.EqualTo(nestedFixed));
}
[Test]
public void NameCollisions()
{
var avatar = CreateRoot("Avatar");
var target1 = CreateChild(avatar, "Target");
var target2 = CreateChild(avatar, "Target");
target1.AddComponent<ModularAvatarWorldFixedObject>();
target2.AddComponent<ModularAvatarWorldFixedObject>();
// initialize context
var buildContext = new BuildContext(avatar);
var animationServices = buildContext.PluginBuildContext.ActivateExtensionContext<AnimationServicesContext>();
new WorldFixedObjectProcessor().Process(buildContext);
Assert.AreSame(target1.transform.parent, target2.transform.parent);
Assert.AreNotSame(target1.transform.parent, avatar.transform);
Assert.AreNotSame(target1.gameObject.name, target2.gameObject.name);
}
}