mirror of
https://github.com/bdunderscore/modular-avatar.git
synced 2025-01-20 13:20:06 +08:00
108 lines
3.1 KiB
C#
108 lines
3.1 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.IO;
|
|||
|
using nadena.dev.modular_avatar.core.editor;
|
|||
|
using NUnit.Framework;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.TestTools;
|
|||
|
using VRC.SDK3.Avatars.Components;
|
|||
|
|
|||
|
namespace modular_avatar_tests
|
|||
|
{
|
|||
|
public class PathMappingTest
|
|||
|
{
|
|||
|
private List<GameObject> objects;
|
|||
|
|
|||
|
[SetUp]
|
|||
|
public void Setup()
|
|||
|
{
|
|||
|
objects = new List<GameObject>();
|
|||
|
}
|
|||
|
|
|||
|
[TearDown]
|
|||
|
public void Teardown()
|
|||
|
{
|
|||
|
foreach (var obj in objects)
|
|||
|
{
|
|||
|
Object.DestroyImmediate(obj);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
|
|||
|
GameObject CreateChild(GameObject parent, string name)
|
|||
|
{
|
|||
|
var go = new GameObject(name);
|
|||
|
go.transform.parent = parent.transform;
|
|||
|
objects.Add(go);
|
|||
|
return go;
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void TracksSimpleRenames()
|
|||
|
{
|
|||
|
var root = CreateRoot("root");
|
|||
|
var a = CreateChild(root, "a");
|
|||
|
|
|||
|
PathMappings.Init(root);
|
|||
|
Assert.AreEqual("a", PathMappings.MapPath("a"));
|
|||
|
a.name = "b";
|
|||
|
PathMappings.ClearCache();
|
|||
|
Assert.AreEqual("b", PathMappings.MapPath("a"));
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void TracksObjectMoves()
|
|||
|
{
|
|||
|
var root = CreateRoot("root");
|
|||
|
var a = CreateChild(root, "a");
|
|||
|
var b = CreateChild(root, "b");
|
|||
|
|
|||
|
PathMappings.Init(root);
|
|||
|
Assert.AreEqual("a", PathMappings.MapPath("a"));
|
|||
|
a.transform.parent = b.transform;
|
|||
|
PathMappings.ClearCache();
|
|||
|
Assert.AreEqual("b/a", PathMappings.MapPath("a"));
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void TracksCollapses()
|
|||
|
{
|
|||
|
var root = CreateRoot("root");
|
|||
|
var a = CreateChild(root, "a");
|
|||
|
var b = CreateChild(a, "b");
|
|||
|
var c = CreateChild(b, "c");
|
|||
|
|
|||
|
PathMappings.Init(root);
|
|||
|
PathMappings.MarkRemoved(b);
|
|||
|
c.transform.parent = a.transform;
|
|||
|
Object.DestroyImmediate(b);
|
|||
|
|
|||
|
Assert.AreEqual("a/c", PathMappings.MapPath("a/b/c"));
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void TransformLookthrough()
|
|||
|
{
|
|||
|
var root = CreateRoot("root");
|
|||
|
var a = CreateChild(root, "a");
|
|||
|
var b = CreateChild(a, "b");
|
|||
|
var c = CreateChild(b, "c");
|
|||
|
var d = CreateChild(c, "d");
|
|||
|
|
|||
|
PathMappings.Init(root);
|
|||
|
PathMappings.MarkTransformLookthrough(b);
|
|||
|
PathMappings.MarkTransformLookthrough(c);
|
|||
|
Assert.AreEqual("a/b/c", PathMappings.MapPath("a/b/c"));
|
|||
|
Assert.AreEqual("a", PathMappings.MapPath("a/b/c", true));
|
|||
|
Assert.AreEqual("a/b/c/d", PathMappings.MapPath("a/b/c/d", true));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|