modular-avatar/UnitTests~/SerializationTests/SerializationTests.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

71 lines
2.5 KiB
C#

#if MA_VRCSDK3_AVATARS
using System.Linq;
using modular_avatar_tests;
using nadena.dev.ndmf.runtime;
using nadena.dev.modular_avatar.core;
using nadena.dev.modular_avatar.core.editor;
using NUnit.Framework;
using UnityEditor;
using UnityEditor.Animations;
using UnityEngine;
using VRC.SDK3.Avatars.Components;
namespace _ModularAvatar.EditModeTests.SerializationTests
{
public class SerializationTests : TestBase
{
[Test]
public void SerializationSavesAssetsRecursively()
{
var avatar = CreatePrefab("TestSerializationTraversal.prefab");
var originalAnimController = avatar.GetComponent<VRCAvatarDescriptor>().baseAnimationLayers
.First(l => l.animatorController != null)
.animatorController as AnimatorController;
AvatarProcessor.ProcessAvatar(avatar);
var avdesc = avatar.GetComponent<VRCAvatarDescriptor>();
var animController = avdesc.baseAnimationLayers
.First(l => l.animatorController != null)
.animatorController as AnimatorController;
Assert.AreNotEqual(originalAnimController, animController);
Assert.False(string.IsNullOrEmpty(AssetDatabase.GetAssetPath(animController)));
AssertTempAsset(animController);
var stateMachine = animController.layers[0].stateMachine;
AssertTempAsset(stateMachine);
var state = stateMachine.states[0].state;
AssertTempAsset(state);
// We might eventually optimize away rewriting clips that don't need changes, so just assert that they're
// saved
var blendTree = state.motion as BlendTree;
Assert.IsFalse(string.IsNullOrEmpty(AssetDatabase.GetAssetPath(blendTree)));
var clip = blendTree.children[0].motion as AnimationClip;
Assert.IsFalse(string.IsNullOrEmpty(AssetDatabase.GetAssetPath(clip)));
// Validate that the menu is saved
var menu = avdesc.expressionsMenu;
AssertTempAsset(menu);
AssertTempAsset(menu.controls[0].subMenu);
var parameters = avdesc.expressionParameters;
AssertTempAsset(parameters);
}
void AssertTempAsset(UnityEngine.Object obj)
{
var path = AssetDatabase.GetAssetPath(obj);
Assert.False(string.IsNullOrEmpty(path));
var mainAsset = AssetDatabase.LoadMainAssetAtPath(path);
Assert.IsInstanceOf<GeneratedAssets>(mainAsset);
}
}
}
#endif