2023-09-24 15:59:02 +08:00
|
|
|
using modular_avatar_tests;
|
|
|
|
using nadena.dev.modular_avatar.animation;
|
2023-11-11 19:29:46 +08:00
|
|
|
using nadena.dev.modular_avatar.core;
|
2023-09-24 15:59:02 +08:00
|
|
|
using nadena.dev.modular_avatar.core.editor;
|
|
|
|
using NUnit.Framework;
|
2024-11-17 11:02:09 +08:00
|
|
|
using UnityEngine;
|
2023-09-24 15:59:02 +08:00
|
|
|
using UnityEngine.Animations;
|
|
|
|
|
|
|
|
public class WorldFixedObjectTest : TestBase
|
|
|
|
{
|
|
|
|
[Test]
|
|
|
|
public void SimpleTest()
|
|
|
|
{
|
|
|
|
var avatar = CreatePrefab("Simple.prefab");
|
|
|
|
|
|
|
|
var fixedObject = avatar.transform.Find("FixedObject");
|
2023-09-30 23:09:43 +08:00
|
|
|
|
2023-09-24 15:59:02 +08:00
|
|
|
// initialize context
|
2023-11-10 14:37:56 +08:00
|
|
|
var buildContext = new BuildContext(avatar);
|
2023-09-30 23:09:43 +08:00
|
|
|
buildContext.PluginBuildContext.ActivateExtensionContext<AnimationServicesContext>();
|
2023-09-24 15:59:02 +08:00
|
|
|
|
2023-10-15 17:44:53 +08:00
|
|
|
new WorldFixedObjectProcessor().Process(buildContext);
|
2023-09-24 15:59:02 +08:00
|
|
|
|
|
|
|
var fixedRoot = avatar.transform.Find("(MA WorldFixedRoot)");
|
|
|
|
var movedFixedObject = avatar.transform.Find("(MA WorldFixedRoot)/FixedObject");
|
|
|
|
|
|
|
|
// fixed root is created
|
|
|
|
Assert.That(fixedRoot, Is.Not.Null);
|
2024-11-17 11:02:09 +08:00
|
|
|
bool isVrcAvatar = false;
|
|
|
|
System.Type vrcParentConstraintType = null;
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
|
|
|
isVrcAvatar = avatar.TryGetComponent(out VRC.SDKBase.VRC_AvatarDescriptor _);
|
|
|
|
vrcParentConstraintType = System.Type.GetType("VRC.SDK3.Dynamics.Constraint.Components.VRCParentConstraint, VRC.SDK3.Dynamics.Constraint");
|
|
|
|
#endif
|
|
|
|
Component constraint = isVrcAvatar && vrcParentConstraintType != null ?
|
|
|
|
fixedRoot.GetComponent(vrcParentConstraintType) :
|
|
|
|
fixedRoot.GetComponent<ParentConstraint>();
|
|
|
|
Assert.That(constraint, Is.Not.Null);
|
2023-09-24 15:59:02 +08:00
|
|
|
|
|
|
|
// objects are moved to fixed root
|
|
|
|
Assert.That(movedFixedObject, Is.Not.Null);
|
|
|
|
Assert.That(movedFixedObject, Is.EqualTo(fixedObject));
|
|
|
|
}
|
2023-09-30 23:09:43 +08:00
|
|
|
|
2023-09-24 15:59:02 +08:00
|
|
|
[Test]
|
|
|
|
public void NestedTest()
|
|
|
|
{
|
|
|
|
var avatar = CreatePrefab("Nested.prefab");
|
|
|
|
|
|
|
|
var fixedObject = avatar.transform.Find("FixedObject");
|
|
|
|
var nestedFixed = avatar.transform.Find("FixedObject/NestedFixed");
|
2023-09-30 23:09:43 +08:00
|
|
|
|
2023-09-24 15:59:02 +08:00
|
|
|
// initialize context
|
2023-11-10 14:37:56 +08:00
|
|
|
var buildContext = new BuildContext(avatar);
|
2023-09-30 23:09:43 +08:00
|
|
|
buildContext.PluginBuildContext.ActivateExtensionContext<AnimationServicesContext>();
|
2023-09-24 15:59:02 +08:00
|
|
|
|
2023-10-15 17:44:53 +08:00
|
|
|
new WorldFixedObjectProcessor().Process(buildContext);
|
2023-09-24 15:59:02 +08:00
|
|
|
|
|
|
|
var fixedRoot = avatar.transform.Find("(MA WorldFixedRoot)");
|
|
|
|
var movedFixedObject = avatar.transform.Find("(MA WorldFixedRoot)/FixedObject");
|
|
|
|
var nestedFixedObject = avatar.transform.Find("(MA WorldFixedRoot)/NestedFixed");
|
|
|
|
|
|
|
|
// fixed root is created
|
|
|
|
Assert.That(fixedRoot, Is.Not.Null);
|
2024-11-17 11:02:09 +08:00
|
|
|
bool isVrcAvatar = false;
|
|
|
|
System.Type vrcParentConstraintType = null;
|
|
|
|
#if MA_VRCSDK3_AVATARS
|
|
|
|
isVrcAvatar = avatar.TryGetComponent(out VRC.SDKBase.VRC_AvatarDescriptor _);
|
|
|
|
vrcParentConstraintType = System.Type.GetType("VRC.SDK3.Dynamics.Constraint.Components.VRCParentConstraint, VRC.SDK3.Dynamics.Constraint");
|
|
|
|
#endif
|
|
|
|
Component constraint = isVrcAvatar && vrcParentConstraintType != null ?
|
|
|
|
fixedRoot.GetComponent(vrcParentConstraintType) :
|
|
|
|
fixedRoot.GetComponent<ParentConstraint>();
|
|
|
|
Assert.That(constraint, Is.Not.Null);
|
2023-09-24 15:59:02 +08:00
|
|
|
|
|
|
|
// objects are moved to fixed root
|
|
|
|
Assert.That(movedFixedObject, Is.Not.Null);
|
|
|
|
Assert.That(movedFixedObject, Is.EqualTo(fixedObject));
|
|
|
|
|
|
|
|
// objects are moved to fixed root
|
|
|
|
Assert.That(nestedFixedObject, Is.Not.Null);
|
|
|
|
Assert.That(nestedFixedObject, Is.EqualTo(nestedFixed));
|
|
|
|
}
|
2023-11-11 19:29:46 +08:00
|
|
|
|
|
|
|
[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);
|
|
|
|
}
|
2023-09-30 23:09:43 +08:00
|
|
|
}
|