first commit
This commit is contained in:
@@ -0,0 +1,264 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.UI.Tests;
|
||||
|
||||
namespace Graphics
|
||||
{
|
||||
class GraphicTests : IPrebuildSetup
|
||||
{
|
||||
private GameObject m_PrefabRoot;
|
||||
private ConcreteGraphic m_graphic;
|
||||
private Canvas m_canvas;
|
||||
|
||||
const string kPrefabPath = "Assets/Resources/GraphicTestsPrefab.prefab";
|
||||
|
||||
bool m_dirtyVert;
|
||||
bool m_dirtyLayout;
|
||||
bool m_dirtyMaterial;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var rootGO = new GameObject("rootGo");
|
||||
var canvasGO = new GameObject("CanvasRoot", typeof(Canvas), typeof(GraphicRaycaster));
|
||||
canvasGO.transform.SetParent(rootGO.transform);
|
||||
|
||||
var graphicGO = new GameObject("Graphic", typeof(RectTransform), typeof(ConcreteGraphic));
|
||||
graphicGO.transform.SetParent(canvasGO.transform);
|
||||
|
||||
var gameObject = new GameObject("EventSystem", typeof(EventSystem));
|
||||
gameObject.transform.SetParent(rootGO.transform);
|
||||
|
||||
if (!Directory.Exists("Assets/Resources/"))
|
||||
Directory.CreateDirectory("Assets/Resources/");
|
||||
|
||||
PrefabUtility.SaveAsPrefabAsset(rootGO, kPrefabPath);
|
||||
|
||||
GameObject.DestroyImmediate(rootGO);
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_PrefabRoot = Object.Instantiate(Resources.Load("GraphicTestsPrefab")) as GameObject;
|
||||
|
||||
m_canvas = m_PrefabRoot.GetComponentInChildren<Canvas>();
|
||||
m_graphic = m_PrefabRoot.GetComponentInChildren<ConcreteGraphic>();
|
||||
|
||||
m_graphic.RegisterDirtyVerticesCallback(() => m_dirtyVert = true);
|
||||
m_graphic.RegisterDirtyLayoutCallback(() => m_dirtyLayout = true);
|
||||
m_graphic.RegisterDirtyMaterialCallback(() => m_dirtyMaterial = true);
|
||||
|
||||
ResetDirtyFlags();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
m_graphic = null;
|
||||
m_canvas = null;
|
||||
GameObject.DestroyImmediate(m_PrefabRoot);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OneTimeTearDown()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset(kPrefabPath);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void ResetDirtyFlags()
|
||||
{
|
||||
m_dirtyVert = m_dirtyLayout = m_dirtyMaterial = false;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingDirtyOnActiveGraphicCallsCallbacks()
|
||||
{
|
||||
m_graphic.enabled = false;
|
||||
m_graphic.enabled = true;
|
||||
m_graphic.SetAllDirty();
|
||||
|
||||
Assert.True(m_dirtyVert, "Vertices have not been dirtied");
|
||||
Assert.True(m_dirtyLayout, "Layout has not been dirtied");
|
||||
Assert.True(m_dirtyMaterial, "Material has not been dirtied");
|
||||
|
||||
ResetDirtyFlags();
|
||||
|
||||
m_graphic.SetLayoutDirty();
|
||||
Assert.True(m_dirtyLayout, "Layout has not been dirtied");
|
||||
|
||||
m_graphic.SetVerticesDirty();
|
||||
Assert.True(m_dirtyVert, "Vertices have not been dirtied");
|
||||
|
||||
m_graphic.SetMaterialDirty();
|
||||
Assert.True(m_dirtyMaterial, "Material has not been dirtied");
|
||||
}
|
||||
|
||||
private bool ContainsGraphic(IList<Graphic> array, int size, Graphic element)
|
||||
{
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
if (array[i] == element)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void RefreshGraphicByRaycast()
|
||||
{
|
||||
// force refresh by raycast
|
||||
List<RaycastResult> raycastResultCache = new List<RaycastResult>();
|
||||
PointerEventData data = new PointerEventData(EventSystem.current);
|
||||
var raycaster = m_canvas.GetComponent<GraphicRaycaster>();
|
||||
raycaster.Raycast(data, raycastResultCache);
|
||||
}
|
||||
|
||||
private bool CheckGraphicAddedToGraphicRegistry()
|
||||
{
|
||||
var graphicList = GraphicRegistry.GetGraphicsForCanvas(m_canvas);
|
||||
var graphicListSize = graphicList.Count;
|
||||
return ContainsGraphic(graphicList, graphicListSize, m_graphic);
|
||||
}
|
||||
|
||||
private bool CheckGraphicAddedToRaycastGraphicRegistry()
|
||||
{
|
||||
var graphicList = GraphicRegistry.GetRaycastableGraphicsForCanvas(m_canvas);
|
||||
var graphicListSize = graphicList.Count;
|
||||
return ContainsGraphic(graphicList, graphicListSize, m_graphic);
|
||||
}
|
||||
|
||||
private void CheckGraphicRaycastDisableValidity()
|
||||
{
|
||||
RefreshGraphicByRaycast();
|
||||
Assert.False(CheckGraphicAddedToGraphicRegistry(), "Graphic should no longer be registered in m_CanvasGraphics");
|
||||
Assert.False(CheckGraphicAddedToRaycastGraphicRegistry(), "Graphic should no longer be registered in m_RaycastableGraphics");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnEnableLeavesGraphicInExpectedState()
|
||||
{
|
||||
m_graphic.enabled = false;
|
||||
m_graphic.enabled = true; // on enable is called directly
|
||||
|
||||
Assert.True(CheckGraphicAddedToGraphicRegistry(), "Graphic should be registered in m_CanvasGraphics");
|
||||
Assert.True(CheckGraphicAddedToRaycastGraphicRegistry(), "Graphic should be registered in m_RaycastableGraphics");
|
||||
|
||||
Assert.AreEqual(Texture2D.whiteTexture, m_graphic.mainTexture, "mainTexture should be Texture2D.whiteTexture");
|
||||
|
||||
Assert.NotNull(m_graphic.canvas);
|
||||
|
||||
Assert.True(m_dirtyVert, "Vertices have not been dirtied");
|
||||
Assert.True(m_dirtyLayout, "Layout has not been dirtied");
|
||||
Assert.True(m_dirtyMaterial, "Material has not been dirtied");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnEnableTwiceLeavesGraphicInExpectedState()
|
||||
{
|
||||
m_graphic.enabled = true;
|
||||
|
||||
// force onEnable by reflection to call it second time
|
||||
m_graphic.InvokeOnEnable();
|
||||
|
||||
m_graphic.enabled = false;
|
||||
|
||||
CheckGraphicRaycastDisableValidity();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnDisableLeavesGraphicInExpectedState()
|
||||
{
|
||||
m_graphic.enabled = true;
|
||||
m_graphic.enabled = false;
|
||||
|
||||
CheckGraphicRaycastDisableValidity();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnPopulateMeshWorksAsExpected()
|
||||
{
|
||||
m_graphic.rectTransform.anchoredPosition = new Vector2(100, 100);
|
||||
m_graphic.rectTransform.sizeDelta = new Vector2(150, 742);
|
||||
m_graphic.color = new Color(50, 100, 150, 200);
|
||||
|
||||
VertexHelper vh = new VertexHelper();
|
||||
m_graphic.InvokeOnPopulateMesh(vh);
|
||||
|
||||
GraphicTestHelper.TestOnPopulateMeshDefaultBehavior(m_graphic, vh);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnDidApplyAnimationPropertiesSetsAllDirty()
|
||||
{
|
||||
m_graphic.enabled = true; // Usually set through SetEnabled, from Behavior
|
||||
|
||||
m_graphic.InvokeOnDidApplyAnimationProperties();
|
||||
Assert.True(m_dirtyVert, "Vertices have not been dirtied");
|
||||
Assert.True(m_dirtyLayout, "Layout has not been dirtied");
|
||||
Assert.True(m_dirtyMaterial, "Material has not been dirtied");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MakingGraphicNonRaycastableRemovesGraphicFromProperLists()
|
||||
{
|
||||
Assert.True(CheckGraphicAddedToGraphicRegistry(), "Graphic should be registered in m_CanvasGraphics");
|
||||
Assert.True(CheckGraphicAddedToRaycastGraphicRegistry(), "Graphic should be registered in m_RaycastableGraphics");
|
||||
|
||||
m_graphic.raycastTarget = false;
|
||||
|
||||
Assert.True(CheckGraphicAddedToGraphicRegistry(), "Graphic should be registered in m_CanvasGraphics");
|
||||
Assert.False(CheckGraphicAddedToRaycastGraphicRegistry(), "Graphic should no longer be registered in m_RaycastableGraphics");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnEnableLeavesNonRaycastGraphicInExpectedState()
|
||||
{
|
||||
m_graphic.enabled = false;
|
||||
m_graphic.raycastTarget = false;
|
||||
m_graphic.enabled = true; // on enable is called directly
|
||||
|
||||
Assert.True(CheckGraphicAddedToGraphicRegistry(), "Graphic should be registered in m_CanvasGraphics");
|
||||
Assert.False(CheckGraphicAddedToRaycastGraphicRegistry(), "Graphic should no longer be registered in m_RaycastableGraphics");
|
||||
|
||||
Assert.AreEqual(Texture2D.whiteTexture, m_graphic.mainTexture, "mainTexture should be Texture2D.whiteTexture");
|
||||
|
||||
Assert.NotNull(m_graphic.canvas);
|
||||
|
||||
Assert.True(m_dirtyVert, "Vertices have not been dirtied");
|
||||
Assert.True(m_dirtyLayout, "Layout has not been dirtied");
|
||||
Assert.True(m_dirtyMaterial, "Material has not been dirtied");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingRaycastTargetOnDisabledGraphicDoesntAddItRaycastList()
|
||||
{
|
||||
Assert.True(CheckGraphicAddedToGraphicRegistry(), "Graphic should be registered in m_CanvasGraphics");
|
||||
Assert.True(CheckGraphicAddedToRaycastGraphicRegistry(), "Graphic should be registered in m_RaycastableGraphics");
|
||||
|
||||
m_graphic.raycastTarget = false;
|
||||
|
||||
Assert.True(CheckGraphicAddedToGraphicRegistry(), "Graphic should be registered in m_CanvasGraphics");
|
||||
Assert.False(CheckGraphicAddedToRaycastGraphicRegistry(), "Graphic should no longer be registered in m_RaycastableGraphics");
|
||||
|
||||
m_graphic.enabled = false;
|
||||
|
||||
Assert.False(CheckGraphicAddedToGraphicRegistry(), "Graphic should NOT be registered in m_CanvasGraphics");
|
||||
Assert.False(CheckGraphicAddedToRaycastGraphicRegistry(), "Graphic should no longer be registered in m_RaycastableGraphics");
|
||||
|
||||
m_graphic.raycastTarget = true;
|
||||
|
||||
Assert.False(CheckGraphicAddedToGraphicRegistry(), "Graphic should NOT be registered in m_CanvasGraphics");
|
||||
Assert.False(CheckGraphicAddedToRaycastGraphicRegistry(), "Graphic should no longer be registered in m_RaycastableGraphics");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e88a766c2b8b47841936c136f4afbba9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0bae4ff8f5baf64aad3b92b8aea0603
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,163 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Graphics
|
||||
{
|
||||
class MaskTests : IPrebuildSetup
|
||||
{
|
||||
GameObject m_PrefabRoot;
|
||||
const string kPrefabPath = "Assets/Resources/MaskTestsPrefab.prefab";
|
||||
|
||||
Mask m_mask;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var rootGO = new GameObject("rootGo");
|
||||
GameObject canvasGO = new GameObject("Canvas", typeof(RectTransform), typeof(Canvas));
|
||||
canvasGO.transform.SetParent(rootGO.transform);
|
||||
|
||||
var canvas = canvasGO.GetComponent<Canvas>();
|
||||
canvas.referencePixelsPerUnit = 100;
|
||||
|
||||
var gameObject = new GameObject("Mask", typeof(RectTransform), typeof(Mask), typeof(Image));
|
||||
gameObject.transform.SetParent(canvasGO.transform);
|
||||
|
||||
if (!Directory.Exists("Assets/Resources/"))
|
||||
Directory.CreateDirectory("Assets/Resources/");
|
||||
|
||||
PrefabUtility.SaveAsPrefabAsset(rootGO, kPrefabPath);
|
||||
GameObject.DestroyImmediate(rootGO);
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_PrefabRoot = Object.Instantiate(Resources.Load("MaskTestsPrefab")) as GameObject;
|
||||
m_mask = m_PrefabRoot.GetComponentInChildren<Mask>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
m_mask = null;
|
||||
Object.DestroyImmediate(m_PrefabRoot);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OneTimeTearDown()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset(kPrefabPath);
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator GetModifiedMaterialReturnsOriginalMaterialWhenNoGraphicComponentIsAttached()
|
||||
{
|
||||
Object.DestroyImmediate(m_mask.gameObject.GetComponent<Image>());
|
||||
yield return null;
|
||||
Material material = new Material(Graphic.defaultGraphicMaterial);
|
||||
Material modifiedMaterial = m_mask.GetModifiedMaterial(material);
|
||||
Assert.AreEqual(material, modifiedMaterial);
|
||||
}
|
||||
|
||||
private Dictionary<string, GameObject> CreateMaskHierarchy(string suffix, int hierarchyDepth, out GameObject root)
|
||||
{
|
||||
var nameToObjectMapping = new Dictionary<string, GameObject>();
|
||||
|
||||
root = new GameObject("root", typeof(RectTransform), typeof(Canvas));
|
||||
nameToObjectMapping["root"] = root;
|
||||
|
||||
GameObject current = root;
|
||||
|
||||
for (int i = 0; i < hierarchyDepth; i++)
|
||||
{
|
||||
string name = suffix + (i + 1);
|
||||
var gameObject = new GameObject(name, typeof(RectTransform), typeof(Mask), typeof(Image));
|
||||
gameObject.transform.SetParent(current.transform);
|
||||
nameToObjectMapping[name] = gameObject;
|
||||
current = gameObject;
|
||||
}
|
||||
|
||||
return nameToObjectMapping;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetModifiedMaterialReturnsOriginalMaterialWhenDepthIsEightOrMore()
|
||||
{
|
||||
GameObject root;
|
||||
var objectsMap = CreateMaskHierarchy("subMask", 9, out root);
|
||||
Mask mask = objectsMap["subMask" + 9].GetComponent<Mask>();
|
||||
Material material = new Material(Graphic.defaultGraphicMaterial);
|
||||
Material modifiedMaterial = mask.GetModifiedMaterial(material);
|
||||
Assert.AreEqual(material, modifiedMaterial);
|
||||
GameObject.DestroyImmediate(root);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetModifiedMaterialReturnsDesiredMaterialWithSingleMask()
|
||||
{
|
||||
Material material = new Material(Graphic.defaultGraphicMaterial);
|
||||
Material modifiedMaterial = m_mask.GetModifiedMaterial(material);
|
||||
|
||||
Assert.AreNotEqual(material, modifiedMaterial);
|
||||
Assert.AreEqual(1, modifiedMaterial.GetInt("_Stencil"));
|
||||
Assert.AreEqual(StencilOp.Replace, (StencilOp)modifiedMaterial.GetInt("_StencilOp"));
|
||||
Assert.AreEqual(CompareFunction.Always, (CompareFunction)modifiedMaterial.GetInt("_StencilComp"));
|
||||
Assert.AreEqual(255, modifiedMaterial.GetInt("_StencilReadMask"));
|
||||
Assert.AreEqual(255, modifiedMaterial.GetInt("_StencilWriteMask"));
|
||||
Assert.AreEqual(ColorWriteMask.All, (ColorWriteMask)modifiedMaterial.GetInt("_ColorMask"));
|
||||
Assert.AreEqual(1, modifiedMaterial.GetInt("_UseUIAlphaClip"));
|
||||
|
||||
Assert.IsTrue(modifiedMaterial.IsKeywordEnabled("UNITY_UI_ALPHACLIP"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetModifiedMaterialReturnsDesiredMaterialWithMultipleMasks()
|
||||
{
|
||||
for (int i = 2; i < 8; i++)
|
||||
{
|
||||
GameObject root;
|
||||
var objectsMap = CreateMaskHierarchy("subMask", i, out root);
|
||||
Mask mask = objectsMap["subMask" + i].GetComponent<Mask>();
|
||||
|
||||
int stencilDepth = MaskUtilities.GetStencilDepth(mask.transform, objectsMap["root"].transform);
|
||||
|
||||
int desiredStencilBit = 1 << stencilDepth;
|
||||
Material material = new Material(Graphic.defaultGraphicMaterial);
|
||||
Material modifiedMaterial = mask.GetModifiedMaterial(material);
|
||||
int stencil = modifiedMaterial.GetInt("_Stencil");
|
||||
|
||||
Assert.AreNotEqual(material, modifiedMaterial);
|
||||
Assert.AreEqual(desiredStencilBit | (desiredStencilBit - 1), stencil);
|
||||
Assert.AreEqual(StencilOp.Replace, (StencilOp)modifiedMaterial.GetInt("_StencilOp"));
|
||||
Assert.AreEqual(CompareFunction.Equal, (CompareFunction)modifiedMaterial.GetInt("_StencilComp"));
|
||||
Assert.AreEqual(desiredStencilBit - 1, modifiedMaterial.GetInt("_StencilReadMask"));
|
||||
Assert.AreEqual(desiredStencilBit | (desiredStencilBit - 1), modifiedMaterial.GetInt("_StencilWriteMask"));
|
||||
Assert.AreEqual(ColorWriteMask.All, (ColorWriteMask)modifiedMaterial.GetInt("_ColorMask"));
|
||||
Assert.AreEqual(1, modifiedMaterial.GetInt("_UseUIAlphaClip"));
|
||||
Assert.IsTrue(modifiedMaterial.IsKeywordEnabled("UNITY_UI_ALPHACLIP"));
|
||||
|
||||
GameObject.DestroyImmediate(root);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GraphicComponentWithMaskIsMarkedAsIsMaskingGraphicWhenEnabled()
|
||||
{
|
||||
var graphic = m_PrefabRoot.GetComponentInChildren<Image>();
|
||||
Assert.AreEqual(true, graphic.isMaskingGraphic);
|
||||
m_mask.enabled = false;
|
||||
Assert.AreEqual(false, graphic.isMaskingGraphic);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b611b0a598aeada419afa9737807c598
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,169 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aca0de4e74f6cdf41a449805f345a4f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,77 @@
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Graphics
|
||||
{
|
||||
public class RawImageTest : IPrebuildSetup
|
||||
{
|
||||
private const int Width = 32;
|
||||
private const int Height = 32;
|
||||
|
||||
private GameObject m_PrefabRoot;
|
||||
private RawImageTestHook m_image;
|
||||
private Texture2D m_defaultTexture;
|
||||
|
||||
const string kPrefabPath = "Assets/Resources/RawImageUpdatePrefab.prefab";
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var rootGO = new GameObject("Root");
|
||||
var canvasGO = new GameObject("Canvas", typeof(Canvas));
|
||||
var canvas = canvasGO.GetComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.WorldSpace;
|
||||
canvasGO.transform.SetParent(rootGO.transform);
|
||||
|
||||
var imageGO = new GameObject("Image", typeof(RectTransform), typeof(RawImageTestHook));
|
||||
var imageTransform = imageGO.GetComponent<RectTransform>();
|
||||
imageTransform.SetParent(canvas.transform);
|
||||
|
||||
imageTransform.anchoredPosition = Vector2.zero;
|
||||
|
||||
if (!Directory.Exists("Assets/Resources/"))
|
||||
Directory.CreateDirectory("Assets/Resources/");
|
||||
|
||||
PrefabUtility.SaveAsPrefabAsset(rootGO, kPrefabPath);
|
||||
GameObject.DestroyImmediate(rootGO);
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_PrefabRoot = Object.Instantiate(Resources.Load("RawImageUpdatePrefab")) as GameObject;
|
||||
|
||||
m_image = m_PrefabRoot.transform.Find("Canvas/Image").GetComponent<RawImageTestHook>();
|
||||
m_defaultTexture = new Texture2D(Width, Height);
|
||||
m_image.texture = m_defaultTexture;
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Sprite_Material()
|
||||
{
|
||||
m_image.ResetTest();
|
||||
|
||||
// can test only on texture change, same texture is bypass by RawImage property
|
||||
m_image.texture = new Texture2D(Width, Height);
|
||||
yield return new WaitUntil(() => m_image.isGeometryUpdated);
|
||||
|
||||
// validate that layout change rebuild is called
|
||||
Assert.IsTrue(m_image.isMaterialRebuild);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_PrefabRoot);
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset(kPrefabPath);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acfa3573efc38c844be021fdaa8cf8a6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RawImageTestHook : RawImage
|
||||
{
|
||||
public bool isGeometryUpdated;
|
||||
public bool isCacheUsed;
|
||||
public bool isLayoutRebuild;
|
||||
public bool isMaterialRebuild;
|
||||
|
||||
public void ResetTest()
|
||||
{
|
||||
isGeometryUpdated = false;
|
||||
isLayoutRebuild = false;
|
||||
isMaterialRebuild = false;
|
||||
isCacheUsed = false;
|
||||
}
|
||||
|
||||
public override void SetLayoutDirty()
|
||||
{
|
||||
base.SetLayoutDirty();
|
||||
isLayoutRebuild = true;
|
||||
}
|
||||
|
||||
public override void SetMaterialDirty()
|
||||
{
|
||||
base.SetMaterialDirty();
|
||||
isMaterialRebuild = true;
|
||||
}
|
||||
|
||||
protected override void UpdateGeometry()
|
||||
{
|
||||
base.UpdateGeometry();
|
||||
isGeometryUpdated = true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 40c83ba6a1a64cb4baac27028dd1acc1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ToggleTestImageHook : Image
|
||||
{
|
||||
public float durationTween;
|
||||
public override void CrossFadeColor(Color targetColor, float duration, bool ignoreTimeScale, bool useAlpha, bool useRGB)
|
||||
{
|
||||
durationTween = duration;
|
||||
base.CrossFadeColor(targetColor, duration, ignoreTimeScale, useAlpha, useRGB);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c004b1354944164fb076276c289afc1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user