UI相关优化补充

This commit is contained in:
2026-05-25 13:21:41 +08:00
parent 3c812cfb41
commit a1f9122153
54 changed files with 2008 additions and 112 deletions

View File

@@ -0,0 +1,49 @@
using NUnit.Framework;
using UnityEngine;
using BaseGames.Core;
namespace BaseGames.Tests.PlayMode
{
/// <summary>
/// RequiredFieldValidator 反射扫描测试。
/// </summary>
public class RequiredFieldValidatorTests
{
private class Sample : MonoBehaviour
{
[RequiredField] public GameObject Required;
[RequiredField("提示文本")] public string RequiredString;
public GameObject Optional;
}
[Test]
public void MissingField_LogsWarning()
{
var go = new GameObject("ReqHost");
var s = go.AddComponent<Sample>();
s.Required = null;
s.RequiredString = "";
// 期待两条警告Required + RequiredString
UnityEngine.TestTools.LogAssert.Expect(LogType.Warning,
new System.Text.RegularExpressions.Regex(@"\[RequiredField\] Sample\.Required.*"));
UnityEngine.TestTools.LogAssert.Expect(LogType.Warning,
new System.Text.RegularExpressions.Regex(@"\[RequiredField\] Sample\.RequiredString.*"));
RequiredFieldValidator.ValidateAll(s);
Object.DestroyImmediate(go);
}
[Test]
public void FilledField_NoWarning()
{
var go = new GameObject("ReqHost2");
var s = go.AddComponent<Sample>();
s.Required = go;
s.RequiredString = "ok";
RequiredFieldValidator.ValidateAll(s); // 不应有警告
Object.DestroyImmediate(go);
}
}
}