2023-01-06 22:45:10 +08:00
|
|
|
|
using System.Collections.Generic;
|
2023-09-17 17:16:27 +08:00
|
|
|
|
using System.IO;
|
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;
|
2023-07-30 01:22:37 +08:00
|
|
|
|
using nadena.dev.modular_avatar.editor.ErrorReporting;
|
2023-01-06 22:45:10 +08:00
|
|
|
|
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
|
|
|
|
|
{
|
2023-09-17 17:16:27 +08:00
|
|
|
|
private const string TEMP_ASSET_PATH = "Assets/ZZZ_Temp";
|
|
|
|
|
private static Dictionary<System.Type, string> _scriptToDirectory = null;
|
|
|
|
|
|
2023-01-06 22:45:10 +08:00
|
|
|
|
private List<GameObject> objects;
|
2023-01-17 19:26:56 +08:00
|
|
|
|
private const string MinimalAvatarGuid = "60d3416d1f6af4a47bf9056aefc38333";
|
2023-01-06 22:45:10 +08:00
|
|
|
|
|
|
|
|
|
[SetUp]
|
2023-02-25 15:45:24 +08:00
|
|
|
|
public virtual void Setup()
|
2023-01-06 22:45:10 +08:00
|
|
|
|
{
|
2023-09-17 17:16:27 +08:00
|
|
|
|
if (_scriptToDirectory == null)
|
|
|
|
|
{
|
|
|
|
|
_scriptToDirectory = new Dictionary<System.Type, string>();
|
|
|
|
|
foreach (var guid in AssetDatabase.FindAssets("t:MonoScript", new string[] {"Assets/_ModularAvatar"}))
|
|
|
|
|
{
|
|
|
|
|
var path = AssetDatabase.GUIDToAssetPath(guid);
|
|
|
|
|
var obj = AssetDatabase.LoadAssetAtPath<MonoScript>(path);
|
|
|
|
|
if (obj != null && obj.GetClass() != null)
|
|
|
|
|
{
|
|
|
|
|
_scriptToDirectory.Add(obj.GetClass(), Path.GetDirectoryName(path));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-30 01:22:37 +08:00
|
|
|
|
BuildReport.Clear();
|
2023-01-06 22:45:10 +08:00
|
|
|
|
objects = new List<GameObject>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
2023-02-25 15:45:24 +08:00
|
|
|
|
public virtual void Teardown()
|
2023-01-06 22:45:10 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (var obj in objects)
|
|
|
|
|
{
|
|
|
|
|
Object.DestroyImmediate(obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Util.DeleteTemporaryAssets();
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-17 17:16:27 +08:00
|
|
|
|
protected nadena.dev.ndmf.BuildContext CreateContext(GameObject root)
|
|
|
|
|
{
|
|
|
|
|
return new nadena.dev.ndmf.BuildContext(root, TEMP_ASSET_PATH); // TODO - cleanup
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 22:45:10 +08:00
|
|
|
|
protected GameObject CreateRoot(string name)
|
|
|
|
|
{
|
2023-01-17 19:26:56 +08:00
|
|
|
|
var path = AssetDatabase.GUIDToAssetPath(MinimalAvatarGuid);
|
|
|
|
|
var go = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath<GameObject>(path));
|
|
|
|
|
|
2023-01-06 22:45:10 +08:00
|
|
|
|
objects.Add(go);
|
|
|
|
|
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)
|
|
|
|
|
{
|
2023-05-23 20:10:22 +08:00
|
|
|
|
var prefab = LoadAsset<GameObject>(relPath);
|
2023-01-06 22:45:10 +08:00
|
|
|
|
|
|
|
|
|
var go = Object.Instantiate(prefab);
|
|
|
|
|
objects.Add(go);
|
|
|
|
|
return go;
|
|
|
|
|
}
|
2023-01-06 22:54:48 +08:00
|
|
|
|
|
2023-09-17 17:16:27 +08:00
|
|
|
|
|
2023-05-23 20:10:22 +08:00
|
|
|
|
protected T LoadAsset<T>(string relPath) where T : UnityEngine.Object
|
|
|
|
|
{
|
2023-09-17 17:16:27 +08:00
|
|
|
|
var root = _scriptToDirectory[GetType()] + "/";
|
2023-05-23 20:10:22 +08:00
|
|
|
|
var path = root + relPath;
|
|
|
|
|
|
|
|
|
|
var obj = AssetDatabase.LoadAssetAtPath<T>(path);
|
|
|
|
|
Assert.NotNull(obj, "Missing test asset {0}", path);
|
|
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-25 14:29:00 +08:00
|
|
|
|
protected static AnimationClip findFxClip(GameObject prefab, string layerName)
|
|
|
|
|
{
|
|
|
|
|
var motion = findFxMotion(prefab, layerName) as AnimationClip;
|
|
|
|
|
Assert.NotNull(motion);
|
|
|
|
|
return motion;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected static Motion findFxMotion(GameObject prefab, string layerName)
|
2023-01-06 22:54:48 +08:00
|
|
|
|
{
|
|
|
|
|
var layer = findFxLayer(prefab, layerName);
|
|
|
|
|
var state = layer.stateMachine.states[0].state;
|
|
|
|
|
Assert.NotNull(state);
|
|
|
|
|
|
2023-03-25 14:29:00 +08:00
|
|
|
|
return state.motion;
|
2023-01-06 22:54:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-27 20:14:20 +08:00
|
|
|
|
protected static AnimatorState FindStateInLayer(AnimatorControllerLayer layer, string stateName)
|
|
|
|
|
{
|
|
|
|
|
foreach (var state in layer.stateMachine.states)
|
|
|
|
|
{
|
|
|
|
|
if (state.state.name == stateName) return state.state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 22:54:48 +08:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|