UI相关优化补充
This commit is contained in:
60
Assets/Tests/PlayMode/UITweenTests.cs
Normal file
60
Assets/Tests/PlayMode/UITweenTests.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.TestTools;
|
||||
using BaseGames.UI;
|
||||
|
||||
namespace BaseGames.Tests.PlayMode
|
||||
{
|
||||
/// <summary>
|
||||
/// UITween 静态库测试:验证补间在终态吸附、零时长立即返回、null 安全。
|
||||
/// </summary>
|
||||
public class UITweenTests
|
||||
{
|
||||
private GameObject _go;
|
||||
|
||||
[SetUp] public void SetUp() { _go = new GameObject("TweenHost", typeof(RectTransform), typeof(CanvasGroup)); }
|
||||
[TearDown] public void TearDown() { Object.DestroyImmediate(_go); }
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator MoveAnchored_ReachesTarget()
|
||||
{
|
||||
var rect = _go.GetComponent<RectTransform>();
|
||||
rect.anchoredPosition = Vector2.zero;
|
||||
yield return _go.AddComponent<TestRunner>().Run(UITween.MoveAnchored(rect, new Vector2(100, 50), 0.05f));
|
||||
Assert.AreEqual(new Vector2(100, 50), rect.anchoredPosition);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator FadeCanvasGroup_ReachesTarget()
|
||||
{
|
||||
var cg = _go.GetComponent<CanvasGroup>();
|
||||
cg.alpha = 0f;
|
||||
yield return _go.AddComponent<TestRunner>().Run(UITween.FadeCanvasGroup(cg, 1f, 0.05f));
|
||||
Assert.AreEqual(1f, cg.alpha, 0.001f);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ZeroDuration_SnapsImmediately()
|
||||
{
|
||||
var rect = _go.GetComponent<RectTransform>();
|
||||
yield return _go.AddComponent<TestRunner>().Run(UITween.MoveAnchored(rect, new Vector2(7, 7), 0f));
|
||||
Assert.AreEqual(new Vector2(7, 7), rect.anchoredPosition);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator NullTarget_NoException()
|
||||
{
|
||||
yield return _go.AddComponent<TestRunner>().Run(UITween.MoveAnchored(null, Vector2.one, 0.05f));
|
||||
yield return _go.AddComponent<TestRunner>().Run(UITween.FadeCanvasGroup(null, 1f, 0.05f));
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
/// <summary>挂宿主跑协程的辅助 MonoBehaviour(测试场景无 EventSystem)。</summary>
|
||||
private class TestRunner : MonoBehaviour
|
||||
{
|
||||
public IEnumerator Run(IEnumerator inner) { yield return StartCoroutine(inner); }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user