modular-avatar/UnitTests~/ArmatureConfusion/ArmatureConfusionTest.cs
bd_ ddbc3b164b
chore: restructure repository to put package at top-level (#477)
* chore: rearrange package structure to have the package at the root

* ci: update CI workflows

* ci: fixing workflow bugs

* ci: recurse building .zip package

* ci: more fixes

* ci: add back in the nadena.dev VPM repo

* ci: fix tests
2023-10-08 15:39:57 +09:00

60 lines
2.0 KiB
C#

using modular_avatar_tests;
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
using UnityEditor;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
using UnityObject = UnityEngine.Object;
public class ArmatureConfusionTest : TestBase
{
[TearDown]
public void TearDown()
{
ESOErrorWindow.Suppress = false;
}
[Test]
public void TestArmatureConfusionWorkaround()
{
ESOErrorWindow.Suppress = true;
// Arrange for a confused armature
var outer = CreatePrefab("shapell.fbx");
var inner = CreatePrefab("shapell.fbx");
var outerAnimator = outer.GetComponent<Animator>();
outer.AddComponent<VRCAvatarDescriptor>();
inner.gameObject.name = "inner";
inner.transform.parent = outer.transform;
// Unity seems to determine which armature is the "true" armature by counting the number of bones that match
// the humanoid description, and finding the root which has the most matches. Let's confuse it a bit by removing
// some non-humanoid bones from the outer armature.
var outerTarget = outer.transform.Find("Armature/Hips/Tail");
UnityObject.DestroyImmediate(outerTarget.gameObject);
// Clear animator cache
var avatar = outerAnimator.avatar;
outerAnimator.avatar = null;
// ReSharper disable once Unity.InefficientPropertyAccess
outerAnimator.avatar = avatar;
// Verify that we're well and confused now
Assert.AreSame(
outerAnimator.GetBoneTransform(HumanBodyBones.Hips),
inner.transform.Find("Armature/Hips")
);
// Now do a setup outfit operation
Selection.activeGameObject = inner;
EasySetupOutfit.SetupOutfit(new MenuCommand(inner));
// Verify that we're not confused anymore
Assert.AreSame(
outerAnimator.GetBoneTransform(HumanBodyBones.Hips),
outer.transform.Find("Armature/Hips")
);
}
}