2023-01-06 22:45:10 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-01-06 22:54:48 +08:00
|
|
|
|
using System.Linq;
|
2023-01-06 22:45:10 +08:00
|
|
|
|
using nadena.dev.modular_avatar.core.editor;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using UnityEditor;
|
2023-01-06 22:54:48 +08:00
|
|
|
|
using UnityEditor.Animations;
|
2023-01-06 22:45:10 +08:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
using VRC.SDK3.Avatars.Components;
|
|
|
|
|
|
|
|
|
|
namespace modular_avatar_tests
|
|
|
|
|
{
|
|
|
|
|
public class TestBase
|
|
|
|
|
{
|
|
|
|
|
private List<GameObject> objects;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void Setup()
|
|
|
|
|
{
|
|
|
|
|
objects = new List<GameObject>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void Teardown()
|
|
|
|
|
{
|
|
|
|
|
foreach (var obj in objects)
|
|
|
|
|
{
|
|
|
|
|
Object.DestroyImmediate(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[OneTimeTearDown]
|
|
|
|
|
void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
Util.DeleteTemporaryAssets();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected GameObject CreateRoot(string name)
|
|
|
|
|
{
|
|
|
|
|
var go = new GameObject(name);
|
|
|
|
|
objects.Add(go);
|
|
|
|
|
// Needed for avatar path finding functions to work properly
|
|
|
|
|
go.AddComponent(typeof(VRCAvatarDescriptor));
|
|
|
|
|
return go;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected GameObject CreateChild(GameObject parent, string name)
|
|
|
|
|
{
|
|
|
|
|
var go = new GameObject(name);
|
|
|
|
|
go.transform.parent = parent.transform;
|
|
|
|
|
objects.Add(go);
|
|
|
|
|
return go;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected GameObject CreatePrefab(string relPath)
|
|
|
|
|
{
|
|
|
|
|
var prefabRoot = "Assets/_ModularAvatar/EditModeTests/" + GetType().Name + "/";
|
|
|
|
|
var prefabPath = prefabRoot + relPath;
|
|
|
|
|
|
|
|
|
|
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
|
|
|
|
|
Assert.NotNull(prefab, "Missing test prefab {0}", prefabPath);
|
|
|
|
|
|
|
|
|
|
var go = Object.Instantiate(prefab);
|
|
|
|
|
objects.Add(go);
|
|
|
|
|
return go;
|
|
|
|
|
}
|
2023-01-06 22:54:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected static AnimationClip findFxMotion(GameObject prefab, string layerName)
|
|
|
|
|
{
|
|
|
|
|
var layer = findFxLayer(prefab, layerName);
|
|
|
|
|
var state = layer.stateMachine.states[0].state;
|
|
|
|
|
Assert.NotNull(state);
|
|
|
|
|
|
|
|
|
|
var motion = state.motion as AnimationClip;
|
|
|
|
|
Assert.NotNull(motion);
|
|
|
|
|
return motion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static AnimatorControllerLayer findFxLayer(GameObject prefab, string layerName)
|
|
|
|
|
{
|
|
|
|
|
var fx = prefab.GetComponent<VRCAvatarDescriptor>().baseAnimationLayers
|
|
|
|
|
.FirstOrDefault(l => l.type == VRCAvatarDescriptor.AnimLayerType.FX);
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(fx);
|
|
|
|
|
var ac = fx.animatorController as AnimatorController;
|
|
|
|
|
Assert.NotNull(ac);
|
|
|
|
|
Assert.False(fx.isDefault);
|
|
|
|
|
|
|
|
|
|
var layer = ac.layers.FirstOrDefault(l => l.name == layerName);
|
|
|
|
|
Assert.NotNull(layer);
|
|
|
|
|
return layer;
|
|
|
|
|
}
|
2023-01-06 22:45:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|