91 lines
3.3 KiB
C#
91 lines
3.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Reflection;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.TestTools;
|
|
|
|
namespace AibisDream.Huoshan.Tests.PlayMode
|
|
{
|
|
public sealed class ExpressionParticlePlayModeTests
|
|
{
|
|
private const string RuntimeAssemblyName = "Assembly-CSharp";
|
|
|
|
[UnityTest]
|
|
public IEnumerator LongWords_ConnectThroughVisualEdgeDistance()
|
|
{
|
|
GameObject firstObject = new GameObject("FirstWordParticle");
|
|
GameObject secondObject = new GameObject("SecondWordParticle");
|
|
try
|
|
{
|
|
Type particleType = RequireRuntimeType(
|
|
"AibisDream.MiniGame.Language.CandidateParticle");
|
|
Component first = firstObject.AddComponent(particleType);
|
|
Component second = secondObject.AddComponent(particleType);
|
|
Invoke(first, "ForceSetUnitText", "internationalization");
|
|
Invoke(second, "ForceSetUnitText", "characteristically");
|
|
yield return null;
|
|
|
|
Bounds firstBounds = (Bounds)Invoke(first, "GetVisualWorldBounds");
|
|
Bounds secondBounds = (Bounds)Invoke(second, "GetVisualWorldBounds");
|
|
secondObject.transform.position = new Vector3(
|
|
firstBounds.extents.x + secondBounds.extents.x + 0.1f,
|
|
0f,
|
|
0f);
|
|
|
|
Type geometryType = RequireRuntimeType(
|
|
"AibisDream.MiniGame.Language.ExpressionParticleGeometry");
|
|
MethodInfo connection = geometryType.GetMethod(
|
|
"TryGetConnection",
|
|
BindingFlags.Public | BindingFlags.Static);
|
|
object[] arguments =
|
|
{
|
|
first,
|
|
second,
|
|
0.01f,
|
|
0.18f,
|
|
Vector3.zero,
|
|
Vector3.zero,
|
|
0f
|
|
};
|
|
|
|
Assert.That(connection, Is.Not.Null);
|
|
bool connected = (bool)connection.Invoke(null, arguments);
|
|
Assert.That(connected, Is.True);
|
|
Assert.That((float)arguments[6], Is.GreaterThan(0f));
|
|
Assert.That(
|
|
Vector3.Distance(
|
|
firstObject.transform.position,
|
|
secondObject.transform.position),
|
|
Is.GreaterThan(0.01f));
|
|
}
|
|
finally
|
|
{
|
|
UnityEngine.Object.Destroy(firstObject);
|
|
UnityEngine.Object.Destroy(secondObject);
|
|
}
|
|
|
|
yield return null;
|
|
}
|
|
|
|
private static Type RequireRuntimeType(string fullName)
|
|
{
|
|
Type type = Type.GetType($"{fullName}, {RuntimeAssemblyName}");
|
|
Assert.That(type, Is.Not.Null, fullName);
|
|
return type;
|
|
}
|
|
|
|
private static object Invoke(
|
|
object target,
|
|
string methodName,
|
|
params object[] arguments)
|
|
{
|
|
MethodInfo method = target.GetType().GetMethod(
|
|
methodName,
|
|
BindingFlags.Public | BindingFlags.Instance);
|
|
Assert.That(method, Is.Not.Null, methodName);
|
|
return method.Invoke(target, arguments);
|
|
}
|
|
}
|
|
}
|