File size: 8,274 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | using System.Reflection;
using System.Collections;
using NUnit.Framework;
using UnityEngine.EventSystems;
using UnityEngine.TestTools;
namespace UnityEngine.UI.Tests
{
[TestFixture]
class NavigationTests
{
GameObject canvasRoot;
Selectable topLeftSelectable;
Selectable bottomLeftSelectable;
Selectable topRightSelectable;
Selectable bottomRightSelectable;
[SetUp]
public void TestSetup()
{
canvasRoot = new GameObject("Canvas", typeof(RectTransform), typeof(Canvas));
GameObject topLeftGO = new GameObject("topLeftGO", typeof(RectTransform), typeof(CanvasRenderer), typeof(Selectable));
topLeftGO.transform.SetParent(canvasRoot.transform);
(topLeftGO.transform as RectTransform).anchoredPosition = new Vector2(50, 200);
topLeftSelectable = topLeftGO.GetComponent<Selectable>();
GameObject bottomLeftGO = new GameObject("bottomLeftGO", typeof(RectTransform), typeof(CanvasRenderer), typeof(Selectable));
bottomLeftGO.transform.SetParent(canvasRoot.transform);
(bottomLeftGO.transform as RectTransform).anchoredPosition = new Vector2(50, 50);
bottomLeftSelectable = bottomLeftGO.GetComponent<Selectable>();
GameObject topRightGO = new GameObject("topRightGO", typeof(RectTransform), typeof(CanvasRenderer), typeof(Selectable));
topRightGO.transform.SetParent(canvasRoot.transform);
(topRightGO.transform as RectTransform).anchoredPosition = new Vector2(200, 200);
topRightSelectable = topRightGO.GetComponent<Selectable>();
GameObject bottomRightGO = new GameObject("bottomRightGO", typeof(RectTransform), typeof(CanvasRenderer), typeof(Selectable));
bottomRightGO.transform.SetParent(canvasRoot.transform);
(bottomRightGO.transform as RectTransform).anchoredPosition = new Vector2(200, 50);
bottomRightSelectable = bottomRightGO.GetComponent<Selectable>();
}
[TearDown]
public void TearDown()
{
GameObject.DestroyImmediate(canvasRoot);
}
[Test]
public void FindSelectableOnRight_ReturnsNextSelectableRightOfTarget()
{
Selectable selectableRightOfTopLeft = topLeftSelectable.FindSelectableOnRight();
Selectable selectableRightOfBottomLeft = bottomLeftSelectable.FindSelectableOnRight();
Assert.AreEqual(topRightSelectable, selectableRightOfTopLeft, "Wrong selectable to right of Top Left Selectable");
Assert.AreEqual(bottomRightSelectable, selectableRightOfBottomLeft, "Wrong selectable to right of Bottom Left Selectable");
}
[Test]
public void FindSelectableOnLeft_ReturnsNextSelectableLeftOfTarget()
{
Selectable selectableLeftOfTopRight = topRightSelectable.FindSelectableOnLeft();
Selectable selectableLeftOfBottomRight = bottomRightSelectable.FindSelectableOnLeft();
Assert.AreEqual(topLeftSelectable, selectableLeftOfTopRight, "Wrong selectable to left of Top Right Selectable");
Assert.AreEqual(bottomLeftSelectable, selectableLeftOfBottomRight, "Wrong selectable to left of Bottom Right Selectable");
}
[Test]
public void FindSelectableOnRDown_ReturnsNextSelectableBelowTarget()
{
Selectable selectableDownOfTopLeft = topLeftSelectable.FindSelectableOnDown();
Selectable selectableDownOfTopRight = topRightSelectable.FindSelectableOnDown();
Assert.AreEqual(bottomLeftSelectable, selectableDownOfTopLeft, "Wrong selectable to Bottom of Top Left Selectable");
Assert.AreEqual(bottomRightSelectable, selectableDownOfTopRight, "Wrong selectable to Bottom of top Right Selectable");
}
[Test]
public void FindSelectableOnUp_ReturnsNextSelectableAboveTarget()
{
Selectable selectableUpOfBottomLeft = bottomLeftSelectable.FindSelectableOnUp();
Selectable selectableUpOfBottomRight = bottomRightSelectable.FindSelectableOnUp();
Assert.AreEqual(topLeftSelectable, selectableUpOfBottomLeft, "Wrong selectable to Up of bottom Left Selectable");
Assert.AreEqual(topRightSelectable, selectableUpOfBottomRight, "Wrong selectable to Up of bottom Right Selectable");
}
[Test]
public void FindSelectableOnRight__WrappingEnabled_ReturnsFurthestSelectableOnLeft()
{
Navigation nav = topRightSelectable.navigation;
nav.wrapAround = true;
nav.mode = Navigation.Mode.Horizontal;
topRightSelectable.navigation = nav;
nav = bottomRightSelectable.navigation;
nav.wrapAround = true;
nav.mode = Navigation.Mode.Horizontal;
bottomRightSelectable.navigation = nav;
Selectable selectableRightOfTopRight = topRightSelectable.FindSelectableOnRight();
Selectable selectableRightOfBottomRight = bottomRightSelectable.FindSelectableOnRight();
Assert.AreEqual(bottomLeftSelectable, selectableRightOfTopRight, "Wrong selectable to right of Top Right Selectable");
Assert.AreEqual(topLeftSelectable, selectableRightOfBottomRight, "Wrong selectable to right of Bottom Right Selectable");
}
[Test]
public void FindSelectableOnLeft_WrappingEnabled_ReturnsFurthestSelectableOnRight()
{
Navigation nav = topLeftSelectable.navigation;
nav.wrapAround = true;
nav.mode = Navigation.Mode.Horizontal;
topLeftSelectable.navigation = nav;
nav = bottomLeftSelectable.navigation;
nav.wrapAround = true;
nav.mode = Navigation.Mode.Horizontal;
bottomLeftSelectable.navigation = nav;
Selectable selectableLeftOfTopLeft = topLeftSelectable.FindSelectableOnLeft();
Selectable selectableLeftOfBottomLeft = bottomLeftSelectable.FindSelectableOnLeft();
Assert.AreEqual(bottomRightSelectable, selectableLeftOfTopLeft, "Wrong selectable to left of Top Left Selectable");
Assert.AreEqual(topRightSelectable, selectableLeftOfBottomLeft, "Wrong selectable to left of Bottom Left Selectable");
}
[Test]
public void FindSelectableOnDown_WrappingEnabled_ReturnsFurthestSelectableAbove()
{
Navigation nav = bottomLeftSelectable.navigation;
nav.wrapAround = true;
nav.mode = Navigation.Mode.Vertical;
bottomLeftSelectable.navigation = nav;
nav = bottomRightSelectable.navigation;
nav.wrapAround = true;
nav.mode = Navigation.Mode.Vertical;
bottomRightSelectable.navigation = nav;
Selectable selectableDownOfBottomLeft = bottomLeftSelectable.FindSelectableOnDown();
Selectable selectableDownOfBottomRight = bottomRightSelectable.FindSelectableOnDown();
Assert.AreEqual(topRightSelectable, selectableDownOfBottomLeft, "Wrong selectable to Bottom of Bottom Left Selectable");
Assert.AreEqual(topLeftSelectable, selectableDownOfBottomRight, "Wrong selectable to Bottom of Bottom Right Selectable");
}
[Test]
public void FindSelectableOnUp_WrappingEnabled_ReturnsFurthestSelectableBelow()
{
Navigation nav = topLeftSelectable.navigation;
nav.wrapAround = true;
nav.mode = Navigation.Mode.Vertical;
topLeftSelectable.navigation = nav;
nav = topRightSelectable.navigation;
nav.wrapAround = true;
nav.mode = Navigation.Mode.Vertical;
topRightSelectable.navigation = nav;
Selectable selectableUpOfTopLeft = topLeftSelectable.FindSelectableOnUp();
Selectable selectableUpOfTopRight = topRightSelectable.FindSelectableOnUp();
Assert.AreEqual(bottomRightSelectable, selectableUpOfTopLeft, "Wrong selectable to Up of Top Left Selectable");
Assert.AreEqual(bottomLeftSelectable, selectableUpOfTopRight, "Wrong selectable to Up of Top Right Selectable");
}
}
}
|