modular-avatar/UnitTests~/GameObjectGC/GameObjectGC.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 System.Linq;
using modular_avatar_tests;
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
public class GameObjectGC : TestBase
{
[Test]
public void FakeHumanoidHandling()
{
var fake_humanoid = CreatePrefab("FakeHumanoid.prefab");
var avdesc = fake_humanoid.GetComponent<VRCAvatarDescriptor>();
new GCGameObjectsPass(new BuildContext(avdesc), fake_humanoid).OnPreprocessAvatar();
AvatarProcessor.ProcessAvatar(fake_humanoid);
var animator = fake_humanoid.GetComponent<Animator>();
Assert.NotNull(animator);
Assert.NotNull(animator.GetBoneTransform(HumanBodyBones.Chest));
Assert.True(fake_humanoid.transform.Find("Body") == null);
}
[Test]
public void RetainEndBones()
{
var fake_humanoid = CreatePrefab("FakeHumanoid.prefab");
var avdesc = fake_humanoid.GetComponent<VRCAvatarDescriptor>();
var bone1 = CreateChild(fake_humanoid, "bone1");
var bone2 = CreateChild(bone1, "bone2.end");
var bone3 = CreateChild(fake_humanoid, "bone2");
new GCGameObjectsPass(new BuildContext(avdesc), fake_humanoid).OnPreprocessAvatar();
AvatarProcessor.ProcessAvatar(fake_humanoid);
Assert.True(bone1 != null);
Assert.True(bone2 != null);
Assert.True(bone3 == null);
}
[Test]
public void RetainArmatureHack()
{
var fake_humanoid = CreatePrefab("FakeHumanoid.prefab");
var avdesc = fake_humanoid.GetComponent<VRCAvatarDescriptor>();
var armature = new GameObject();
armature.name = "Armature";
armature.transform.parent = fake_humanoid.transform;
armature.transform.SetSiblingIndex(0);
new GCGameObjectsPass(new BuildContext(avdesc), fake_humanoid).OnPreprocessAvatar();
AvatarProcessor.ProcessAvatar(fake_humanoid);
Assert.AreEqual(2,
avdesc.GetComponentsInChildren<Transform>().Count(t => t.gameObject.name == "Armature"));
}
}