53 lines
1.6 KiB
C#
53 lines
1.6 KiB
C#
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using XGame;
|
|
|
|
public sealed class UIManagerAttachTests
|
|
{
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
DestroyIfExists("ZeroSizedCanvas");
|
|
DestroyIfExists("UIRoot");
|
|
EventSystem eventSystem = Object.FindObjectOfType<EventSystem>();
|
|
if (eventSystem != null)
|
|
{
|
|
Object.DestroyImmediate(eventSystem.gameObject);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void AttachTo_StretchesZeroSizedCanvasRootAndAppliesUiLayer()
|
|
{
|
|
GameObject ui = new GameObject("ZeroSizedCanvas", typeof(RectTransform), typeof(Canvas));
|
|
GameObject child = new GameObject("Child", typeof(RectTransform), typeof(Image));
|
|
child.transform.SetParent(ui.transform, false);
|
|
|
|
RectTransform rt = ui.GetComponent<RectTransform>();
|
|
rt.anchorMin = Vector2.zero;
|
|
rt.anchorMax = Vector2.zero;
|
|
rt.sizeDelta = Vector2.zero;
|
|
|
|
UIManager.AttachTo(UILayer.Normal, ui);
|
|
|
|
int uiLayer = LayerMask.NameToLayer("UI");
|
|
Assert.That(rt.anchorMin, Is.EqualTo(Vector2.zero));
|
|
Assert.That(rt.anchorMax, Is.EqualTo(Vector2.one));
|
|
Assert.That(rt.offsetMin, Is.EqualTo(Vector2.zero));
|
|
Assert.That(rt.offsetMax, Is.EqualTo(Vector2.zero));
|
|
Assert.That(ui.layer, Is.EqualTo(uiLayer));
|
|
Assert.That(child.layer, Is.EqualTo(uiLayer));
|
|
}
|
|
|
|
private static void DestroyIfExists(string name)
|
|
{
|
|
GameObject go = GameObject.Find(name);
|
|
if (go != null)
|
|
{
|
|
Object.DestroyImmediate(go);
|
|
}
|
|
}
|
|
}
|