mirror of
https://github.com/nolen777/eagle0.git
synced 2026-07-28 21:35:42 +00:00
Guard province action animation sprites (#7224)
This commit is contained in:
+64
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using eagle;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace eagle0.Tests {
|
||||
[TestFixture]
|
||||
public class ProvinceActionAnimatorSpriteTests {
|
||||
private const string EagleScenePath = "Assets/Scenes/Eagle.unity";
|
||||
|
||||
[Test]
|
||||
public void EagleSceneProvinceActionAnimatorHasVisualSpritesAssigned() {
|
||||
var scene = EditorSceneManager.OpenScene(EagleScenePath, OpenSceneMode.Single);
|
||||
var animator = FindSceneComponent<ProvinceActionAnimator>(scene);
|
||||
var violations = new List<string>();
|
||||
|
||||
foreach (var field in PublicInstanceFields()) {
|
||||
if (field.FieldType == typeof(Sprite)) {
|
||||
if (field.GetValue(animator) == null) {
|
||||
violations.Add($"{field.Name} must be assigned.");
|
||||
}
|
||||
} else if (field.FieldType == typeof(Sprite[])) {
|
||||
var sprites = (Sprite[])field.GetValue(animator);
|
||||
if (sprites == null || sprites.Length == 0) {
|
||||
violations.Add($"{field.Name} must contain at least one sprite.");
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var i = 0; i < sprites.Length; i++) {
|
||||
if (sprites[i] == null) {
|
||||
violations.Add($"{field.Name}[{i}] must be assigned.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert.IsEmpty(
|
||||
violations,
|
||||
"Eagle action animation sprites should stay assigned so URP visual QA covers real effects:\n" +
|
||||
string.Join("\n", violations));
|
||||
}
|
||||
|
||||
private static IEnumerable<FieldInfo> PublicInstanceFields() {
|
||||
return typeof(ProvinceActionAnimator)
|
||||
.GetFields(BindingFlags.Instance | BindingFlags.Public)
|
||||
.Where(field => field.FieldType == typeof(Sprite) ||
|
||||
field.FieldType == typeof(Sprite[]))
|
||||
.OrderBy(field => field.Name, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
private static T FindSceneComponent<T>(Scene scene)
|
||||
where T : Component {
|
||||
var component = Resources.FindObjectsOfTypeAll<T>().FirstOrDefault(
|
||||
item => item.gameObject.scene == scene);
|
||||
Assert.NotNull(component, $"{scene.path} must contain {typeof(T).Name}.");
|
||||
return component;
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d6061174edd34718ab7e71ea8a08ffe5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user