first commit
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BridgeScriptForRetainingObjects : MonoBehaviour
|
||||
{
|
||||
public const string bridgeObjectName = "BridgeGameObject";
|
||||
|
||||
public GameObject canvasGO;
|
||||
public GameObject nestedCanvasGO;
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a26e19d51cbfac42a02631ad1f9e39e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,203 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[TestFixture]
|
||||
public class CanvasGroupTests
|
||||
{
|
||||
GameObject m_CanvasObject;
|
||||
CanvasGroup m_CanvasGroup;
|
||||
|
||||
CanvasRenderer m_ChildCanvasRenderer;
|
||||
CanvasGroup m_ChildCanvasGroup;
|
||||
|
||||
CanvasRenderer m_GrandChildCanvasRenderer;
|
||||
CanvasGroup m_GrandChildCanvasGroup;
|
||||
|
||||
GameObject m_CanvasTwoObject;
|
||||
CanvasGroup m_CanvasTwoGroup;
|
||||
|
||||
CanvasRenderer m_ChildCanvasTwoRenderer;
|
||||
|
||||
const float m_CanvasAlpha = 0.25f;
|
||||
const float m_ChildAlpha = 0.5f;
|
||||
const float m_GrandChildAlpha = 0.8f;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_CanvasObject = new GameObject("Canvas", typeof(Canvas));
|
||||
m_CanvasGroup = m_CanvasObject.AddComponent<CanvasGroup>();
|
||||
m_CanvasGroup.alpha = m_CanvasAlpha;
|
||||
|
||||
var childObject = new GameObject("Child Object", typeof(Image));
|
||||
childObject.transform.SetParent(m_CanvasObject.transform);
|
||||
m_ChildCanvasGroup = childObject.AddComponent<CanvasGroup>();
|
||||
m_ChildCanvasGroup.alpha = m_ChildAlpha;
|
||||
m_ChildCanvasRenderer = childObject.GetComponent<CanvasRenderer>();
|
||||
|
||||
var grandChildObject = new GameObject("Grand Child Object", typeof(Image));
|
||||
grandChildObject.transform.SetParent(childObject.transform);
|
||||
m_GrandChildCanvasGroup = grandChildObject.AddComponent<CanvasGroup>();
|
||||
m_GrandChildCanvasGroup.alpha = m_GrandChildAlpha;
|
||||
m_GrandChildCanvasRenderer = grandChildObject.GetComponent<CanvasRenderer>();
|
||||
|
||||
m_CanvasTwoObject = new GameObject("CanvasTwo", typeof(Canvas));
|
||||
m_CanvasTwoObject.transform.SetParent(m_CanvasObject.transform);
|
||||
m_CanvasTwoGroup = m_CanvasTwoObject.AddComponent<CanvasGroup>();
|
||||
m_CanvasTwoGroup.alpha = m_CanvasAlpha;
|
||||
|
||||
var childTwoObject = new GameObject("Child Two Object", typeof(Image));
|
||||
childTwoObject.transform.SetParent(m_CanvasTwoObject.transform);
|
||||
m_ChildCanvasTwoRenderer = childTwoObject.GetComponent<CanvasRenderer>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasObject);
|
||||
}
|
||||
|
||||
private void SetUpCanvasGroupState()
|
||||
{
|
||||
m_CanvasGroup.enabled = false;
|
||||
m_CanvasGroup.ignoreParentGroups = false;
|
||||
m_ChildCanvasGroup.enabled = false;
|
||||
m_ChildCanvasGroup.ignoreParentGroups = false;
|
||||
m_GrandChildCanvasGroup.enabled = false;
|
||||
m_GrandChildCanvasGroup.ignoreParentGroups = false;
|
||||
|
||||
m_CanvasTwoGroup.enabled = false;
|
||||
m_CanvasTwoGroup.ignoreParentGroups = false;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupEffectSelfAndChildrenAlpha()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the child CanvasGroup. It and its children should now have the same alpha value.
|
||||
m_ChildCanvasGroup.enabled = true;
|
||||
|
||||
Assert.AreEqual(m_ChildAlpha, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_ChildAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnACanvasEffectAllChildrenAlpha()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Children under a different nest canvas should also obey the alpha
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasTwoRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Canvas CanvasGroup. All of the Canvas children should now have the same alpha value.
|
||||
m_CanvasGroup.enabled = true;
|
||||
|
||||
Assert.AreEqual(m_CanvasAlpha, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_CanvasAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Children under a different nest canvas should also obey the alpha
|
||||
Assert.AreEqual(m_CanvasAlpha, m_ChildCanvasTwoRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnLeafChildEffectOnlyThatChild()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Leaf child CanvasGroup. Only it should have a modified alpha
|
||||
m_GrandChildCanvasGroup.enabled = true;
|
||||
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_GrandChildAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnCanvasAndChildMultipleAlphaValuesCorrectly()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Canvas CanvasGroup. All of the Canvas children should now have the same alpha value.
|
||||
m_CanvasGroup.enabled = true;
|
||||
m_ChildCanvasGroup.enabled = true;
|
||||
Assert.AreEqual(m_CanvasAlpha * m_ChildAlpha, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_CanvasAlpha * m_ChildAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnCanvasAndChildWithChildIgnoringParentGroupMultipleAlphaValuesCorrectly()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Canvas CanvasGroup. All of the Canvas children should now have the same alpha value.
|
||||
m_CanvasGroup.enabled = true;
|
||||
m_ChildCanvasGroup.enabled = true;
|
||||
m_ChildCanvasGroup.ignoreParentGroups = true;
|
||||
Assert.AreEqual(m_ChildAlpha, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_ChildAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnCanvasAndChildrenWithAllChildrenIgnoringParentGroupMultipleAlphaValuesCorrectly()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Canvas CanvasGroup. All of the Canvas children should now have the same alpha value.
|
||||
m_CanvasGroup.enabled = true;
|
||||
m_ChildCanvasGroup.enabled = true;
|
||||
m_GrandChildCanvasGroup.enabled = true;
|
||||
m_ChildCanvasGroup.ignoreParentGroups = true;
|
||||
m_GrandChildCanvasGroup.ignoreParentGroups = true;
|
||||
Assert.AreEqual(m_ChildAlpha, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_GrandChildAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnNestedCanvasIgnoringParentGroupMultipleAlphaValuesCorrectly()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasTwoRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Canvas CanvasGroup. All of the Canvas children should now have the same alpha value.
|
||||
m_CanvasGroup.enabled = true;
|
||||
m_CanvasTwoGroup.enabled = true;
|
||||
m_CanvasTwoGroup.ignoreParentGroups = true;
|
||||
Assert.AreEqual(m_CanvasAlpha, m_ChildCanvasTwoRenderer.GetInheritedAlpha());
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a14a59f2a5c757e469c3e4e17b798c2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEditor;
|
||||
|
||||
[TestFixture]
|
||||
public class CanvasResizeCorrectlyForRenderTexture
|
||||
{
|
||||
Canvas m_Canvas;
|
||||
Camera m_Camera;
|
||||
RenderTexture m_RenderTexture;
|
||||
|
||||
[Test]
|
||||
public void CanvasResizeCorrectly()
|
||||
{
|
||||
var cameraGameObject = new GameObject("PreviewCamera", typeof(Camera));
|
||||
var canvasGameObject = new GameObject("Canvas", typeof(Canvas));
|
||||
m_Camera = cameraGameObject.GetComponent<Camera>();
|
||||
m_Canvas = canvasGameObject.GetComponent<Canvas>();
|
||||
|
||||
m_Canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
m_Canvas.worldCamera = m_Camera;
|
||||
var rectTransform = canvasGameObject.transform as RectTransform;
|
||||
m_Canvas.updateRectTransformForStandalone = StandaloneRenderResize.Disabled;
|
||||
m_RenderTexture = new RenderTexture(100, 100, 0);
|
||||
m_Camera.targetTexture = m_RenderTexture;
|
||||
|
||||
m_Camera.Render();
|
||||
|
||||
Assert.AreNotEqual(new Vector2(100, 100), rectTransform.sizeDelta);
|
||||
|
||||
m_Canvas.updateRectTransformForStandalone = StandaloneRenderResize.Enabled;
|
||||
m_Camera.Render();
|
||||
Assert.AreEqual(new Vector2(100, 100), rectTransform.sizeDelta);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_Canvas.gameObject);
|
||||
GameObject.DestroyImmediate(m_Camera.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(m_RenderTexture);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4dbe29df1b294c4f8f0a2fb529d19fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[TestFixture]
|
||||
[Category("RegressionTest")]
|
||||
[Description("CoveredBugID = 734299")]
|
||||
public class CanvasScalerWithChildTextObjectDoesNotCrash
|
||||
{
|
||||
GameObject m_CanvasObject;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.ExecuteMenuItem("Window/General/Game");
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CanvasScalerWithChildTextObjectWithTextFontDoesNotCrash()
|
||||
{
|
||||
//This adds a Canvas component as well
|
||||
m_CanvasObject = new GameObject("Canvas");
|
||||
var canvasScaler = m_CanvasObject.AddComponent<CanvasScaler>();
|
||||
m_CanvasObject.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceCamera;
|
||||
|
||||
//the crash only reproduces if the text component is a child of the game object
|
||||
//that has the CanvasScaler component and if it has an actual font and text set
|
||||
var textObject = new GameObject("Text").AddComponent<UnityEngine.UI.Text>();
|
||||
textObject.font = Font.CreateDynamicFontFromOSFont("Arial", 14);
|
||||
textObject.text = "New Text";
|
||||
textObject.transform.SetParent(m_CanvasObject.transform);
|
||||
canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
canvasScaler.referenceResolution = new Vector2(1080, 1020);
|
||||
|
||||
//The crash happens when setting the referenceResolution to a small value
|
||||
canvasScaler.referenceResolution = new Vector2(9, 9);
|
||||
|
||||
//We need to wait a few milliseconds for the crash to happen, otherwise Debug.Log will
|
||||
//get executed and the test will pass
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
|
||||
Assert.That(true);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasObject);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13d161b14bb3ab74e8a9634e26fb7a5e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEditor;
|
||||
|
||||
[TestFixture]
|
||||
public class CanvasSizeCorrectInAwakeAndStart : IPrebuildSetup
|
||||
{
|
||||
const string k_SceneName = "CanvasSizeCorrectInAwakeAndStartScene";
|
||||
GameObject m_CanvasGameObject;
|
||||
Scene m_InitScene;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Action codeToExecute = delegate()
|
||||
{
|
||||
var canvasGO = new GameObject("CanvasToAddImage", typeof(Canvas));
|
||||
var imageGO = new GameObject("ImageOnCanvas", typeof(UnityEngine.UI.Image));
|
||||
imageGO.transform.localPosition = Vector3.one;
|
||||
imageGO.transform.SetParent(canvasGO.transform);
|
||||
imageGO.AddComponent<CanvasSizeCorrectInAwakeAndStartScript>();
|
||||
canvasGO.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
imageGO.SetActive(false);
|
||||
};
|
||||
CreateSceneUtility.CreateScene(k_SceneName, codeToExecute);
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_InitScene = SceneManager.GetActiveScene();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CanvasSizeIsCorrectInAwakeAndStart()
|
||||
{
|
||||
AsyncOperation operation = SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
|
||||
yield return operation;
|
||||
|
||||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
|
||||
m_CanvasGameObject = GameObject.Find("CanvasToAddImage");
|
||||
var imageGO = m_CanvasGameObject.transform.Find("ImageOnCanvas");
|
||||
imageGO.gameObject.SetActive(true);
|
||||
var component = imageGO.GetComponent<CanvasSizeCorrectInAwakeAndStartScript>();
|
||||
|
||||
yield return new WaitUntil(() => component.isAwakeCalled && component.isStartCalled);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasGameObject);
|
||||
SceneManager.SetActiveScene(m_InitScene);
|
||||
SceneManager.UnloadSceneAsync(k_SceneName);
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset("Assets/" + k_SceneName + ".unity");
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec35c13a8280a8d4e817bc4afd8a95de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,21 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
public class CanvasSizeCorrectInAwakeAndStartScript : MonoBehaviour
|
||||
{
|
||||
public bool isStartCalled { get; private set; }
|
||||
public bool isAwakeCalled { get; private set; }
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
Assert.That(transform.position, Is.Not.EqualTo(Vector3.zero).Using(new Vector3EqualityComparer(0.0f)));
|
||||
isAwakeCalled = true;
|
||||
}
|
||||
|
||||
protected void Start()
|
||||
{
|
||||
Assert.That(transform.position, Is.Not.EqualTo(Vector3.zero).Using(new Vector3EqualityComparer(0.0f)));
|
||||
isStartCalled = true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df1ba932d4ce4534e97a0f10c85cd3c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,84 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
[TestFixture]
|
||||
public class CheckMeshColorsAndColors32Match
|
||||
{
|
||||
GameObject m_CanvasGO;
|
||||
GameObject m_ColorMeshGO;
|
||||
GameObject m_Color32MeshGO;
|
||||
Texture2D m_ScreenTexture;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
// Create Canvas
|
||||
m_CanvasGO = new GameObject("Canvas");
|
||||
Canvas canvas = m_CanvasGO.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
// Create Color UI GameObject
|
||||
m_ColorMeshGO = new GameObject("ColorMesh");
|
||||
CanvasRenderer colorMeshCanvasRenderer = m_ColorMeshGO.AddComponent<CanvasRenderer>();
|
||||
RectTransform colorMeshRectTransform = m_ColorMeshGO.AddComponent<RectTransform>();
|
||||
colorMeshRectTransform.pivot = colorMeshRectTransform.anchorMin = colorMeshRectTransform.anchorMax = Vector2.zero;
|
||||
m_ColorMeshGO.transform.SetParent(m_CanvasGO.transform);
|
||||
|
||||
// Create Color32 UI GameObject
|
||||
m_Color32MeshGO = new GameObject("Color32Mesh");
|
||||
CanvasRenderer color32MeshCanvasRenderer = m_Color32MeshGO.AddComponent<CanvasRenderer>();
|
||||
RectTransform color32MeshRectTransform = m_Color32MeshGO.AddComponent<RectTransform>();
|
||||
color32MeshRectTransform.pivot = color32MeshRectTransform.anchorMin = color32MeshRectTransform.anchorMax = Vector2.zero;
|
||||
m_Color32MeshGO.transform.SetParent(m_CanvasGO.transform);
|
||||
|
||||
Material material = new Material(Shader.Find("UI/Default"));
|
||||
|
||||
// Setup Color mesh and add it to Color CanvasRenderer
|
||||
Mesh meshColor = new Mesh();
|
||||
meshColor.vertices = new Vector3[3] { new Vector3(0, 0, 0), new Vector3(0, 10, 0), new Vector3(10, 0, 0) };
|
||||
meshColor.triangles = new int[3] { 0, 1, 2 };
|
||||
meshColor.normals = new Vector3[3] { Vector3.zero, Vector3.zero, Vector3.zero };
|
||||
meshColor.colors = new Color[3] { Color.white, Color.white, Color.white };
|
||||
meshColor.uv = new Vector2[3] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 0) };
|
||||
|
||||
colorMeshCanvasRenderer.SetMesh(meshColor);
|
||||
colorMeshCanvasRenderer.SetMaterial(material, null);
|
||||
|
||||
// Setup Color32 mesh and add it to Color32 CanvasRenderer
|
||||
Mesh meshColor32 = new Mesh();
|
||||
meshColor32.vertices = new Vector3[3] { new Vector3(10, 0, 0), new Vector3(10, 10, 0), new Vector3(20, 0, 0) };
|
||||
meshColor32.triangles = new int[3] { 0, 1, 2 };
|
||||
meshColor32.normals = new Vector3[3] { Vector3.zero, Vector3.zero, Vector3.zero };
|
||||
meshColor32.colors32 = new Color32[3] { Color.white, Color.white, Color.white };
|
||||
meshColor32.uv = new Vector2[3] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 0) };
|
||||
|
||||
color32MeshCanvasRenderer.SetMesh(meshColor32);
|
||||
color32MeshCanvasRenderer.SetMaterial(material, null);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasGO);
|
||||
GameObject.DestroyImmediate(m_ScreenTexture);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CheckMeshColorsAndColors32Matches()
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
// Create a Texture2D
|
||||
m_ScreenTexture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
|
||||
m_ScreenTexture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
|
||||
m_ScreenTexture.Apply();
|
||||
|
||||
Color screenPixelColorForMeshColor = m_ScreenTexture.GetPixel(1, 0);
|
||||
Color screenPixelColorForMesh32Color = m_ScreenTexture.GetPixel(11, 0);
|
||||
|
||||
Assert.That(screenPixelColorForMesh32Color, Is.EqualTo(screenPixelColorForMeshColor).Using(new ColorEqualityComparer(0.0f)), "UI Mesh with Colors does not match UI Mesh with Colors32");
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9390296e78291b543b2f4a9761ef8139
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[TestFixture]
|
||||
[UnityPlatform(include = new RuntimePlatform[] { RuntimePlatform.OSXEditor, RuntimePlatform.LinuxEditor, RuntimePlatform.WindowsEditor })]
|
||||
[Category("RegressionTest")]
|
||||
[Description("CoveredBugID = 904415")]
|
||||
public class CoroutineWorksIfUIObjectIsAttached
|
||||
{
|
||||
GameObject m_CanvasMaster;
|
||||
GameObject m_ImageObject;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_CanvasMaster = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
|
||||
m_ImageObject = new GameObject("Image", typeof(Image));
|
||||
m_ImageObject.SetActive(false);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CoroutineWorksOnAttachingUIObject()
|
||||
{
|
||||
// Generating Basic scene
|
||||
m_CanvasMaster.AddComponent<CoroutineObject>();
|
||||
|
||||
yield return null;
|
||||
|
||||
m_ImageObject.transform.SetParent(m_CanvasMaster.transform);
|
||||
m_ImageObject.AddComponent<BugObject>();
|
||||
m_ImageObject.SetActive(true);
|
||||
|
||||
yield return null;
|
||||
yield return null;
|
||||
yield return null;
|
||||
|
||||
Assert.That(m_CanvasMaster.GetComponent<CoroutineObject>().coroutineCount, Is.GreaterThan(1), "The Coroutine wasn't supposed to stop but continue to run, something made it stopped");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasMaster);
|
||||
GameObject.DestroyImmediate(m_ImageObject);
|
||||
}
|
||||
}
|
||||
|
||||
public class BugObject : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
GameObject newObject = new GameObject("NewGameObjectThatTriggersBug");
|
||||
newObject.transform.SetParent(transform);
|
||||
newObject.AddComponent<Text>();
|
||||
}
|
||||
}
|
||||
|
||||
public class CoroutineObject : MonoBehaviour
|
||||
{
|
||||
public int coroutineCount { get; private set; }
|
||||
|
||||
public IEnumerator Start()
|
||||
{
|
||||
// This coroutine should not stop and continue adding to the timer
|
||||
while (true)
|
||||
{
|
||||
coroutineCount++;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8573c56c34e616248a3881b2c56280ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
class CreateSceneUtility
|
||||
{
|
||||
public static void CreateScene(string sceneName, Action delegateToExecute)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
string scenePath = "Assets/" + sceneName + ".unity";
|
||||
var initScene = SceneManager.GetActiveScene();
|
||||
var list = UnityEditor.EditorBuildSettings.scenes.ToList();
|
||||
var newScene = UnityEditor.SceneManagement.EditorSceneManager.NewScene(UnityEditor.SceneManagement.NewSceneSetup.DefaultGameObjects, UnityEditor.SceneManagement.NewSceneMode.Additive);
|
||||
GameObject.DestroyImmediate(Camera.main.GetComponent<AudioListener>());
|
||||
delegateToExecute();
|
||||
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(newScene, scenePath);
|
||||
UnityEditor.SceneManagement.EditorSceneManager.UnloadSceneAsync(newScene);
|
||||
|
||||
list.Add(new UnityEditor.EditorBuildSettingsScene(scenePath, true));
|
||||
UnityEditor.EditorBuildSettings.scenes = list.ToArray();
|
||||
SceneManager.SetActiveScene(initScene);
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db339ef553721e94999125c0b9f909dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,102 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
public class NestedCanvas : IPrebuildSetup
|
||||
{
|
||||
Object m_GO1;
|
||||
Object m_GO2;
|
||||
|
||||
const string kPrefabPath = "Assets/Resources/NestedCanvasPrefab.prefab";
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
var rootGO = new GameObject("RootGO");
|
||||
|
||||
var rootCanvasGO = new GameObject("Canvas", typeof(Canvas), typeof(CanvasGroup));
|
||||
rootCanvasGO.transform.SetParent(rootGO.transform);
|
||||
|
||||
var nestedCanvas = new GameObject("Nested Canvas", typeof(Canvas), typeof(Image));
|
||||
nestedCanvas.transform.SetParent(rootCanvasGO.transform);
|
||||
|
||||
var nestedCanvasCamera = new GameObject("Nested Canvas Camera", typeof(Camera));
|
||||
nestedCanvasCamera.transform.SetParent(rootCanvasGO.transform);
|
||||
|
||||
var rootCanvas = rootCanvasGO.GetComponent<Canvas>();
|
||||
rootCanvas.renderMode = RenderMode.WorldSpace;
|
||||
rootCanvas.worldCamera = nestedCanvasCamera.GetComponent<Camera>();
|
||||
|
||||
if (!Directory.Exists("Assets/Resources/"))
|
||||
Directory.CreateDirectory("Assets/Resources/");
|
||||
|
||||
UnityEditor.PrefabUtility.SaveAsPrefabAsset(rootGO, kPrefabPath);
|
||||
GameObject.DestroyImmediate(rootGO);
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
[Description("[UI] Button does not interact after nested canvas is used(case 892913)")]
|
||||
public IEnumerator WorldCanvas_CanFindCameraAfterDisablingAndEnablingRootCanvas()
|
||||
{
|
||||
m_GO1 = Object.Instantiate(Resources.Load("NestedCanvasPrefab"));
|
||||
yield return null;
|
||||
|
||||
var nestedCanvasGo = GameObject.Find("Nested Canvas");
|
||||
var nestedCanvas = nestedCanvasGo.GetComponent<Canvas>();
|
||||
Assert.IsNotNull(nestedCanvas.worldCamera, "Expected the nested canvas worldCamera to NOT be null after loading the scene.");
|
||||
|
||||
nestedCanvasGo.transform.parent.gameObject.SetActive(false);
|
||||
nestedCanvasGo.transform.parent.gameObject.SetActive(true);
|
||||
Assert.IsNotNull(nestedCanvas.worldCamera, "Expected the nested canvas worldCamera to NOT be null after the parent canvas has been re-enabled.");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator WorldCanvas_CanFindTheSameCameraAfterDisablingAndEnablingRootCanvas()
|
||||
{
|
||||
m_GO2 = Object.Instantiate(Resources.Load("NestedCanvasPrefab"));
|
||||
yield return null;
|
||||
|
||||
var nestedCanvasGo = GameObject.Find("Nested Canvas");
|
||||
var nestedCanvas = nestedCanvasGo.GetComponent<Canvas>();
|
||||
var worldCamera = nestedCanvas.worldCamera;
|
||||
nestedCanvasGo.transform.parent.gameObject.SetActive(false);
|
||||
nestedCanvasGo.transform.parent.gameObject.SetActive(true);
|
||||
Assert.AreEqual(worldCamera, nestedCanvas.worldCamera, "Expected the same world camera to be returned after the root canvas was disabled and then re-enabled.");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator NestedCanvasHasProperInheritedAlpha()
|
||||
{
|
||||
GameObject root = (GameObject)Object.Instantiate(Resources.Load("NestedCanvasPrefab"));
|
||||
CanvasGroup group = root.GetComponentInChildren<CanvasGroup>();
|
||||
Image image = root.GetComponentInChildren<Image>();
|
||||
|
||||
group.alpha = 0.5f;
|
||||
|
||||
yield return null;
|
||||
|
||||
Assert.True(image.canvasRenderer.GetInheritedAlpha() == 0.5f);
|
||||
GameObject.DestroyImmediate(root);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_GO1);
|
||||
GameObject.DestroyImmediate(m_GO2);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OneTimeTearDown()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset(kPrefabPath);
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc8d686a4c18b8d49bb1db4150de0459
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
|
||||
public class NestedCanvasMaintainsCorrectSize : IPrebuildSetup
|
||||
{
|
||||
BridgeScriptForRetainingObjects m_BridgeComponent;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var canvasGO = new GameObject("Canvas", typeof(Canvas));
|
||||
canvasGO.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
var nestedCanvasGO = new GameObject("NestedCanvas", typeof(Canvas));
|
||||
nestedCanvasGO.transform.SetParent(canvasGO.transform);
|
||||
|
||||
var rectTransform = (RectTransform)nestedCanvasGO.transform;
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.anchorMax = Vector2.one;
|
||||
rectTransform.anchoredPosition = Vector2.zero;
|
||||
rectTransform.sizeDelta = new Vector2(-20f, -20f);
|
||||
|
||||
var bridgeObject = GameObject.Find(BridgeScriptForRetainingObjects.bridgeObjectName) ?? new GameObject(BridgeScriptForRetainingObjects.bridgeObjectName);
|
||||
var component = bridgeObject.GetComponent<BridgeScriptForRetainingObjects>() ?? bridgeObject.AddComponent<BridgeScriptForRetainingObjects>();
|
||||
component.canvasGO = canvasGO;
|
||||
component.nestedCanvasGO = nestedCanvasGO;
|
||||
|
||||
canvasGO.SetActive(false);
|
||||
nestedCanvasGO.SetActive(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_BridgeComponent = GameObject.Find(BridgeScriptForRetainingObjects.bridgeObjectName).GetComponent<BridgeScriptForRetainingObjects>();
|
||||
m_BridgeComponent.canvasGO.SetActive(true);
|
||||
m_BridgeComponent.nestedCanvasGO.SetActive(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NestedCanvasMaintainsCorrectSizeAtGameStart()
|
||||
{
|
||||
var rectTransform = (RectTransform)m_BridgeComponent.nestedCanvasGO.transform;
|
||||
Assert.That(rectTransform.anchoredPosition, Is.EqualTo(Vector2.zero));
|
||||
Assert.That(rectTransform.sizeDelta, Is.EqualTo(new Vector2(-20f, -20f)));
|
||||
Assert.That(rectTransform.anchorMin, Is.EqualTo(Vector2.zero));
|
||||
Assert.That(rectTransform.anchorMax, Is.EqualTo(Vector2.one));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_BridgeComponent.canvasGO);
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be07f70ee67e6d74e851a9333719bbb6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.Profiling;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEditor;
|
||||
|
||||
[TestFixture]
|
||||
[UnityPlatform(include = new RuntimePlatform[] { RuntimePlatform.OSXEditor, RuntimePlatform.LinuxEditor, RuntimePlatform.WindowsEditor })]
|
||||
[Category("RegressionTest")]
|
||||
[Description("CoveredBugID = 883807, CoveredBugDescription = \"Object::GetInstanceID crash when trying to switch canvas\"")]
|
||||
public class NoActiveCameraInSceneDoesNotCrashEditor : IPrebuildSetup
|
||||
{
|
||||
Scene m_InitScene;
|
||||
const string k_SceneName = "NoActiveCameraInSceneDoesNotCrashEditorScene";
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Action codeToExecute = delegate()
|
||||
{
|
||||
UnityEditor.EditorApplication.ExecuteMenuItem("GameObject/UI/Legacy/Button");
|
||||
};
|
||||
|
||||
CreateSceneUtility.CreateScene(k_SceneName, codeToExecute);
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_InitScene = SceneManager.GetActiveScene();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator EditorShouldNotCrashWithoutActiveCamera()
|
||||
{
|
||||
AsyncOperation operationResult = SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
|
||||
yield return operationResult;
|
||||
|
||||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
|
||||
|
||||
Profiler.enabled = true;
|
||||
Camera.main.gameObject.SetActive(false);
|
||||
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
Assert.That(Profiler.enabled, Is.True, "Expected the profiler to be enabled. Unable to test if the profiler will crash the editor if it is not enabled.");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
SceneManager.SetActiveScene(m_InitScene);
|
||||
SceneManager.UnloadSceneAsync(k_SceneName);
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset("Assets/" + k_SceneName + ".unity");
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c21cfda3336137438c3001d40564be0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,47 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Graphics
|
||||
{
|
||||
[Category("RegressionTest")]
|
||||
[Description("CoveredBugID = 1395695, CoveredBugDescription = \"RectMask2D hides all content when parented from other display to first dislpay in the Game view window\"")]
|
||||
public class RectMask2DReparentedToDifferentCanvas
|
||||
{
|
||||
GameObject m_GameObjectA;
|
||||
GameObject m_GameObjectB;
|
||||
Canvas m_CanvasA;
|
||||
Canvas m_CanvasB;
|
||||
RectMask2D m_Mask;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_GameObjectA = new GameObject("Canvas A");
|
||||
m_GameObjectB = new GameObject("Canvas B");
|
||||
m_CanvasA = m_GameObjectA.AddComponent<Canvas>();
|
||||
m_CanvasB = m_GameObjectB.AddComponent<Canvas>();
|
||||
|
||||
var rectMaskGameObject = new GameObject("RectMask2D");
|
||||
m_Mask = rectMaskGameObject.AddComponent<RectMask2D>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Object.DestroyImmediate(m_Mask.gameObject);
|
||||
Object.DestroyImmediate(m_GameObjectA);
|
||||
Object.DestroyImmediate(m_GameObjectB);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReparentingRectMask2D_UpdatesCanvas()
|
||||
{
|
||||
m_Mask.transform.SetParent(m_GameObjectA.transform);
|
||||
Assert.AreSame(m_CanvasA, m_Mask.Canvas);
|
||||
|
||||
m_Mask.transform.SetParent(m_GameObjectB.transform);
|
||||
Assert.AreSame(m_CanvasB, m_Mask.Canvas, "Expected Canvas to be updated after parent changed.");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ba506934dc2ce14591a37f3b00dca92
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Graphics
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("RegressionTest")]
|
||||
[Description(
|
||||
"CoveredBugID = 782957, CoveredBugDescription = \"Some element from scroll view are invisible when they're masked with RectMask2D and sub-canvases\"")]
|
||||
public class RectMask2DWithNestedCanvasCullsUsingCorrectCanvasRect
|
||||
{
|
||||
GameObject m_RootCanvasGO;
|
||||
GameObject m_MaskGO;
|
||||
GameObject m_ImageGO;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_RootCanvasGO = new GameObject("Canvas");
|
||||
m_MaskGO = new GameObject("Mask", typeof(RectMask2D));
|
||||
m_ImageGO = new GameObject("Image");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator RectMask2DShouldNotCullImagesWithCanvas()
|
||||
{
|
||||
//Root Canvas
|
||||
var canvas = m_RootCanvasGO.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
// Rectmaskk2D
|
||||
var maskRect = m_MaskGO.GetComponent<RectTransform>();
|
||||
maskRect.sizeDelta = new Vector2(200, 200);
|
||||
|
||||
// Our image that will be in the RectMask2D
|
||||
var image = m_ImageGO.AddComponent<Image>();
|
||||
var imageRenderer = m_ImageGO.GetComponent<CanvasRenderer>();
|
||||
var imageRect = m_ImageGO.GetComponent<RectTransform>();
|
||||
m_ImageGO.AddComponent<Canvas>();
|
||||
imageRect.sizeDelta = new Vector2(10, 10);
|
||||
|
||||
m_MaskGO.transform.SetParent(canvas.transform);
|
||||
image.transform.SetParent(m_MaskGO.transform);
|
||||
imageRect.position = maskRect.position = Vector3.zero;
|
||||
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
|
||||
Assert.That(imageRenderer.cull, Is.False,
|
||||
"Expected image(with canvas) to not be culled by the RectMask2D but it was.");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_RootCanvasGO);
|
||||
GameObject.DestroyImmediate(m_MaskGO);
|
||||
GameObject.DestroyImmediate(m_ImageGO);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 735d54f21944f834f931716514c87a84
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityEditor;
|
||||
|
||||
[TestFixture]
|
||||
public class RectTransformValidAfterEnable : IPrebuildSetup
|
||||
{
|
||||
const string kSceneName = "DisabledCanvasScene";
|
||||
const string kGameObjectName = "DisabledCanvas";
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Action codeToExecute = delegate()
|
||||
{
|
||||
var canvasGameObject = new GameObject(kGameObjectName, typeof(Canvas));
|
||||
canvasGameObject.SetActive(false);
|
||||
canvasGameObject.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
canvasGameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(0, 0);
|
||||
canvasGameObject.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0);
|
||||
CanvasScaler canvasScaler = canvasGameObject.AddComponent<CanvasScaler>();
|
||||
canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
canvasScaler.referenceResolution = new Vector2(1024, 768);
|
||||
};
|
||||
CreateSceneUtility.CreateScene(kSceneName, codeToExecute);
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CheckRectTransformValidAfterEnable()
|
||||
{
|
||||
AsyncOperation operation = SceneManager.LoadSceneAsync(kSceneName, LoadSceneMode.Additive);
|
||||
yield return operation;
|
||||
|
||||
Scene scene = SceneManager.GetSceneByName(kSceneName);
|
||||
GameObject[] gameObjects = scene.GetRootGameObjects();
|
||||
GameObject canvasGameObject = null;
|
||||
foreach (GameObject gameObject in gameObjects)
|
||||
{
|
||||
if (gameObject.name == kGameObjectName)
|
||||
{
|
||||
canvasGameObject = gameObject;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.IsNotNull(canvasGameObject);
|
||||
|
||||
RectTransform rectTransform = canvasGameObject.GetComponent<RectTransform>();
|
||||
canvasGameObject.SetActive(true);
|
||||
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
Rect rect = rectTransform.rect;
|
||||
Assert.Greater(rect.width, 0);
|
||||
Assert.Greater(rect.height, 0);
|
||||
|
||||
operation = SceneManager.UnloadSceneAsync(kSceneName);
|
||||
yield return operation;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
//Manually add Assets/ and .unity as CreateSceneUtility does that for you.
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset("Assets/" + kSceneName + ".unity");
|
||||
#endif
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 811d999912a5f3f459a637aad029fbc8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,76 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
public class RectangleContainsScreenPointTest : MonoBehaviour
|
||||
{
|
||||
RectTransform m_RectTransform;
|
||||
Camera m_MainCamera;
|
||||
GameObject m_CanvasObject;
|
||||
GameObject m_RectObject;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
m_MainCamera = new GameObject("MainCamera").AddComponent<Camera>();
|
||||
m_MainCamera.transform.position = new Vector3(0, 1, -10);
|
||||
m_MainCamera.depth = -1;
|
||||
|
||||
m_CanvasObject = new GameObject("Canvas");
|
||||
Canvas m_canvas = m_CanvasObject.AddComponent<Canvas>();
|
||||
m_canvas.transform.localPosition = new Vector3(0, 1, 90);
|
||||
m_canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
m_canvas.worldCamera = m_MainCamera;
|
||||
|
||||
m_RectObject = new GameObject("RectTransformObject");
|
||||
m_RectTransform = m_RectObject.AddComponent<RectTransform>();
|
||||
m_RectTransform.SetParent(m_CanvasObject.transform, false);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Destroy(m_MainCamera.gameObject);
|
||||
Destroy(m_CanvasObject);
|
||||
Destroy(m_RectObject);
|
||||
Destroy(m_RectTransform);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RectangleContainsScreenPoint_ReturnsTrue_ForAllPointsInTheRectangle()
|
||||
{
|
||||
var fourCourners = new Vector3[4];
|
||||
m_RectTransform.GetWorldCorners(fourCourners);
|
||||
|
||||
var worldCorners = fourCourners
|
||||
.Select(p => m_MainCamera.WorldToScreenPoint(p))
|
||||
.ToArray();
|
||||
|
||||
var minValue = new Vector2(
|
||||
x: worldCorners.Min(p => p.x),
|
||||
y: worldCorners.Min(p => p.y));
|
||||
|
||||
var maxValue = new Vector2(
|
||||
x: worldCorners.Max(p => p.x),
|
||||
y: worldCorners.Max(p => p.y));
|
||||
|
||||
var steps = 10000;
|
||||
bool ErrorHit = false;
|
||||
|
||||
for (float i = 0; i < steps; i++)
|
||||
{
|
||||
var point = Vector2.Lerp(minValue, maxValue, i / steps);
|
||||
if (!RectTransformUtility.RectangleContainsScreenPoint(m_RectTransform, point, m_MainCamera))
|
||||
{
|
||||
ErrorHit = true;
|
||||
Assert.Fail("Rectangle does not Contains ScreenPoint");
|
||||
}
|
||||
}
|
||||
|
||||
if (!ErrorHit)
|
||||
{
|
||||
Assert.Pass();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08a8587e5f07fb64f88a0cbe2ebe327e
|
@@ -0,0 +1,83 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[TestFixture]
|
||||
[Category("RegressionTest")]
|
||||
[Description("Case 723062")]
|
||||
public class SiblingOrderChangesLayout
|
||||
{
|
||||
GameObject m_CanvasGO;
|
||||
GameObject m_ParentGO;
|
||||
GameObject m_Child1GO;
|
||||
GameObject m_Child2GO;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_CanvasGO = new GameObject("Canvas", typeof(Canvas));
|
||||
m_ParentGO = new GameObject("ParentRenderer");
|
||||
m_Child1GO = CreateTextObject("ChildRenderer1");
|
||||
m_Child2GO = CreateTextObject("ChildRenderer2");
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.ExecuteMenuItem("Window/General/Game");
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ReorderingSiblingChangesLayout()
|
||||
{
|
||||
m_ParentGO.transform.SetParent(m_CanvasGO.transform);
|
||||
m_Child1GO.transform.SetParent(m_ParentGO.transform);
|
||||
m_Child2GO.transform.SetParent(m_ParentGO.transform);
|
||||
|
||||
m_ParentGO.AddComponent<CanvasRenderer>();
|
||||
m_ParentGO.AddComponent<RectTransform>();
|
||||
m_ParentGO.AddComponent<VerticalLayoutGroup>();
|
||||
m_ParentGO.AddComponent<ContentSizeFitter>();
|
||||
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
Vector2 child1Pos = m_Child1GO.GetComponent<RectTransform>().anchoredPosition;
|
||||
Vector2 child2Pos = m_Child2GO.GetComponent<RectTransform>().anchoredPosition;
|
||||
|
||||
Assert.That(child1Pos, Is.Not.EqualTo(child2Pos));
|
||||
Assert.That(m_Child1GO.GetComponent<CanvasRenderer>().hasMoved, Is.False, "CanvasRenderer.hasMoved should be false");
|
||||
|
||||
m_Child2GO.transform.SetAsFirstSibling();
|
||||
Canvas.ForceUpdateCanvases();
|
||||
|
||||
Assert.That(m_Child1GO.GetComponent<CanvasRenderer>().hasMoved, Is.True, "CanvasRenderer.hasMoved should be true");
|
||||
Vector2 newChild1Pos = m_Child1GO.GetComponent<RectTransform>().anchoredPosition;
|
||||
Vector2 newChild2Pos = m_Child2GO.GetComponent<RectTransform>().anchoredPosition;
|
||||
|
||||
Assert.That(newChild1Pos, Is.EqualTo(child2Pos), "Child1 should have moved to Child2's position");
|
||||
Assert.That(newChild2Pos, Is.EqualTo(child1Pos), "Child2 should have moved to Child1's position");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasGO);
|
||||
}
|
||||
|
||||
// Factory method for creating UI text objects taken from the original bug repro scene:
|
||||
private GameObject CreateTextObject(string name)
|
||||
{
|
||||
GameObject outputTextGameObject = new GameObject("OutputContent", typeof(CanvasRenderer));
|
||||
|
||||
RectTransform outputTextTransform = outputTextGameObject.AddComponent<RectTransform>();
|
||||
outputTextTransform.pivot = new Vector2(0.5f, 0);
|
||||
outputTextTransform.anchorMin = Vector2.zero;
|
||||
outputTextTransform.anchorMax = new Vector2(1, 0);
|
||||
outputTextTransform.anchoredPosition = Vector2.zero;
|
||||
outputTextTransform.sizeDelta = Vector2.zero;
|
||||
|
||||
Text outputText = outputTextGameObject.AddComponent<Text>();
|
||||
outputText.text = "Hello World!";
|
||||
outputTextGameObject.name = name;
|
||||
return outputTextGameObject;
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c32df609537c54c46adf92992a673693
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user