modular-avatar/UnitTests~/SyncedLayerHandling/SyncedLayerHandling.cs
kaikoga 3667dc319a
chore: Wrap VRC dependencies and VRCAvatarDescriptors (#504)
* add version defines

* refactor: prefer BuildContext.ctor() overload taking GameObject

* wrap unit tests entirely with MA_VRCSDK3_AVATARS

* wrap unit tests smart with MA_VRCSDK3_AVATARS

* wrap runtime entirely with MA_VRCSDK3_AVATARS

* wrap VRC.SDKBase.IEditorOnly with MA_VRCSDK3_AVATARS

* wrap editor entirely with MA_VRCSDK3_AVATARS

* fix AvatarObjectReference.Get(Component)

* wrap editor smart with MA_VRCSDK3_AVATARS

* wrap BuildContext smart with MA_VRCSDK3_AVATARS

* wrap PluginDefinition smart with MA_VRCSDK3_AVATARS

* style: move conditional compiles one step outside
2023-11-10 15:37:56 +09:00

101 lines
3.5 KiB
C#

#if MA_VRCSDK3_AVATARS
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
using VRC.SDK3.Avatars.Components;
namespace modular_avatar_tests.SyncedLayerHandling
{
public class SyncedLayerHandling : TestBase
{
[Test]
public void WhenSyncedLayerIsOnBaseController_SyncedConfigIsPreserved()
{
var prefab = CreatePrefab("BaseController.prefab");
AvatarProcessor.ProcessAvatar(prefab);
var mainLayer = findFxLayer(prefab, "main");
var syncLayer = findFxLayer(prefab, "sync");
Assert.AreEqual(1, syncLayer.syncedLayerIndex);
var m1State = FindStateInLayer(mainLayer, "m1");
var m2State = FindStateInLayer(mainLayer, "m2");
var m1Override = syncLayer.GetOverrideMotion(m1State);
var m2Override = syncLayer.GetOverrideMotion(m2State);
Assert.True(m1State.motion.name.Contains("m1"));
Assert.True(m2State.motion.name.Contains("m2"));
Assert.True(m1Override.name.Contains("m3"));
Assert.True(m2Override.name.Contains("m4"));
}
[Test]
public void WhenSyncedLayerIsOnMergedController_SyncedConfigIsPreserved()
{
var prefab = CreatePrefab("MergedController.prefab");
AvatarProcessor.ProcessAvatar(prefab);
var mainLayer = findFxLayer(prefab, "main");
var syncLayer = findFxLayer(prefab, "sync");
Assert.AreEqual(2, syncLayer.syncedLayerIndex);
var m1State = FindStateInLayer(mainLayer, "m1");
var m2State = FindStateInLayer(mainLayer, "m2");
var m1Override = syncLayer.GetOverrideMotion(m1State);
var m2Override = syncLayer.GetOverrideMotion(m2State);
Assert.True(m1State.motion.name.Contains("m1"));
Assert.True(m2State.motion.name.Contains("m2"));
Assert.True(m1Override.name.Contains("m3"));
Assert.True(m2Override.name.Contains("m4"));
}
[Test]
public void WhenSyncedLayerIsOnBaseController_LayerControlBehaviorsArePreserved()
{
var prefab = CreatePrefab("BaseController.prefab");
AvatarProcessor.ProcessAvatar(prefab);
var mainLayer = findFxLayer(prefab, "main");
var syncLayer = findFxLayer(prefab, "sync");
Assert.AreEqual(1, syncLayer.syncedLayerIndex);
var m1State = FindStateInLayer(mainLayer, "m1");
var overrides = syncLayer.GetOverrideBehaviours(m1State);
Assert.AreEqual(1, overrides.Length);
var layercontrol = overrides[0] as VRCAnimatorLayerControl;
Assert.NotNull(layercontrol);
Assert.AreEqual(1, layercontrol.layer);
}
[Test]
public void WhenSyncedLayerIsOnMergedController_LayerControlBehaviorsAreAdjusted()
{
var prefab = CreatePrefab("MergedController.prefab");
AvatarProcessor.ProcessAvatar(prefab);
var mainLayer = findFxLayer(prefab, "main");
var syncLayer = findFxLayer(prefab, "sync");
Assert.AreEqual(2, syncLayer.syncedLayerIndex);
var m1State = FindStateInLayer(mainLayer, "m1");
var overrides = syncLayer.GetOverrideBehaviours(m1State);
Assert.AreEqual(1, overrides.Length);
var layercontrol = overrides[0] as VRCAnimatorLayerControl;
Assert.NotNull(layercontrol);
Assert.AreEqual(2, layercontrol.layer);
}
}
}
#endif