mirror of
https://github.com/Project-Redacted/Highscores-Server.git
synced 2025-05-18 01:14:56 +00:00
Add example Unity Project
This commit is contained in:
parent
fda7ff28dd
commit
e3acdb9d6b
7122 changed files with 505543 additions and 2 deletions
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 936bea4b2545c4a4fad2e623b0f6371f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b86b117346968ac4d9cc63e4385becb7
|
||||
folderAsset: yes
|
||||
timeCreated: 1459501450
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,40 @@
|
|||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEditor;
|
||||
|
||||
public class AssertionFailureOnOutputVertexCount
|
||||
{
|
||||
const string scenePath = "Assets/AssertionFailureOnOutputVertexCountTestScene.unity";
|
||||
[Test]
|
||||
public void AssertionFailureOnOutputVertexCountTest()
|
||||
{
|
||||
var newScene = EditorSceneManager.NewScene(UnityEditor.SceneManagement.NewSceneSetup.DefaultGameObjects, UnityEditor.SceneManagement.NewSceneMode.Single);
|
||||
|
||||
var canvasMaster = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
|
||||
var canvasChild = new GameObject("Canvas Child", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
|
||||
canvasChild.transform.SetParent(canvasMaster.transform);
|
||||
|
||||
var panel1 = new GameObject("Panel", typeof(CanvasRenderer), typeof(UnityEngine.UI.Image));
|
||||
panel1.transform.SetParent(canvasMaster.transform);
|
||||
|
||||
var panel2 = new GameObject("Panel", typeof(CanvasRenderer), typeof(UnityEngine.UI.Image));
|
||||
panel2.transform.SetParent(canvasChild.transform);
|
||||
|
||||
// Saving a scene would trigger the error case 893551
|
||||
EditorSceneManager.SaveScene(newScene, scenePath);
|
||||
Debug.Log("Success");
|
||||
|
||||
LogAssert.Expect(LogType.Log, "Success");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset(scenePath);
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bede4033d9f359b41878c4cda6a910b3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,50 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
public class CanvasElementsMaintainValidPositionsWhenCameraOrthoSizeIsZero
|
||||
{
|
||||
GameObject image;
|
||||
GameObject canvas;
|
||||
GameObject camera;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
canvas = new GameObject("Canvas", typeof(Canvas));
|
||||
|
||||
image = new GameObject("Image", typeof(Image));
|
||||
image.transform.SetParent(canvas.transform);
|
||||
|
||||
camera = new GameObject("Camera", typeof(Camera));
|
||||
var cameraComponent = camera.GetComponent<Camera>();
|
||||
cameraComponent.orthographic = true;
|
||||
|
||||
var canvasComponent = canvas.GetComponent<Canvas>();
|
||||
canvasComponent.worldCamera = camera.GetComponent<Camera>();
|
||||
canvasComponent.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestCanvasElementsMaintainValidPositionsWhenCameraOrthoSizeIsZero()
|
||||
{
|
||||
var cameraComponent = camera.GetComponent<Camera>();
|
||||
cameraComponent.orthographicSize = 0;
|
||||
yield return null;
|
||||
|
||||
Assert.AreNotEqual(image.transform.position.x, float.NaN);
|
||||
Assert.AreNotEqual(image.transform.position.y, float.NaN);
|
||||
|
||||
|
||||
cameraComponent.orthographicSize = 2;
|
||||
yield return null;
|
||||
|
||||
Assert.AreEqual(image.transform.position.x, 0.0f);
|
||||
Assert.AreEqual(image.transform.position.y, 0.0f);
|
||||
|
||||
Assert.Pass();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 35a0d10199de49f4db0128003bfd3bda
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,47 @@
|
|||
using UnityEngine;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[TestFixture]
|
||||
[Category("RegressionTest")]
|
||||
[Description("CoveredBugID = 913932")]
|
||||
public class CanvasWidthAssertionErrorWithRectTransform
|
||||
{
|
||||
GameObject m_CanvasMaster;
|
||||
GameObject m_CanvasChild;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_CanvasMaster = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
|
||||
m_CanvasChild = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanvasWidthAssertionErrorCheckOnModifyingRectTransform()
|
||||
{
|
||||
// Creating canvas and child canvas
|
||||
m_CanvasChild.transform.SetParent(m_CanvasMaster.transform);
|
||||
|
||||
// Getting the rect Transform and modifying it
|
||||
RectTransform rt = m_CanvasChild.GetComponent<RectTransform>();
|
||||
|
||||
rt.anchorMin = new Vector2(0, 0);
|
||||
rt.anchorMax = new Vector2(1, 1);
|
||||
|
||||
rt.offsetMin = new Vector2(rt.offsetMin.x, 1000);
|
||||
rt.offsetMax = new Vector2(rt.offsetMax.x, 200);
|
||||
|
||||
rt.offsetMin = new Vector2(rt.offsetMin.y, 1);
|
||||
rt.offsetMax = new Vector2(rt.offsetMax.y, 0);
|
||||
|
||||
//Assertion failed: Assertion failed on expression: 'width >= 0 should not happen
|
||||
Assert.Pass();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasMaster);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4585b5feb801bdb44b0e5eafdd95a3be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,49 @@
|
|||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
[Category("Canvas")]
|
||||
public class RootCanvasTests : TestBehaviourBase<UnityEngine.Canvas>
|
||||
{
|
||||
// A simple nested canvas hierarchy
|
||||
// m_TestObject
|
||||
// └ rootCanvasChild
|
||||
// └ emptyChildGameObject
|
||||
// └ baseCanvas
|
||||
private UnityEngine.Canvas rootCanvasChild;
|
||||
private GameObject emptyChildGameObject;
|
||||
private UnityEngine.Canvas baseCanvas;
|
||||
|
||||
[SetUp]
|
||||
public override void TestSetup()
|
||||
{
|
||||
base.TestSetup();
|
||||
|
||||
var rootChildGO = new GameObject("root child");
|
||||
rootCanvasChild = rootChildGO.AddComponent<Canvas>();
|
||||
|
||||
emptyChildGameObject = new GameObject("empty");
|
||||
|
||||
var baseGO = new GameObject("base");
|
||||
baseCanvas = baseGO.AddComponent<Canvas>();
|
||||
|
||||
baseCanvas.transform.SetParent(emptyChildGameObject.transform);
|
||||
emptyChildGameObject.transform.SetParent(rootChildGO.transform);
|
||||
rootChildGO.transform.SetParent(m_TestObject.transform);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsRootCanvasTest()
|
||||
{
|
||||
Assert.IsFalse(baseCanvas.isRootCanvas);
|
||||
Assert.IsFalse(rootCanvasChild.isRootCanvas);
|
||||
Assert.IsTrue(m_TestObject.isRootCanvas);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CorrectRootCanvasReturned()
|
||||
{
|
||||
Assert.AreEqual(m_TestObject, m_TestObject.rootCanvas);
|
||||
Assert.AreEqual(m_TestObject, rootCanvasChild.rootCanvas);
|
||||
Assert.AreEqual(m_TestObject, baseCanvas.rootCanvas);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 798968d841703b54bb9d08b1da6bc52f
|
||||
timeCreated: 1459501500
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
using UnityEngine;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
public class UISystemProfilerAddMarkerWithNullObjectDoesNotCrash
|
||||
{
|
||||
[Test]
|
||||
public void AddMarkerShouldNotCrashWithNullObject()
|
||||
{
|
||||
UISystemProfilerApi.AddMarker("Test", null);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0ca81982e37e893498abf804c12a22c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ae242449e9279d44789513b922d3178a
|
||||
folderAsset: yes
|
||||
timeCreated: 1493922593
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,41 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEditor.SceneManagement;
|
||||
|
||||
public class ChangingHierarchyOfCanvasRenderer
|
||||
{
|
||||
[Test]
|
||||
public void ChangingHierarchyOfCanvasRenderer_DoesntCrash()
|
||||
{
|
||||
// Canvas
|
||||
// - Middle
|
||||
// - Renderer
|
||||
// OtherCanvas
|
||||
var canvasObject = new GameObject("Canvas");
|
||||
canvasObject.AddComponent<Canvas>();
|
||||
|
||||
var otherCanvasObject = new GameObject("OtherCanvas");
|
||||
otherCanvasObject.AddComponent<Canvas>();
|
||||
|
||||
var middleObject = new GameObject("Middle");
|
||||
middleObject.transform.parent = canvasObject.transform;
|
||||
|
||||
var renderObject = new GameObject("Render");
|
||||
renderObject.AddComponent<CanvasRenderer>();
|
||||
renderObject.transform.parent = middleObject.transform;
|
||||
renderObject.SetActive(false);
|
||||
|
||||
// Translation causes IgnoreNextTransformChanged to be set on Renderer
|
||||
canvasObject.transform.Translate(1, 1, 1);
|
||||
// Reparenting after ignore
|
||||
middleObject.transform.parent = otherCanvasObject.transform;
|
||||
|
||||
// Destroy the original canvas, and create a new scene to force destruction of everything else
|
||||
GameObject.DestroyImmediate(canvasObject);
|
||||
EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
|
||||
|
||||
Assert.Pass();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c825bad77a42dd341a8f0a5ef9cd5f4c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,58 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ParentCanvasIsSane
|
||||
{
|
||||
GameObject rootCanvas;
|
||||
GameObject rootObject;
|
||||
GameObject child1;
|
||||
CanvasGroup c1CanvasGroup;
|
||||
GameObject child2;
|
||||
GameObject child3;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
// root GO
|
||||
// root Canvas
|
||||
// L child1 GO (RectTransform, CanvasGroup)
|
||||
// L child2 GO (RectTransform)
|
||||
// L child3 GO (Image)
|
||||
|
||||
rootCanvas = new GameObject("root Canvas");
|
||||
rootCanvas.AddComponent<Canvas>();
|
||||
rootCanvas.AddComponent<CanvasScaler>();
|
||||
|
||||
rootObject = new GameObject("root GO");
|
||||
|
||||
child1 = new GameObject("child1 GO");
|
||||
child1.AddComponent<RectTransform>();
|
||||
c1CanvasGroup = child1.AddComponent<CanvasGroup>();
|
||||
|
||||
child2 = new GameObject("child2 GO");
|
||||
child2.AddComponent<RectTransform>();
|
||||
|
||||
child3 = new GameObject("child3 GO");
|
||||
child3.AddComponent<Image>();
|
||||
|
||||
child3.transform.SetParent(child2.transform);
|
||||
child2.transform.SetParent(child1.transform);
|
||||
child1.transform.SetParent(rootCanvas.transform);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator RecalculatingAlphaOnReparentedInactiveObjectsDoesNotCrash()
|
||||
{
|
||||
Assert.IsNotNull(child3.GetComponent<CanvasRenderer>());
|
||||
|
||||
c1CanvasGroup.alpha = 0.5f;
|
||||
child1.SetActive(false);
|
||||
child1.transform.SetParent(rootObject.transform, true);
|
||||
|
||||
// This will crash if child3.GetComponent<CanvasRenderer>().m_ParentCanvas is not null.
|
||||
yield return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dcb49b07db5e5f64e876b498105314f1
|
||||
timeCreated: 1493922633
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 98d14ab1acf42df4f88a0561822ac807
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEditor;
|
||||
using NUnit.Framework;
|
||||
|
||||
public class InterceptedEventsPreviewTests
|
||||
{
|
||||
[Test]
|
||||
public void InterceptedEventsPreviewCacheUsingTypeCacheReturnsSameTypes()
|
||||
{
|
||||
var typeCacheEventInterfaces = new List<Type>();
|
||||
TypeCache.TypeCollection types = TypeCache.GetTypesDerivedFrom<IEventSystemHandler>();
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (!type.IsInterface)
|
||||
continue;
|
||||
|
||||
typeCacheEventInterfaces.Add(type);
|
||||
}
|
||||
|
||||
var appDomainEventInterfaces = new List<Type>();
|
||||
foreach (var type in GetAccessibleTypesInLoadedAssemblies())
|
||||
{
|
||||
if (!type.IsInterface)
|
||||
continue;
|
||||
|
||||
appDomainEventInterfaces.Add(type);
|
||||
}
|
||||
|
||||
Assert.AreNotEqual(typeCacheEventInterfaces.Count, appDomainEventInterfaces.Count, "Did not find the same number of EventInterface types");
|
||||
|
||||
for (int i = 0; i < typeCacheEventInterfaces.Count; ++i)
|
||||
{
|
||||
Assert.Contains(typeCacheEventInterfaces[i], appDomainEventInterfaces);
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<Type> GetAccessibleTypesInLoadedAssemblies()
|
||||
{
|
||||
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
for (var i = 0; i < assemblies.Length; ++i)
|
||||
{
|
||||
Type[] types;
|
||||
var assembly = assemblies[i];
|
||||
|
||||
if (assembly == null)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
types = assembly.GetTypes();
|
||||
}
|
||||
catch (ReflectionTypeLoadException e)
|
||||
{
|
||||
// assembly.GetTypes() might fail in case the Assembly cannot resolve all its references,
|
||||
// or in case it was built targetting a newer version of .NET.
|
||||
// In case the resolution fails for some types, we can still access the ones that have been
|
||||
// properly loaded.
|
||||
types = e.Types;
|
||||
}
|
||||
|
||||
for (var j = 0; j < types.Length; ++j)
|
||||
{
|
||||
var type = types[j];
|
||||
if (type == null)
|
||||
continue;
|
||||
|
||||
yield return type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2aff4fada0516c64a8537a20bfe1b699
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c16c54fe03afb5740bcc0a2a295cb79d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,45 @@
|
|||
using NUnit.Framework;
|
||||
|
||||
namespace Core.InputField
|
||||
{
|
||||
public class CharacterLimitValidation : TestBehaviourBase<UnityEngine.UI.InputField>
|
||||
{
|
||||
[Test]
|
||||
public void LimitCanNotBeNegative()
|
||||
{
|
||||
const int testValue = -1;
|
||||
m_TestObject.characterLimit = testValue;
|
||||
Assert.AreNotEqual(testValue, m_TestObject.characterLimit);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TextLengthShorterThanLimit()
|
||||
{
|
||||
const string testValue = "Test";
|
||||
m_TestObject.characterLimit = 10;
|
||||
m_TestObject.text = testValue;
|
||||
|
||||
Assert.AreEqual(testValue, m_TestObject.text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TextLengthEqualToLimit()
|
||||
{
|
||||
const string testValue = "0123456789";
|
||||
m_TestObject.characterLimit = 10;
|
||||
m_TestObject.text = testValue;
|
||||
|
||||
Assert.AreEqual(testValue, m_TestObject.text);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TextLengthGreaterThanLimit()
|
||||
{
|
||||
m_TestObject.characterLimit = 10;
|
||||
m_TestObject.text = "01234567891234567890";
|
||||
|
||||
Assert.AreEqual(10, m_TestObject.text.Length);
|
||||
Assert.AreEqual("0123456789", m_TestObject.text);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4b8be68229770db4ea3c78ab0d854325
|
||||
timeCreated: 1456921340
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,94 @@
|
|||
using NUnit.Framework;
|
||||
using ContentType = UnityEngine.UI.InputField.ContentType;
|
||||
|
||||
namespace Core.InputField
|
||||
{
|
||||
public class ContentValidation : TestBehaviourBase<UnityEngine.UI.InputField>
|
||||
{
|
||||
[Test]
|
||||
[TestCase(ContentType.Alphanumeric, "0", "0")]
|
||||
[TestCase(ContentType.Alphanumeric, "1", "1")]
|
||||
[TestCase(ContentType.Alphanumeric, "123456", "123456")]
|
||||
[TestCase(ContentType.Alphanumeric, "0123456", "0123456")]
|
||||
[TestCase(ContentType.Alphanumeric, "111110123456", "111110123456")]
|
||||
[TestCase(ContentType.Alphanumeric, "123456", "123456")]
|
||||
[TestCase(ContentType.Alphanumeric, "-1.0", "10")]
|
||||
[TestCase(ContentType.Alphanumeric, "-00.45", "0045")]
|
||||
[TestCase(ContentType.Alphanumeric, "-1111101.23456", "111110123456")]
|
||||
[TestCase(ContentType.Alphanumeric, "Test", "Test")]
|
||||
[TestCase(ContentType.Alphanumeric, "-1-", "1")]
|
||||
[TestCase(ContentType.Alphanumeric, "--1", "1")]
|
||||
[TestCase(ContentType.Alphanumeric, "123456abc", "123456abc")]
|
||||
[TestCase(ContentType.Alphanumeric, "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789", "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789")]
|
||||
|
||||
[TestCase(ContentType.DecimalNumber, "0", "0")]
|
||||
[TestCase(ContentType.DecimalNumber, "1", "1")]
|
||||
[TestCase(ContentType.DecimalNumber, "123456", "123456")]
|
||||
[TestCase(ContentType.DecimalNumber, "0123456", "0123456")]
|
||||
[TestCase(ContentType.DecimalNumber, "111110123456", "111110123456")]
|
||||
//[TestCase(ContentType.DecimalNumber, "3.14", "3.14")]
|
||||
//[TestCase(ContentType.DecimalNumber, "1.23", "1.23")]
|
||||
//[TestCase(ContentType.DecimalNumber, "1.0", "1.0")]
|
||||
//[TestCase(ContentType.DecimalNumber, "00.45", "00.45")]
|
||||
//[TestCase(ContentType.DecimalNumber, "1111101.23456", "1111101.23456")]
|
||||
//[TestCase(ContentType.DecimalNumber, "-1", "-1")]
|
||||
[TestCase(ContentType.DecimalNumber, "-123456", "-123456")]
|
||||
[TestCase(ContentType.DecimalNumber, "-0123456", "-0123456")]
|
||||
[TestCase(ContentType.DecimalNumber, "-111110123456", "-111110123456")]
|
||||
//[TestCase(ContentType.DecimalNumber, "-3.14", "-3.14")]
|
||||
//[TestCase(ContentType.DecimalNumber, "-1.23", "-1.23")]
|
||||
//[TestCase(ContentType.DecimalNumber, "-1.0", "-1.0")]
|
||||
//[TestCase(ContentType.DecimalNumber, "-00.45", "-00.45")]
|
||||
//[TestCase(ContentType.DecimalNumber, "-1111101.23456", "-1111101.23456")]
|
||||
[TestCase(ContentType.DecimalNumber, "Test", "")]
|
||||
[TestCase(ContentType.DecimalNumber, "-1-", "-1")]
|
||||
//[TestCase(ContentType.DecimalNumber, "-0", "0")]
|
||||
[TestCase(ContentType.DecimalNumber, "--1", "-1")]
|
||||
[TestCase(ContentType.DecimalNumber, "123456abc", "123456")]
|
||||
//[TestCase(ContentType.DecimalNumber, "12.34.5#6abc", "12.3456")]
|
||||
|
||||
[TestCase(ContentType.EmailAddress, "name@domain.com", "name@domain.com")]
|
||||
[TestCase(ContentType.EmailAddress, "name@@@domain.com", "name@domain.com")]
|
||||
[TestCase(ContentType.EmailAddress, "name@domain.co.uk", "name@domain.co.uk")]
|
||||
[TestCase(ContentType.EmailAddress, "name.other@domain-site.co.uk", "name.other@domain-site.co.uk")]
|
||||
[TestCase(ContentType.EmailAddress, "name!#$%&'*+-/=?^_`{|}~@domain.com", "name!#$%&'*+-/=?^_`{|}~@domain.com")]
|
||||
|
||||
[TestCase(ContentType.IntegerNumber, "0", "0")]
|
||||
[TestCase(ContentType.IntegerNumber, "1", "1")]
|
||||
[TestCase(ContentType.IntegerNumber, "123456", "123456")]
|
||||
[TestCase(ContentType.IntegerNumber, "0123456", "0123456")]
|
||||
[TestCase(ContentType.IntegerNumber, "111110123456", "111110123456")]
|
||||
[TestCase(ContentType.IntegerNumber, "-1", "-1")]
|
||||
[TestCase(ContentType.IntegerNumber, "-123456", "-123456")]
|
||||
[TestCase(ContentType.IntegerNumber, "-0123456", "-0123456")]
|
||||
[TestCase(ContentType.IntegerNumber, "-111110123456", "-111110123456")]
|
||||
[TestCase(ContentType.IntegerNumber, "3.14", "314")]
|
||||
[TestCase(ContentType.IntegerNumber, "Test", "")]
|
||||
[TestCase(ContentType.IntegerNumber, "-1-", "-1")]
|
||||
//[TestCase(ContentType.IntegerNumber, "-0", "0")]
|
||||
//[TestCase(ContentType.IntegerNumber, "-0", "")]
|
||||
[TestCase(ContentType.IntegerNumber, "--1", "-1")]
|
||||
[TestCase(ContentType.IntegerNumber, "123456abc", "123456")]
|
||||
[TestCase(ContentType.IntegerNumber, "12.34.5#6abc", "123456")]
|
||||
|
||||
[TestCase(ContentType.Name, "john smith", "John Smith")]
|
||||
[TestCase(ContentType.Name, "mary jane", "Mary Jane")]
|
||||
[TestCase(ContentType.Name, "jOHn smIth", "John Smith")]
|
||||
[TestCase(ContentType.Name, "john123 smith123", "John Smith")]
|
||||
[TestCase(ContentType.Name, "Bucky O'Hare", "Bucky O'Hare")]
|
||||
[TestCase(ContentType.Name, "bucky o'Har'e", "Bucky O'Hare")]
|
||||
[TestCase(ContentType.Name, "first second third", "First Second Third")]
|
||||
|
||||
[TestCase(ContentType.Pin, "012345", "012345")]
|
||||
[TestCase(ContentType.Pin, "012345abc", "012345")]
|
||||
[TestCase(ContentType.Pin, "0a1b2c3#45", "012345")]
|
||||
[TestCase(ContentType.Pin, "-012345", "-012345")]
|
||||
[TestCase(ContentType.Pin, " 012345", "012345")]
|
||||
public void ValueIsValidatedCorrectly(ContentType type, string testValue, string expected)
|
||||
{
|
||||
m_TestObject.contentType = type;
|
||||
m_TestObject.text = testValue;
|
||||
Assert.AreEqual(expected, m_TestObject.text);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5a2e98b03511c6f43bc645238cd40857
|
||||
timeCreated: 1457018121
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 305ca32be1aa5504aa182f583895dfe4
|
||||
folderAsset: yes
|
||||
timeCreated: 1458135852
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,42 @@
|
|||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RectMask2DCulling : TestBehaviourBase<UnityEngine.Canvas>
|
||||
{
|
||||
[Test]
|
||||
public void CullFlagNotResetWhenReparented740604()
|
||||
{
|
||||
var noMaskGameObject = new GameObject("noMaskGO");
|
||||
noMaskGameObject.AddComponent<RectTransform>();
|
||||
|
||||
var maskGameObject = new GameObject("MaskGO");
|
||||
var rectMask2D = maskGameObject.AddComponent<RectMask2D>();
|
||||
|
||||
noMaskGameObject.transform.SetParent(m_TestObject.transform);
|
||||
maskGameObject.transform.SetParent(m_TestObject.transform);
|
||||
|
||||
noMaskGameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(800, 800);
|
||||
maskGameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(400, 400);
|
||||
|
||||
var imageGameObject = new GameObject("ImageGO");
|
||||
var image = imageGameObject.AddComponent<Image>();
|
||||
imageGameObject.transform.SetParent(maskGameObject.transform);
|
||||
|
||||
imageGameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(100, 100);
|
||||
|
||||
// Start with image inside RectMask2D area so that it's no culled
|
||||
rectMask2D.PerformClipping();
|
||||
Assert.IsFalse(image.canvasRenderer.cull);
|
||||
|
||||
// Move image outside of RectMask2D so that it is culled
|
||||
imageGameObject.GetComponent<RectTransform>().position = new Vector2(275, 275);
|
||||
rectMask2D.PerformClipping();
|
||||
Assert.IsTrue(image.canvasRenderer.cull);
|
||||
|
||||
// Change parent to noMask so that it's unaffected by RectMask2D and isn't culled
|
||||
imageGameObject.transform.SetParent(noMaskGameObject.transform);
|
||||
rectMask2D.PerformClipping();
|
||||
Assert.IsFalse(image.canvasRenderer.cull);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4402dcee6e9969549bf5b33f11533208
|
||||
timeCreated: 1458135886
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,18 @@
|
|||
using UnityEngine;
|
||||
using NUnit.Framework;
|
||||
|
||||
public class RectTransformPosition
|
||||
{
|
||||
[Test]
|
||||
public void SettingPositionBeforeGameObjectIsActivatedWorks_953409()
|
||||
{
|
||||
var positionToSet = new Vector3(1, 2, 3);
|
||||
var go = new GameObject("RectTransform", typeof(RectTransform));
|
||||
|
||||
go.SetActive(false);
|
||||
go.transform.position = positionToSet;
|
||||
go.SetActive(true);
|
||||
|
||||
Assert.AreEqual(positionToSet, go.transform.position, "Expected RectTransform position to be set but it was not.");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fb660d86885d89a499a31c6ab6f26269
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4cfe5ade9a1375e40aed87618b92bd12
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,49 @@
|
|||
using NUnit.Framework;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
|
||||
[Category("Slider")]
|
||||
public class SliderRectRefernces : TestBehaviourBase<UnityEngine.UI.Slider>
|
||||
{
|
||||
private Slider slider;
|
||||
private GameObject emptyGO;
|
||||
|
||||
[SetUp]
|
||||
public override void TestSetup()
|
||||
{
|
||||
base.TestSetup();
|
||||
|
||||
var rootChildGO = new GameObject("root child");
|
||||
rootChildGO.AddComponent<Canvas>();
|
||||
|
||||
var sliderGameObject = new GameObject("Slider");
|
||||
slider = sliderGameObject.AddComponent<Slider>();
|
||||
|
||||
emptyGO = new GameObject("base", typeof(RectTransform));
|
||||
|
||||
sliderGameObject.transform.SetParent(rootChildGO.transform);
|
||||
emptyGO.transform.SetParent(sliderGameObject.transform);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssigningSelfResultsInNullReferenceField()
|
||||
{
|
||||
slider.fillRect = (RectTransform)slider.transform;
|
||||
Assert.IsNull(slider.fillRect);
|
||||
|
||||
slider.handleRect = (RectTransform)slider.transform;
|
||||
Assert.IsNull(slider.handleRect);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AssigningOtherObjectResultsInCorrectReferenceField()
|
||||
{
|
||||
slider.fillRect = (RectTransform)emptyGO.transform;
|
||||
Assert.IsNotNull(slider.fillRect);
|
||||
Assert.AreEqual(slider.fillRect, (RectTransform)emptyGO.transform);
|
||||
|
||||
slider.handleRect = (RectTransform)emptyGO.transform;
|
||||
Assert.IsNotNull(slider.handleRect);
|
||||
Assert.AreEqual(slider.handleRect, (RectTransform)emptyGO.transform);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 373b4c78c0396334288fa5ff8e7b7350
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,20 @@
|
|||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
public class TestBehaviourBase<T> where T : Behaviour
|
||||
{
|
||||
protected T m_TestObject;
|
||||
|
||||
[SetUp]
|
||||
public virtual void TestSetup()
|
||||
{
|
||||
var gameObject = new GameObject();
|
||||
m_TestObject = gameObject.AddComponent<T>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public virtual void Teardown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_TestObject.gameObject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 393b15da08c88194dbbcacd6ee15a89c
|
||||
timeCreated: 1456926887
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,9 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4f9ac6e545d53f94b9f09c85b9576f36
|
||||
folderAsset: yes
|
||||
timeCreated: 1485515713
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,60 @@
|
|||
using System;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
[Category("Text")]
|
||||
public class FontCreatedByScript
|
||||
{
|
||||
static Font CreateDefaultFontWithOneCharacter(int character)
|
||||
{
|
||||
var font = new Font();
|
||||
CharacterInfo[] characterInfo = new CharacterInfo[1];
|
||||
characterInfo[0].index = character;
|
||||
font.characterInfo = characterInfo;
|
||||
return font;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void GetCharacterInfo_FindsCharacterInfoThatIsInSet()
|
||||
{
|
||||
char character = 'A';
|
||||
int charIndex = Convert.ToInt32(character);
|
||||
|
||||
var font = CreateDefaultFontWithOneCharacter(charIndex);
|
||||
CharacterInfo result = new CharacterInfo();
|
||||
Assert.IsTrue(font.GetCharacterInfo(character, out result), "Could not find character info for '" + character + "' even though the Font contains it.");
|
||||
Assert.AreEqual(charIndex, result.index, "Incorrect character info was returned for " + character);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void GetCharacterInfo_DoesNotFindCharacterInfoThatIsNotInSet()
|
||||
{
|
||||
char character = 'A';
|
||||
char characterNotInSet = 'X';
|
||||
int charIndex = Convert.ToInt32(character);
|
||||
|
||||
var font = CreateDefaultFontWithOneCharacter(charIndex);
|
||||
CharacterInfo result;
|
||||
Assert.IsFalse(font.GetCharacterInfo(characterNotInSet, out result), "Found character info for '" + characterNotInSet + "' even though the Font does not contain it.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void HasCharacterReturns8BitChars()
|
||||
{
|
||||
char character = 'A';
|
||||
int charIndex = Convert.ToInt32(character);
|
||||
|
||||
var font = CreateDefaultFontWithOneCharacter(charIndex);
|
||||
Assert.IsTrue(font.HasCharacter(character), "HasCharacter returned false even though it should have " + character);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void HasCharacterReturns16BitChars()
|
||||
{
|
||||
char character = '\u03A9';
|
||||
int charIndex = Convert.ToInt32(character);
|
||||
|
||||
var font = CreateDefaultFontWithOneCharacter(charIndex);
|
||||
Assert.IsTrue(font.HasCharacter(character), "HasCharacter returned false even though it should have " + character);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 812aaaefaab404448a3e4db49dfa5206
|
||||
timeCreated: 1485515717
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "UnityEditor.UI.EditorTests",
|
||||
"references": [
|
||||
"UnityEditor.UI",
|
||||
"UnityEngine.UI"
|
||||
],
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": []
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7c04f0dfa9243c04681a55d90d3ff3fc
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e90cc37a5ccf4a44dbecc5b7172ec512
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,63 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Events;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
|
||||
public class UnityEventInvoke
|
||||
{
|
||||
class SimpleCounter : MonoBehaviour
|
||||
{
|
||||
public int m_Count = 0;
|
||||
|
||||
public void Add()
|
||||
{
|
||||
++m_Count;
|
||||
}
|
||||
|
||||
public void NoOp(int i)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
GameObject m_CounterObject;
|
||||
SimpleCounter Counter { get; set; }
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_CounterObject = new GameObject("Counter");
|
||||
Counter = m_CounterObject.AddComponent<SimpleCounter>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CounterObject);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Description("Using a CachedInvokableCall in a UnityEvent should not go re-trigger all the calls stored in the UnityEvent. Case-950588")]
|
||||
public void UnityEvent_InvokeCallsListenerOnce()
|
||||
{
|
||||
var _event = new UnityEvent();
|
||||
UnityEventTools.AddPersistentListener(_event, new UnityAction(Counter.Add));
|
||||
_event.SetPersistentListenerState(0, UnityEventCallState.EditorAndRuntime);
|
||||
|
||||
_event.Invoke();
|
||||
|
||||
Assert.AreEqual(1, Counter.m_Count);
|
||||
|
||||
for (int i = 1; i < 5; ++i)
|
||||
{
|
||||
UnityEventTools.AddIntPersistentListener(_event, new UnityAction<int>(Counter.NoOp), i);
|
||||
_event.SetPersistentListenerState(i, UnityEventCallState.EditorAndRuntime);
|
||||
}
|
||||
|
||||
_event.Invoke();
|
||||
|
||||
Assert.AreEqual(2, Counter.m_Count);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 977190a4db46de442aed27279d247df4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c545241cf2e56ec4997d7677f01ef43d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 239dd6edc8e5cd14585c03e09e86a747
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,149 @@
|
|||
using System.Collections;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
|
||||
public class ButtonTests : IPrebuildSetup
|
||||
{
|
||||
GameObject m_PrefabRoot;
|
||||
const string kPrefabPath = "Assets/Resources/ButtonPrefab.prefab";
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var rootGO = new GameObject("rootGo");
|
||||
var canvasGO = new GameObject("Canvas", typeof(Canvas));
|
||||
canvasGO.transform.SetParent(rootGO.transform);
|
||||
var canvas = canvasGO.GetComponent<Canvas>();
|
||||
canvas.referencePixelsPerUnit = 100;
|
||||
GameObject eventSystemGO = new GameObject("EventSystem", typeof(EventSystem));
|
||||
eventSystemGO.transform.SetParent(rootGO.transform);
|
||||
GameObject TestButtonGO = new GameObject("TestButton", typeof(RectTransform), typeof(TestButton));
|
||||
TestButtonGO.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("ButtonPrefab")) as GameObject;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_PrefabRoot);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OneTimeTearDown()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset(kPrefabPath);
|
||||
#endif
|
||||
}
|
||||
|
||||
#region Press
|
||||
|
||||
[Test]
|
||||
public void PressShouldCallClickHandler()
|
||||
{
|
||||
Button button = m_PrefabRoot.GetComponentInChildren<Button>();
|
||||
bool called = false;
|
||||
button.onClick.AddListener(() => { called = true; });
|
||||
button.OnPointerClick(new PointerEventData(m_PrefabRoot.GetComponentInChildren<EventSystem>()) { button = PointerEventData.InputButton.Left });
|
||||
Assert.True(called);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PressInactiveShouldNotCallClickHandler()
|
||||
{
|
||||
Button button = m_PrefabRoot.GetComponentInChildren<Button>();
|
||||
bool called = false;
|
||||
button.enabled = false;
|
||||
button.onClick.AddListener(() => { called = true; });
|
||||
button.OnPointerClick(new PointerEventData(m_PrefabRoot.GetComponentInChildren<EventSystem>()) { button = PointerEventData.InputButton.Left });
|
||||
Assert.False(called);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PressNotInteractableShouldNotCallClickHandler()
|
||||
{
|
||||
Button button = m_PrefabRoot.GetComponentInChildren<Button>();
|
||||
bool called = false;
|
||||
button.interactable = false;
|
||||
button.onClick.AddListener(() => { called = true; });
|
||||
button.OnPointerClick(new PointerEventData(m_PrefabRoot.GetComponentInChildren<EventSystem>()) { button = PointerEventData.InputButton.Left });
|
||||
Assert.False(called);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Submit
|
||||
|
||||
[Test]
|
||||
public void SubmitShouldCallClickHandler()
|
||||
{
|
||||
Button button = m_PrefabRoot.GetComponentInChildren<Button>();
|
||||
bool called = false;
|
||||
button.onClick.AddListener(() => { called = true; });
|
||||
button.OnSubmit(null);
|
||||
Assert.True(called);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SubmitInactiveShouldNotCallClickHandler()
|
||||
{
|
||||
Button button = m_PrefabRoot.GetComponentInChildren<Button>();
|
||||
bool called = false;
|
||||
button.enabled = false;
|
||||
button.onClick.AddListener(() => { called = true; });
|
||||
button.OnSubmit(new PointerEventData(m_PrefabRoot.GetComponentInChildren<EventSystem>()) { button = PointerEventData.InputButton.Left });
|
||||
Assert.False(called);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SubmitNotInteractableShouldNotCallClickHandler()
|
||||
{
|
||||
Button button = m_PrefabRoot.GetComponentInChildren<Button>();
|
||||
bool called = false;
|
||||
button.interactable = false;
|
||||
button.onClick.AddListener(() => { called = true; });
|
||||
button.OnSubmit(new PointerEventData(m_PrefabRoot.GetComponentInChildren<EventSystem>()) { button = PointerEventData.InputButton.Left });
|
||||
Assert.False(called);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Submit Transition
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator SubmitShouldTransitionToPressedStateAndBackToNormal()
|
||||
{
|
||||
TestButton button = m_PrefabRoot.GetComponentInChildren<TestButton>();
|
||||
Assert.True(button.IsTransitionToNormal(0));
|
||||
|
||||
button.OnSubmit(null);
|
||||
Assert.True(button.isStateNormal);
|
||||
Assert.True(button.IsTransitionToPressed(1));
|
||||
yield return new WaitWhile(() => button.StateTransitionCount == 2);
|
||||
|
||||
// 3rd transition back to normal should have started
|
||||
Assert.True(button.IsTransitionToNormal(2));
|
||||
yield return null;
|
||||
|
||||
Assert.True(button.isStateNormal);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1ef2923b9c5521948a04299da53ae750
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,30 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
|
||||
class TestButton : Button
|
||||
{
|
||||
public bool isStateNormal { get { return currentSelectionState == SelectionState.Normal; } }
|
||||
public bool isStateHighlighted { get { return currentSelectionState == SelectionState.Highlighted; } }
|
||||
public bool isStatePressed { get { return currentSelectionState == SelectionState.Pressed; } }
|
||||
public bool isStateDisabled { get { return currentSelectionState == SelectionState.Disabled; } }
|
||||
|
||||
private bool IsTransitionTo(int index, SelectionState selectionState)
|
||||
{
|
||||
return index < m_StateTransitions.Count && m_StateTransitions[index] == selectionState;
|
||||
}
|
||||
|
||||
public bool IsTransitionToNormal(int index) { return IsTransitionTo(index, SelectionState.Normal); }
|
||||
public bool IsTransitionToHighlighted(int index) { return IsTransitionTo(index, SelectionState.Highlighted); }
|
||||
public bool IsTransitionToPressed(int index) { return IsTransitionTo(index, SelectionState.Pressed); }
|
||||
public bool IsTransitionToDisabled(int index) { return IsTransitionTo(index, SelectionState.Disabled); }
|
||||
|
||||
private readonly List<SelectionState> m_StateTransitions = new List<SelectionState>();
|
||||
|
||||
public int StateTransitionCount { get { return m_StateTransitions.Count; } }
|
||||
|
||||
protected override void DoStateTransition(SelectionState state, bool instant)
|
||||
{
|
||||
m_StateTransitions.Add(state);
|
||||
base.DoStateTransition(state, instant);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4f5ed95515938d14189b094f8654d0bd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9a3557da07c729b4eb774b8e30e157a4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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>();
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
//GameObject.DestroyImmediate(m_CanvasObject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a14a59f2a5c757e469c3e4e17b798c2e
|
||||
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,24 @@
|
|||
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);
|
||||
|
||||
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,101 @@
|
|||
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);
|
||||
}
|
||||
|
||||
[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/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,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,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:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bae197be297529d4fa735fbe7c91828d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,161 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class DropdownTests : IPrebuildSetup
|
||||
{
|
||||
GameObject m_PrefabRoot;
|
||||
GameObject m_CameraGO;
|
||||
|
||||
const string kPrefabPath = "Assets/Resources/DropdownPrefab.prefab";
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var rootGO = new GameObject("rootGo");
|
||||
var canvasGO = new GameObject("Canvas", typeof(Canvas));
|
||||
var canvas = canvasGO.GetComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.WorldSpace;
|
||||
canvasGO.transform.SetParent(rootGO.transform);
|
||||
|
||||
var dropdownGO = new GameObject("Dropdown", typeof(Dropdown), typeof(RectTransform));
|
||||
var dropdownTransform = dropdownGO.GetComponent<RectTransform>();
|
||||
dropdownTransform.SetParent(canvas.transform);
|
||||
dropdownTransform.anchoredPosition = Vector2.zero;
|
||||
var dropdown = dropdownGO.GetComponent<Dropdown>();
|
||||
|
||||
var templateGO = new GameObject("Template", typeof(RectTransform));
|
||||
templateGO.SetActive(false);
|
||||
var templateTransform = templateGO.GetComponent<RectTransform>();
|
||||
templateTransform.SetParent(dropdownTransform);
|
||||
|
||||
var itemGo = new GameObject("Item", typeof(RectTransform), typeof(Toggle));
|
||||
itemGo.transform.SetParent(templateTransform);
|
||||
|
||||
dropdown.template = templateTransform;
|
||||
|
||||
if (!Directory.Exists("Assets/Resources/"))
|
||||
Directory.CreateDirectory("Assets/Resources/");
|
||||
|
||||
PrefabUtility.SaveAsPrefabAsset(rootGO, kPrefabPath);
|
||||
GameObject.DestroyImmediate(rootGO);
|
||||
|
||||
|
||||
// add a custom sorting layer before test. It doesn't seem to be serialized so no need to remove it after test
|
||||
SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
|
||||
SerializedProperty sortingLayers = tagManager.FindProperty("m_SortingLayers");
|
||||
sortingLayers.InsertArrayElementAtIndex(sortingLayers.arraySize);
|
||||
var arrayElement = sortingLayers.GetArrayElementAtIndex(sortingLayers.arraySize - 1);
|
||||
foreach (SerializedProperty a in arrayElement)
|
||||
{
|
||||
switch (a.name)
|
||||
{
|
||||
case "name":
|
||||
a.stringValue = "test layer";
|
||||
break;
|
||||
case "uniqueID":
|
||||
a.intValue = 314159265;
|
||||
break;
|
||||
case "locked":
|
||||
a.boolValue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
tagManager.ApplyModifiedProperties();
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_PrefabRoot = Object.Instantiate(Resources.Load("DropdownPrefab")) as GameObject;
|
||||
m_CameraGO = new GameObject("Camera", typeof(Camera));
|
||||
}
|
||||
|
||||
// test for case 958281 - [UI] Dropdown list does not copy the parent canvas layer when the panel is opened
|
||||
[UnityTest]
|
||||
public IEnumerator Dropdown_Canvas()
|
||||
{
|
||||
var dropdown = m_PrefabRoot.GetComponentInChildren<Dropdown>();
|
||||
var rootCanvas = m_PrefabRoot.GetComponentInChildren<Canvas>();
|
||||
rootCanvas.sortingLayerName = "test layer";
|
||||
dropdown.Show();
|
||||
yield return null;
|
||||
var dropdownList = dropdown.transform.Find("Dropdown List");
|
||||
var dropdownListCanvas = dropdownList.GetComponentInChildren<Canvas>();
|
||||
Assert.AreEqual(rootCanvas.sortingLayerID, dropdownListCanvas.sortingLayerID, "Sorting layers should match");
|
||||
}
|
||||
|
||||
// test for case 1343542 - [UI] Child Canvas' Sorting Layer is changed to the same value as the parent
|
||||
[UnityTest]
|
||||
public IEnumerator Dropdown_Canvas_Already_Exists()
|
||||
{
|
||||
var dropdown = m_PrefabRoot.GetComponentInChildren<Dropdown>();
|
||||
var rootCanvas = m_PrefabRoot.GetComponentInChildren<Canvas>();
|
||||
var templateCanvas = dropdown.transform.Find("Template").gameObject.AddComponent<Canvas>();
|
||||
templateCanvas.overrideSorting = true;
|
||||
templateCanvas.sortingLayerName = "test layer";
|
||||
dropdown.Show();
|
||||
yield return null;
|
||||
var dropdownList = dropdown.transform.Find("Dropdown List");
|
||||
var dropdownListCanvas = dropdownList.GetComponentInChildren<Canvas>();
|
||||
Assert.AreNotEqual(rootCanvas.sortingLayerName, dropdownListCanvas.sortingLayerName, "Sorting layers should not match");
|
||||
}
|
||||
|
||||
// test for case 935649 - open dropdown menus become unresponsive when disabled and reenabled
|
||||
[UnityTest]
|
||||
public IEnumerator Dropdown_Disable()
|
||||
{
|
||||
var dropdown = m_PrefabRoot.GetComponentInChildren<Dropdown>();
|
||||
dropdown.Show();
|
||||
dropdown.gameObject.SetActive(false);
|
||||
yield return null;
|
||||
var dropdownList = dropdown.transform.Find("Dropdown List");
|
||||
Assert.IsNull(dropdownList);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Dropdown_ResetAndClear()
|
||||
{
|
||||
var options = new List<string> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" };
|
||||
var dropdown = m_PrefabRoot.GetComponentInChildren<Dropdown>();
|
||||
|
||||
// generate a first dropdown
|
||||
dropdown.ClearOptions();
|
||||
dropdown.AddOptions(options);
|
||||
dropdown.value = 3;
|
||||
yield return null;
|
||||
|
||||
|
||||
// clear it and generate a new one
|
||||
dropdown.ClearOptions();
|
||||
yield return null;
|
||||
|
||||
// check is the value is 0
|
||||
Assert.IsTrue(dropdown.value == 0);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Object.DestroyImmediate(m_PrefabRoot);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OneTimeTearDown()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset(kPrefabPath);
|
||||
|
||||
SerializedObject tagManager = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
|
||||
SerializedProperty sortingLayers = tagManager.FindProperty("m_SortingLayers");
|
||||
sortingLayers.DeleteArrayElementAtIndex(sortingLayers.arraySize);
|
||||
tagManager.ApplyModifiedProperties();
|
||||
#endif
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 358a618bc6bd9354d81cc206fd2ed80e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ab93e1a81defc3243a6e9cd0df3cb443
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,113 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
public class GraphicRaycasterTests
|
||||
{
|
||||
Camera m_Camera;
|
||||
EventSystem m_EventSystem;
|
||||
Canvas m_Canvas;
|
||||
RectTransform m_CanvasRectTrans;
|
||||
Text m_TextComponent;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_Camera = new GameObject("GraphicRaycaster Camera").AddComponent<Camera>();
|
||||
m_Camera.transform.position = Vector3.zero;
|
||||
m_Camera.transform.LookAt(Vector3.forward);
|
||||
m_Camera.farClipPlane = 10;
|
||||
|
||||
m_EventSystem = new GameObject("Event System").AddComponent<EventSystem>();
|
||||
|
||||
m_Canvas = new GameObject("Canvas").AddComponent<Canvas>();
|
||||
m_Canvas.renderMode = RenderMode.WorldSpace;
|
||||
m_Canvas.worldCamera = m_Camera;
|
||||
m_Canvas.gameObject.AddComponent<GraphicRaycaster>();
|
||||
m_CanvasRectTrans = m_Canvas.GetComponent<RectTransform>();
|
||||
m_CanvasRectTrans.sizeDelta = new Vector2(100, 100);
|
||||
|
||||
var textGO = new GameObject("Text");
|
||||
m_TextComponent = textGO.AddComponent<Text>();
|
||||
var textRectTrans = m_TextComponent.rectTransform;
|
||||
textRectTrans.SetParent(m_Canvas.transform);
|
||||
textRectTrans.anchorMin = Vector2.zero;
|
||||
textRectTrans.anchorMax = Vector2.one;
|
||||
textRectTrans.offsetMin = Vector2.zero;
|
||||
textRectTrans.offsetMax = Vector2.zero;
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator GraphicRaycasterDoesNotHitGraphicBehindCameraFarClipPlane()
|
||||
{
|
||||
m_CanvasRectTrans.anchoredPosition3D = new Vector3(0, 0, 11);
|
||||
|
||||
yield return null;
|
||||
|
||||
var results = new List<RaycastResult>();
|
||||
var pointerEvent = new PointerEventData(m_EventSystem)
|
||||
{
|
||||
position = new Vector2(Screen.width / 2f, Screen.height / 2f)
|
||||
};
|
||||
|
||||
m_EventSystem.RaycastAll(pointerEvent, results);
|
||||
|
||||
Assert.IsEmpty(results, "Expected no results from a raycast against a graphic behind the camera's far clip plane.");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator GraphicRaycasterReturnsWorldPositionAndWorldNormal()
|
||||
{
|
||||
m_CanvasRectTrans.anchoredPosition3D = new Vector3(0, 0, 11);
|
||||
m_Camera.farClipPlane = 12;
|
||||
|
||||
yield return null;
|
||||
|
||||
var results = new List<RaycastResult>();
|
||||
var pointerEvent = new PointerEventData(m_EventSystem)
|
||||
{
|
||||
position = new Vector2(Screen.width / 2f, Screen.height / 2f)
|
||||
};
|
||||
|
||||
m_EventSystem.RaycastAll(pointerEvent, results);
|
||||
// on katana on 10.13 agents world position returned is 0, -0.00952, 11
|
||||
// it does not reproduce for me localy, so we just tweak the comparison threshold
|
||||
Assert.That(new Vector3(0, 0, 11), Is.EqualTo(results[0].worldPosition).Using(new Vector3EqualityComparer(0.01f)));
|
||||
Assert.That(new Vector3(0, 0, -1), Is.EqualTo(results[0].worldNormal).Using(new Vector3EqualityComparer(0.001f)));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator GraphicOnTheSamePlaneAsTheCameraCanBeTargetedForEvents()
|
||||
{
|
||||
m_Canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
m_Canvas.planeDistance = 0;
|
||||
m_Camera.orthographic = true;
|
||||
m_Camera.orthographicSize = 1;
|
||||
m_Camera.nearClipPlane = 0;
|
||||
m_Camera.farClipPlane = 12;
|
||||
yield return null;
|
||||
|
||||
var results = new List<RaycastResult>();
|
||||
var pointerEvent = new PointerEventData(m_EventSystem)
|
||||
{
|
||||
position = new Vector2((Screen.width / 2f), Screen.height / 2f)
|
||||
};
|
||||
|
||||
m_EventSystem.RaycastAll(pointerEvent, results);
|
||||
|
||||
Assert.IsNotEmpty(results, "Expected at least 1 result from a raycast ");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Object.DestroyImmediate(m_Camera.gameObject);
|
||||
Object.DestroyImmediate(m_EventSystem.gameObject);
|
||||
Object.DestroyImmediate(m_Canvas.gameObject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e6323ebef616fee4486ee155cd56d191
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,88 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
public class GraphicRaycasterWorldSpaceCanvasTests
|
||||
{
|
||||
Camera m_Camera;
|
||||
EventSystem m_EventSystem;
|
||||
Canvas m_Canvas;
|
||||
RectTransform m_CanvasRectTrans;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_Camera = new GameObject("GraphicRaycaster Camera").AddComponent<Camera>();
|
||||
m_Camera.transform.position = Vector3.zero;
|
||||
m_Camera.transform.LookAt(Vector3.forward);
|
||||
m_Camera.farClipPlane = 10;
|
||||
|
||||
m_EventSystem = new GameObject("Event System").AddComponent<EventSystem>();
|
||||
|
||||
m_Canvas = new GameObject("Canvas").AddComponent<Canvas>();
|
||||
m_Canvas.renderMode = RenderMode.WorldSpace;
|
||||
m_Canvas.worldCamera = m_Camera;
|
||||
m_Canvas.gameObject.AddComponent<GraphicRaycaster>();
|
||||
m_CanvasRectTrans = m_Canvas.GetComponent<RectTransform>();
|
||||
m_CanvasRectTrans.sizeDelta = new Vector2(100, 100);
|
||||
|
||||
var textRectTrans = new GameObject("Text").AddComponent<Text>().rectTransform;
|
||||
textRectTrans.SetParent(m_Canvas.transform);
|
||||
textRectTrans.anchorMin = Vector2.zero;
|
||||
textRectTrans.anchorMax = Vector2.one;
|
||||
textRectTrans.offsetMin = Vector2.zero;
|
||||
textRectTrans.offsetMax = Vector2.zero;
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator GraphicRaycasterDoesNotHitGraphicBehindCameraFarClipPlane()
|
||||
{
|
||||
m_CanvasRectTrans.anchoredPosition3D = new Vector3(0, 0, 11);
|
||||
|
||||
yield return null;
|
||||
|
||||
var results = new List<RaycastResult>();
|
||||
var pointerEvent = new PointerEventData(m_EventSystem)
|
||||
{
|
||||
position = new Vector2(Screen.width / 2f, Screen.height / 2f)
|
||||
};
|
||||
|
||||
m_EventSystem.RaycastAll(pointerEvent, results);
|
||||
|
||||
Assert.IsEmpty(results, "Expected no results from a raycast against a graphic behind the camera's far clip plane.");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator GraphicRaycasterReturnsWorldPositionAndWorldNormal()
|
||||
{
|
||||
m_CanvasRectTrans.anchoredPosition3D = new Vector3(0, 0, 11);
|
||||
m_Camera.farClipPlane = 12;
|
||||
|
||||
yield return null;
|
||||
|
||||
var results = new List<RaycastResult>();
|
||||
var pointerEvent = new PointerEventData(m_EventSystem)
|
||||
{
|
||||
position = new Vector2(Screen.width / 2f, Screen.height / 2f)
|
||||
};
|
||||
|
||||
m_EventSystem.RaycastAll(pointerEvent, results);
|
||||
// on katana on 10.13 agents world position returned is 0, -0.00952, 11
|
||||
// it does not reproduce for me localy, so we just tweak the comparison threshold
|
||||
Assert.That(new Vector3(0, 0, 11), Is.EqualTo(results[0].worldPosition).Using(new Vector3EqualityComparer(0.01f)));
|
||||
Assert.That(new Vector3(0, 0, -1), Is.EqualTo(results[0].worldNormal).Using(new Vector3EqualityComparer(0.001f)));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Object.DestroyImmediate(m_Camera.gameObject);
|
||||
Object.DestroyImmediate(m_EventSystem.gameObject);
|
||||
Object.DestroyImmediate(m_Canvas.gameObject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3d42c4854f9093e409cd90c00ef26de0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,144 @@
|
|||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class InputModuleTests
|
||||
{
|
||||
EventSystem m_EventSystem;
|
||||
FakeBaseInput m_FakeBaseInput;
|
||||
StandaloneInputModule m_StandaloneInputModule;
|
||||
Canvas m_Canvas;
|
||||
Image m_Image;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
// Camera | Canvas (Image) | Event System
|
||||
|
||||
m_Canvas = new GameObject("Canvas").AddComponent<Canvas>();
|
||||
m_Canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
m_Canvas.gameObject.AddComponent<GraphicRaycaster>();
|
||||
|
||||
m_Image = new GameObject("Image").AddComponent<Image>();
|
||||
m_Image.gameObject.transform.SetParent(m_Canvas.transform);
|
||||
RectTransform imageRectTransform = m_Image.GetComponent<RectTransform>();
|
||||
imageRectTransform.sizeDelta = new Vector2(400f, 400f);
|
||||
imageRectTransform.localPosition = Vector3.zero;
|
||||
|
||||
GameObject go = new GameObject("Event System");
|
||||
m_StandaloneInputModule = go.AddComponent<StandaloneInputModule>();
|
||||
m_FakeBaseInput = go.AddComponent<FakeBaseInput>();
|
||||
|
||||
// Override input with FakeBaseInput so we can send fake mouse/keyboards button presses and touches
|
||||
m_StandaloneInputModule.inputOverride = m_FakeBaseInput;
|
||||
|
||||
m_EventSystem = go.AddComponent<EventSystem>();
|
||||
m_EventSystem.pixelDragThreshold = 1;
|
||||
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator DragCallbacksDoGetCalled()
|
||||
{
|
||||
// While left mouse button is pressed and the mouse is moving, OnBeginDrag and OnDrag callbacks should be called
|
||||
// Then when the left mouse button is released, OnEndDrag callback should be called
|
||||
|
||||
// Add script to EventSystem to update the mouse position
|
||||
m_EventSystem.gameObject.AddComponent<MouseUpdate>();
|
||||
|
||||
// Add script to Image which implements OnBeginDrag, OnDrag & OnEndDrag callbacks
|
||||
DragCallbackCheck callbackCheck = m_Image.gameObject.AddComponent<DragCallbackCheck>();
|
||||
|
||||
// Setting required input.mousePresent to fake mouse presence
|
||||
m_FakeBaseInput.MousePresent = true;
|
||||
|
||||
var canvasRT = m_Canvas.gameObject.transform as RectTransform;
|
||||
m_FakeBaseInput.MousePosition = new Vector2(Screen.width / 2, Screen.height / 2);
|
||||
|
||||
yield return null;
|
||||
|
||||
// Left mouse button down simulation
|
||||
m_FakeBaseInput.MouseButtonDown[0] = true;
|
||||
|
||||
yield return null;
|
||||
|
||||
// Left mouse button down flag needs to reset in the next frame
|
||||
m_FakeBaseInput.MouseButtonDown[0] = false;
|
||||
|
||||
yield return null;
|
||||
|
||||
// Left mouse button up simulation
|
||||
m_FakeBaseInput.MouseButtonUp[0] = true;
|
||||
|
||||
yield return null;
|
||||
|
||||
// Left mouse button up flag needs to reset in the next frame
|
||||
m_FakeBaseInput.MouseButtonUp[0] = false;
|
||||
|
||||
yield return null;
|
||||
|
||||
Assert.IsTrue(callbackCheck.onBeginDragCalled, "OnBeginDrag not called");
|
||||
Assert.IsTrue(callbackCheck.onDragCalled, "OnDragCalled not called");
|
||||
Assert.IsTrue(callbackCheck.onEndDragCalled, "OnEndDragCalled not called");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator MouseOutsideMaskRectTransform_WhileInsidePaddedArea_PerformsClick()
|
||||
{
|
||||
var mask = new GameObject("Panel").AddComponent<RectMask2D>();
|
||||
mask.gameObject.transform.SetParent(m_Canvas.transform);
|
||||
RectTransform panelRectTransform = mask.GetComponent<RectTransform>();
|
||||
panelRectTransform.sizeDelta = new Vector2(100, 100f);
|
||||
panelRectTransform.localPosition = Vector3.zero;
|
||||
|
||||
m_Image.gameObject.transform.SetParent(mask.transform, true);
|
||||
mask.padding = new Vector4(-30, -30, -30, -30);
|
||||
|
||||
|
||||
PointerClickCallbackCheck callbackCheck = m_Image.gameObject.AddComponent<PointerClickCallbackCheck>();
|
||||
|
||||
var canvasRT = m_Canvas.gameObject.transform as RectTransform;
|
||||
var screenMiddle = new Vector2(Screen.width / 2, Screen.height / 2);
|
||||
m_FakeBaseInput.MousePresent = true;
|
||||
m_FakeBaseInput.MousePosition = screenMiddle;
|
||||
|
||||
yield return null;
|
||||
// Click the center of the screen should hit the middle of the image.
|
||||
m_FakeBaseInput.MouseButtonDown[0] = true;
|
||||
yield return null;
|
||||
m_FakeBaseInput.MouseButtonDown[0] = false;
|
||||
yield return null;
|
||||
Assert.IsTrue(callbackCheck.pointerDown);
|
||||
|
||||
//Reset the callbackcheck and click outside the mask but still in the image.
|
||||
callbackCheck.pointerDown = false;
|
||||
m_FakeBaseInput.MousePosition = new Vector2(screenMiddle.x - 60, screenMiddle.y);
|
||||
yield return null;
|
||||
m_FakeBaseInput.MouseButtonDown[0] = true;
|
||||
yield return null;
|
||||
m_FakeBaseInput.MouseButtonDown[0] = false;
|
||||
yield return null;
|
||||
Assert.IsTrue(callbackCheck.pointerDown);
|
||||
|
||||
//Reset the callbackcheck and click outside the mask and outside in the image.
|
||||
callbackCheck.pointerDown = false;
|
||||
m_FakeBaseInput.MousePosition = new Vector2(screenMiddle.x - 100, screenMiddle.y);
|
||||
yield return null;
|
||||
m_FakeBaseInput.MouseButtonDown[0] = true;
|
||||
yield return null;
|
||||
m_FakeBaseInput.MouseButtonDown[0] = false;
|
||||
yield return null;
|
||||
Assert.IsFalse(callbackCheck.pointerDown);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_EventSystem.gameObject);
|
||||
GameObject.DestroyImmediate(m_Canvas.gameObject);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e4e290d31ab7fb54880746bb8f818e0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7a892c920c8ad2848b469ec9579c5219
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,29 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class DragCallbackCheck : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
||||
{
|
||||
private bool loggedOnDrag = false;
|
||||
public bool onBeginDragCalled = false;
|
||||
public bool onDragCalled = false;
|
||||
public bool onEndDragCalled = false;
|
||||
|
||||
public void OnBeginDrag(PointerEventData eventData)
|
||||
{
|
||||
onBeginDragCalled = true;
|
||||
}
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (loggedOnDrag)
|
||||
return;
|
||||
|
||||
loggedOnDrag = true;
|
||||
onDragCalled = true;
|
||||
}
|
||||
|
||||
public void OnEndDrag(PointerEventData eventData)
|
||||
{
|
||||
onEndDragCalled = true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 76c82729ad712f14bae1a8a279c52ac3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,117 @@
|
|||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class FakeBaseInput : BaseInput
|
||||
{
|
||||
[NonSerialized]
|
||||
public String CompositionString = "";
|
||||
|
||||
private IMECompositionMode m_ImeCompositionMode = IMECompositionMode.Auto;
|
||||
private Vector2 m_CompositionCursorPos = Vector2.zero;
|
||||
|
||||
[NonSerialized]
|
||||
public bool MousePresent = false;
|
||||
|
||||
[NonSerialized]
|
||||
public bool[] MouseButtonDown = new bool[3];
|
||||
|
||||
[NonSerialized]
|
||||
public bool[] MouseButtonUp = new bool[3];
|
||||
|
||||
[NonSerialized]
|
||||
public bool[] MouseButton = new bool[3];
|
||||
|
||||
[NonSerialized]
|
||||
public Vector2 MousePosition = Vector2.zero;
|
||||
|
||||
[NonSerialized]
|
||||
public Vector2 MouseScrollDelta = Vector2.zero;
|
||||
|
||||
[NonSerialized]
|
||||
public bool TouchSupported = false;
|
||||
|
||||
[NonSerialized]
|
||||
public int TouchCount = 0;
|
||||
|
||||
[NonSerialized]
|
||||
public Touch TouchData;
|
||||
|
||||
[NonSerialized]
|
||||
public float AxisRaw = 0f;
|
||||
|
||||
[NonSerialized]
|
||||
public bool ButtonDown = false;
|
||||
|
||||
public override string compositionString
|
||||
{
|
||||
get { return CompositionString; }
|
||||
}
|
||||
|
||||
public override IMECompositionMode imeCompositionMode
|
||||
{
|
||||
get { return m_ImeCompositionMode; }
|
||||
set { m_ImeCompositionMode = value; }
|
||||
}
|
||||
|
||||
public override Vector2 compositionCursorPos
|
||||
{
|
||||
get { return m_CompositionCursorPos; }
|
||||
set { m_CompositionCursorPos = value; }
|
||||
}
|
||||
|
||||
public override bool mousePresent
|
||||
{
|
||||
get { return MousePresent; }
|
||||
}
|
||||
|
||||
public override bool GetMouseButtonDown(int button)
|
||||
{
|
||||
return MouseButtonDown[button];
|
||||
}
|
||||
|
||||
public override bool GetMouseButtonUp(int button)
|
||||
{
|
||||
return MouseButtonUp[button];
|
||||
}
|
||||
|
||||
public override bool GetMouseButton(int button)
|
||||
{
|
||||
return MouseButton[button];
|
||||
}
|
||||
|
||||
public override Vector2 mousePosition
|
||||
{
|
||||
get { return MousePosition; }
|
||||
}
|
||||
|
||||
public override Vector2 mouseScrollDelta
|
||||
{
|
||||
get { return MouseScrollDelta; }
|
||||
}
|
||||
|
||||
public override bool touchSupported
|
||||
{
|
||||
get { return TouchSupported; }
|
||||
}
|
||||
|
||||
public override int touchCount
|
||||
{
|
||||
get { return TouchCount; }
|
||||
}
|
||||
|
||||
public override Touch GetTouch(int index)
|
||||
{
|
||||
return TouchData;
|
||||
}
|
||||
|
||||
public override float GetAxisRaw(string axisName)
|
||||
{
|
||||
return AxisRaw;
|
||||
}
|
||||
|
||||
public override bool GetButtonDown(string buttonName)
|
||||
{
|
||||
return ButtonDown;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 138dbec4f8742654fbceb0a19d68b9c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,20 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class MouseUpdate : MonoBehaviour
|
||||
{
|
||||
FakeBaseInput m_FakeBaseInput;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
m_FakeBaseInput = GetComponent<FakeBaseInput>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
Debug.Assert(m_FakeBaseInput, "FakeBaseInput component has not been added to the EventSystem");
|
||||
|
||||
// Update mouse position
|
||||
m_FakeBaseInput.MousePosition.x += 10f;
|
||||
m_FakeBaseInput.MousePosition.y += 10f;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 19c6f364c1e81cb4f829a057824639ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,13 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
public class PointerClickCallbackCheck : MonoBehaviour, IPointerDownHandler
|
||||
{
|
||||
public bool pointerDown = false;
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
pointerDown = true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0573713975c6b8246b7544ed524ef1dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,46 @@
|
|||
using UnityEngine;
|
||||
using NUnit.Framework;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class PhysicsRaycasterTests
|
||||
{
|
||||
GameObject m_CamGO;
|
||||
GameObject m_Collider;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_CamGO = new GameObject("PhysicsRaycaster Camera");
|
||||
m_Collider = GameObject.CreatePrimitive(PrimitiveType.Cube);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhysicsRaycasterDoesNotCastOutsideCameraViewRect()
|
||||
{
|
||||
m_CamGO.transform.position = new Vector3(0, 0, -10);
|
||||
m_CamGO.transform.LookAt(Vector3.zero);
|
||||
var cam = m_CamGO.AddComponent<Camera>();
|
||||
cam.rect = new Rect(0.5f, 0, 0.5f, 1);
|
||||
m_CamGO.AddComponent<PhysicsRaycaster>();
|
||||
var eventSystem = m_CamGO.AddComponent<EventSystem>();
|
||||
|
||||
// Create an object that will be hit if a raycast does occur.
|
||||
m_Collider.transform.localScale = new Vector3(100, 100, 1);
|
||||
List<RaycastResult> results = new List<RaycastResult>();
|
||||
var pointerEvent = new PointerEventData(eventSystem)
|
||||
{
|
||||
position = new Vector2(0, 0) // Raycast from the left side of the screen which is outside of the camera's view rect.
|
||||
};
|
||||
|
||||
eventSystem.RaycastAll(pointerEvent, results);
|
||||
Assert.IsEmpty(results, "Expected no results from a raycast that is outside of the camera's viewport.");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CamGO);
|
||||
GameObject.DestroyImmediate(m_Collider);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 833143c443f979e44ae0b8ed899e3b59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,121 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RaycastSortingTests : IPrebuildSetup
|
||||
{
|
||||
// Test to check that a a raycast over two canvases will not use hierarchal depth to compare two results
|
||||
// from different canvases (case 912396 - Raycast hits ignores 2nd Canvas which is drawn in front)
|
||||
GameObject m_PrefabRoot;
|
||||
|
||||
const string kPrefabPath = "Assets/Resources/RaycastSortingPrefab.prefab";
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var rootGO = new GameObject("RootGO");
|
||||
var cameraGO = new GameObject("Camera", typeof(Camera));
|
||||
var camera = cameraGO.GetComponent<Camera>();
|
||||
cameraGO.transform.SetParent(rootGO.transform);
|
||||
var eventSystemGO = new GameObject("EventSystem", typeof(EventSystem), typeof(StandaloneInputModule));
|
||||
eventSystemGO.transform.SetParent(rootGO.transform);
|
||||
|
||||
var backCanvasGO = new GameObject("BackCanvas", typeof(Canvas), typeof(GraphicRaycaster));
|
||||
backCanvasGO.transform.SetParent(rootGO.transform);
|
||||
var backCanvas = backCanvasGO.GetComponent<Canvas>();
|
||||
backCanvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
backCanvas.planeDistance = 100;
|
||||
backCanvas.worldCamera = camera;
|
||||
|
||||
var backCanvasBackground = new GameObject("BackCanvasBackground", typeof(Image), typeof(RectTransform));
|
||||
var backCanvasBackgroundTransform = backCanvasBackground.GetComponent<RectTransform>();
|
||||
backCanvasBackgroundTransform.SetParent(backCanvasGO.transform);
|
||||
backCanvasBackgroundTransform.anchorMin = Vector2.zero;
|
||||
backCanvasBackgroundTransform.anchorMax = Vector2.one;
|
||||
backCanvasBackgroundTransform.sizeDelta = Vector2.zero;
|
||||
backCanvasBackgroundTransform.anchoredPosition3D = Vector3.zero;
|
||||
backCanvasBackgroundTransform.localScale = Vector3.one;
|
||||
|
||||
var backCanvasDeeper = new GameObject("BackCanvasDeeperHierarchy", typeof(Image), typeof(RectTransform));
|
||||
var backCanvasDeeperTransform = backCanvasDeeper.GetComponent<RectTransform>();
|
||||
backCanvasDeeperTransform.SetParent(backCanvasBackgroundTransform);
|
||||
backCanvasDeeperTransform.anchorMin = new Vector2(0.5f, 0);
|
||||
backCanvasDeeperTransform.anchorMax = Vector2.one;
|
||||
backCanvasDeeperTransform.sizeDelta = Vector2.zero;
|
||||
backCanvasDeeperTransform.anchoredPosition3D = Vector3.zero;
|
||||
backCanvasDeeperTransform.localScale = Vector3.one;
|
||||
backCanvasDeeper.GetComponent<Image>().color = new Color(0.6985294f, 0.7754564f, 1f);
|
||||
|
||||
var frontCanvasGO = new GameObject("FrontCanvas", typeof(Canvas), typeof(GraphicRaycaster));
|
||||
frontCanvasGO.transform.SetParent(rootGO.transform);
|
||||
var frontCanvas = frontCanvasGO.GetComponent<Canvas>();
|
||||
frontCanvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
frontCanvas.planeDistance = 50;
|
||||
frontCanvas.worldCamera = camera;
|
||||
|
||||
var frontCanvasTopLevel = new GameObject("FrontCanvasTopLevel", typeof(Text), typeof(RectTransform));
|
||||
var frontCanvasTopLevelTransform = frontCanvasTopLevel.GetComponent<RectTransform>();
|
||||
frontCanvasTopLevelTransform.SetParent(frontCanvasGO.transform);
|
||||
frontCanvasTopLevelTransform.anchorMin = Vector2.zero;
|
||||
frontCanvasTopLevelTransform.anchorMax = new Vector2(1, 0.5f);
|
||||
frontCanvasTopLevelTransform.sizeDelta = Vector2.zero;
|
||||
frontCanvasTopLevelTransform.anchoredPosition3D = Vector3.zero;
|
||||
frontCanvasTopLevelTransform.localScale = Vector3.one;
|
||||
var text = frontCanvasTopLevel.GetComponent<Text>();
|
||||
text.text = "FrontCanvasTopLevel";
|
||||
text.color = Color.black;
|
||||
text.fontSize = 97;
|
||||
|
||||
if (!Directory.Exists("Assets/Resources/"))
|
||||
Directory.CreateDirectory("Assets/Resources/");
|
||||
|
||||
UnityEditor.PrefabUtility.SaveAsPrefabAsset(rootGO, kPrefabPath);
|
||||
GameObject.DestroyImmediate(rootGO);
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_PrefabRoot = Object.Instantiate(Resources.Load("RaycastSortingPrefab")) as GameObject;
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator RaycastResult_Sorting()
|
||||
{
|
||||
Camera cam = m_PrefabRoot.GetComponentInChildren<Camera>();
|
||||
EventSystem eventSystem = m_PrefabRoot.GetComponentInChildren<EventSystem>();
|
||||
GameObject shouldHit = m_PrefabRoot.GetComponentInChildren<Text>().gameObject;
|
||||
|
||||
PointerEventData eventData = new PointerEventData(eventSystem);
|
||||
//bottom left quadrant
|
||||
eventData.position = cam.ViewportToScreenPoint(new Vector3(0.75f, 0.25f));
|
||||
|
||||
List<RaycastResult> results = new List<RaycastResult>();
|
||||
eventSystem.RaycastAll(eventData, results);
|
||||
|
||||
Assert.IsTrue(results[0].gameObject.name == shouldHit.name);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Object.DestroyImmediate(m_PrefabRoot);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OneTimeTearDown()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset(kPrefabPath);
|
||||
#endif
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue