2023-09-15 20:00:08 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using modular_avatar_tests;
|
2023-05-21 15:49:02 +08:00
|
|
|
|
using nadena.dev.modular_avatar.core.editor;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class GameObjectGC : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void FakeHumanoidHandling()
|
|
|
|
|
{
|
|
|
|
|
var fake_humanoid = CreatePrefab("FakeHumanoid.prefab");
|
2023-11-10 14:37:56 +08:00
|
|
|
|
var context = new BuildContext(fake_humanoid);
|
2023-05-21 15:49:02 +08:00
|
|
|
|
|
2023-11-10 14:37:56 +08:00
|
|
|
|
new GCGameObjectsPass(context, fake_humanoid).OnPreprocessAvatar();
|
2023-05-21 15:49:02 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
2023-06-19 19:11:18 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void RetainEndBones()
|
|
|
|
|
{
|
|
|
|
|
var fake_humanoid = CreatePrefab("FakeHumanoid.prefab");
|
2023-11-10 14:37:56 +08:00
|
|
|
|
var context = new BuildContext(fake_humanoid);
|
2023-06-19 19:11:18 +08:00
|
|
|
|
|
|
|
|
|
var bone1 = CreateChild(fake_humanoid, "bone1");
|
|
|
|
|
var bone2 = CreateChild(bone1, "bone2.end");
|
|
|
|
|
var bone3 = CreateChild(fake_humanoid, "bone2");
|
|
|
|
|
|
2023-11-10 14:37:56 +08:00
|
|
|
|
new GCGameObjectsPass(context, fake_humanoid).OnPreprocessAvatar();
|
2023-06-19 19:11:18 +08:00
|
|
|
|
AvatarProcessor.ProcessAvatar(fake_humanoid);
|
|
|
|
|
|
|
|
|
|
Assert.True(bone1 != null);
|
|
|
|
|
Assert.True(bone2 != null);
|
|
|
|
|
Assert.True(bone3 == null);
|
|
|
|
|
}
|
2023-09-15 20:00:08 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void RetainArmatureHack()
|
|
|
|
|
{
|
|
|
|
|
var fake_humanoid = CreatePrefab("FakeHumanoid.prefab");
|
2023-11-10 14:37:56 +08:00
|
|
|
|
var context = new BuildContext(fake_humanoid);
|
2023-09-15 20:00:08 +08:00
|
|
|
|
|
|
|
|
|
var armature = new GameObject();
|
|
|
|
|
armature.name = "Armature";
|
|
|
|
|
armature.transform.parent = fake_humanoid.transform;
|
|
|
|
|
armature.transform.SetSiblingIndex(0);
|
|
|
|
|
|
2023-11-10 14:37:56 +08:00
|
|
|
|
new GCGameObjectsPass(context, fake_humanoid).OnPreprocessAvatar();
|
2023-09-15 20:00:08 +08:00
|
|
|
|
AvatarProcessor.ProcessAvatar(fake_humanoid);
|
|
|
|
|
|
|
|
|
|
Assert.AreEqual(2,
|
2023-11-10 14:37:56 +08:00
|
|
|
|
context.AvatarRootObject.GetComponentsInChildren<Transform>().Count(t => t.gameObject.name == "Armature"));
|
2023-09-15 20:00:08 +08:00
|
|
|
|
}
|
2023-05-21 15:49:02 +08:00
|
|
|
|
}
|