Created unity project
This commit is contained in:
@@ -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,57 @@
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
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;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(canvas);
|
||||
GameObject.DestroyImmediate(camera);
|
||||
}
|
||||
|
||||
[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,81 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NotRootCanvasAnchorsDontGetReset()
|
||||
{
|
||||
var rect = rootCanvasChild.GetComponent<RectTransform>();
|
||||
|
||||
rect.anchorMin = Vector2.zero;
|
||||
rect.anchorMax = Vector2.one;
|
||||
|
||||
Assert.IsTrue(rect.anchorMin == Vector2.zero);
|
||||
Assert.IsTrue(rect.anchorMax == Vector2.one);
|
||||
|
||||
m_TestObject.gameObject.SetActive(false);
|
||||
|
||||
Assert.IsTrue(rect.anchorMin == Vector2.zero);
|
||||
Assert.IsTrue(rect.anchorMax == Vector2.one);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ChildOfDisabledCanvasCantReceiveClicks()
|
||||
{
|
||||
rootCanvasChild.gameObject.AddComponent<Image>();
|
||||
var raycasts = GraphicRegistry.GetRaycastableGraphicsForCanvas(rootCanvasChild);
|
||||
|
||||
Assert.IsTrue(raycasts.Count == 1);
|
||||
|
||||
m_TestObject.gameObject.SetActive(false);
|
||||
raycasts = GraphicRegistry.GetRaycastableGraphicsForCanvas(rootCanvasChild);
|
||||
|
||||
Assert.IsTrue(raycasts.Count == 0);
|
||||
}
|
||||
}
|
||||
@@ -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: 1f71aeacc4a9f1a40b22a1a590331f6b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
using UnityEditor;
|
||||
using NUnit.Framework;
|
||||
|
||||
public class DropdownOptionsListDrawer : WrapperWindowFixture
|
||||
{
|
||||
public class Fixture : MonoBehaviour
|
||||
{
|
||||
public Dropdown.OptionDataList options = new Dropdown.OptionDataList();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator PropertyDrawerDoesNotThrowExceptionWhenObjectIsDisposed()
|
||||
{
|
||||
var go = new GameObject();
|
||||
var component = go.AddComponent<Fixture>();
|
||||
var so = new SerializedObject(component);
|
||||
var win = GetWindow((wnd) => {
|
||||
Assert.DoesNotThrow(() => EditorGUILayout.PropertyField(so.FindProperty("options")));
|
||||
so.Dispose();
|
||||
so = new SerializedObject(component);
|
||||
Assert.DoesNotThrow(() => EditorGUILayout.PropertyField(so.FindProperty("options")));
|
||||
return true;
|
||||
});
|
||||
|
||||
while (win.TestCompleted == false)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b180d0cec21671c45a32a9ce99bff2f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
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,38 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public class EventTriggerRemoveDuringExecution
|
||||
{
|
||||
[Test]
|
||||
[Description("ArgumentOutOfRange Exception is thrown when removing handler in callback in EventTrigger (case 1401557)")]
|
||||
public void EventTrigger_DoesNotThrowExceptionWhenRemovingEventDuringExecution()
|
||||
{
|
||||
var go = new GameObject();
|
||||
var eventTrigger = go.AddComponent<EventTrigger>();
|
||||
var eventSystem = go.AddComponent<EventSystem>();
|
||||
|
||||
var entry1 = new EventTrigger.Entry { eventID = EventTriggerType.PointerDown };
|
||||
var entry2 = new EventTrigger.Entry { eventID = EventTriggerType.PointerDown };
|
||||
|
||||
bool executed1 = false;
|
||||
bool executed2 = false;
|
||||
entry1.callback.AddListener(e =>
|
||||
{
|
||||
executed1 = true;
|
||||
eventTrigger.triggers.Remove(entry2);
|
||||
});
|
||||
entry2.callback.AddListener(e => executed2 = true);
|
||||
|
||||
eventTrigger.triggers.Add(entry1);
|
||||
eventTrigger.triggers.Add(entry2);
|
||||
|
||||
Assert.DoesNotThrow(() => eventTrigger.OnPointerDown(new PointerEventData(eventSystem)));
|
||||
Assert.True(executed1, "Expected Event 1 to be called but it was not.");
|
||||
Assert.False(executed2, "Expected Event 2 to not be called as it was removed by event 1.");
|
||||
Assert.That(eventTrigger.triggers, Does.Not.Contains(entry2));
|
||||
Assert.That(eventTrigger.triggers, Does.Contain(entry1));
|
||||
|
||||
Object.DestroyImmediate(go);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4adb1f65bbae8004a88d8f5bc3523298
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
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,54 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
|
||||
[Category("Slider")]
|
||||
public class SliderRectRefernces : Behaviour
|
||||
{
|
||||
private Slider slider;
|
||||
private GameObject emptyGO;
|
||||
private GameObject rootGO;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
rootGO = new GameObject("root child");
|
||||
rootGO.AddComponent<Canvas>();
|
||||
|
||||
var sliderGameObject = new GameObject("Slider");
|
||||
slider = sliderGameObject.AddComponent<Slider>();
|
||||
|
||||
emptyGO = new GameObject("base", typeof(RectTransform));
|
||||
|
||||
sliderGameObject.transform.SetParent(rootGO.transform);
|
||||
emptyGO.transform.SetParent(sliderGameObject.transform);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(rootGO);
|
||||
}
|
||||
|
||||
[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,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7689eda3a8b1a847a8b197dbe90d9a6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24333a116497b144f9782b1160984b57
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,116 @@
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.UIElements;
|
||||
using UnityEngine.Search;
|
||||
using UnityEngine;
|
||||
|
||||
public class PropertyDrawerTests
|
||||
{
|
||||
class PropertyDrawerTestsWindow : EditorWindow
|
||||
{
|
||||
public Navigation navigation;
|
||||
public SpriteState spriteState;
|
||||
public Dropdown.OptionDataList optionDataList;
|
||||
[SearchContext("t:gameObject is:gameObject", "gameObject")]
|
||||
public GameObject searchContext;
|
||||
public ExposedReference<GameObject> exposedReference;
|
||||
|
||||
SerializedObject serializedObject;
|
||||
|
||||
void CreateGUI()
|
||||
{
|
||||
serializedObject = new SerializedObject(this);
|
||||
|
||||
Add(nameof(navigation));
|
||||
Add(nameof(spriteState));
|
||||
Add(nameof(optionDataList));
|
||||
Add(nameof(searchContext));
|
||||
Add(nameof(exposedReference));
|
||||
|
||||
rootVisualElement.Bind(serializedObject);
|
||||
|
||||
// Forces visual tree update
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
void Add(string propertyName)
|
||||
{
|
||||
rootVisualElement.Add(new PropertyField() { bindingPath = propertyName });
|
||||
}
|
||||
|
||||
public SerializedProperty Property(string propertyName) => serializedObject.FindProperty(propertyName);
|
||||
|
||||
public void Rebuild() => rootVisualElement.Bind(serializedObject);
|
||||
}
|
||||
|
||||
static PropertyDrawerTestsWindow window;
|
||||
|
||||
[OneTimeSetUp]
|
||||
[MenuItem("Tests/Open Property Drawer Test Window")]
|
||||
public static void OneTimeSetUp() => window = EditorWindow.GetWindow<PropertyDrawerTestsWindow>();
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OneTimeTearDown() => window.Close();
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator NavigationDrawer_IsVisible()
|
||||
{
|
||||
yield return null;
|
||||
Assert.IsNotNull(window.rootVisualElement.Query<VisualElement>("Navigation").Build().First());
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator SpriteStateDrawer_IsVisible()
|
||||
{
|
||||
yield return null;
|
||||
Assert.IsNotNull(window.rootVisualElement.Q("SpriteState"));
|
||||
}
|
||||
|
||||
[UnityTest, Ignore("Disabled for Instability https://jira.unity3d.com/browse/UUM-11060")]
|
||||
public IEnumerator DropdownOptionDataListDrawer_IsVisible()
|
||||
{
|
||||
yield return null;
|
||||
Assert.IsNotNull(window.rootVisualElement.Q("DropdownOptionDataList"), $"Item is null. Root object count: {window.rootVisualElement.childCount}");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator SearchContextDrawer_IsVisible()
|
||||
{
|
||||
yield return null;
|
||||
Assert.IsNotNull(window.rootVisualElement.Q("SearchContext"));
|
||||
}
|
||||
|
||||
[UnityTest, Ignore("Disabled for Instability https://jira.unity3d.com/browse/UUM-11060")]
|
||||
public IEnumerator ExposedReferenceDrawer_IsVisible()
|
||||
{
|
||||
yield return null;
|
||||
Assert.IsNotNull(window.rootVisualElement.Q("ExposedReference"), $"Item is null. Root object count: {window.rootVisualElement.childCount}");
|
||||
}
|
||||
|
||||
// Fake expected result in order to make TestCaseAttribute to work with UnityTest
|
||||
[UnityTest]
|
||||
[TestCase(new object[] { (int)Navigation.Mode.None, 0}, ExpectedResult = null)]
|
||||
[TestCase(new object[] { (int)Navigation.Mode.Horizontal, 1 }, ExpectedResult = null)]
|
||||
[TestCase(new object[] { (int)Navigation.Mode.Vertical, 1 }, ExpectedResult = null)]
|
||||
[TestCase(new object[] { (int)Navigation.Mode.Automatic, 0 }, ExpectedResult = null)]
|
||||
[TestCase(new object[] { (int)Navigation.Mode.Explicit, 4 }, ExpectedResult = null)]
|
||||
[TestCase(new object[] { (int)(Navigation.Mode.Explicit | Navigation.Mode.Horizontal), 0 }, ExpectedResult = null)]
|
||||
[TestCase(new object[] { (int)(Navigation.Mode.Automatic | Navigation.Mode.Explicit), 0 }, ExpectedResult = null)]
|
||||
public static IEnumerator NavigationDrawer_ShowsCorrectAdditionalControlCount(int mode, int expectedCount)
|
||||
{
|
||||
window.Property("navigation.m_Mode").enumValueFlag = mode;
|
||||
window.Rebuild();
|
||||
yield return null;
|
||||
|
||||
var indent = window.rootVisualElement.Query<VisualElement>("Navigation").Build().First().Query<VisualElement>("Indent").Build().First();
|
||||
var visibleChildren = indent.Children().Count(child => child.resolvedStyle.display != DisplayStyle.None);
|
||||
Assert.AreEqual(expectedCount, visibleChildren, $"{expectedCount} additional Navigation object properties should be " +
|
||||
$"visible when 'Mode' is set to '{(Navigation.Mode)window.Property("navigation.m_Mode").enumValueFlag}'");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 433d3b96b2a40a5479d3d7d8495882ed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
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,83 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor.Events;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
[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_EditMode_InvokeDoesNotCallRuntimeListener()
|
||||
{
|
||||
var _event = new UnityEvent();
|
||||
UnityEventTools.AddPersistentListener(_event, new UnityAction(Counter.Add));
|
||||
Assert.AreEqual(UnityEventCallState.RuntimeOnly, _event.GetPersistentListenerState(0));
|
||||
Assert.False(Application.isPlaying);
|
||||
|
||||
_event.Invoke();
|
||||
|
||||
Assert.AreEqual(0, Counter.m_Count, "Expected Event to not be called when not in play mode and event is marked as Runtime only");
|
||||
|
||||
for (int i = 1; i < 5; ++i)
|
||||
{
|
||||
UnityEventTools.AddIntPersistentListener(_event, new UnityAction<int>(Counter.NoOp), i);
|
||||
}
|
||||
|
||||
_event.Invoke();
|
||||
|
||||
Assert.AreEqual(0, Counter.m_Count, "Expected Event to not be called when not in play mode and event is marked as Runtime only");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 977190a4db46de442aed27279d247df4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
public class WrapperWindowFixture
|
||||
{
|
||||
private static WrapperWindow s_MostRecentWrapperWindow;
|
||||
|
||||
public class WrapperWindow : EditorWindow
|
||||
{
|
||||
// Return true to end the test
|
||||
public Func<WrapperWindow, bool> onGUIDelegate;
|
||||
|
||||
public bool TestCompleted { get; set; }
|
||||
|
||||
public void OnGUI()
|
||||
{
|
||||
if (onGUIDelegate != null)
|
||||
{
|
||||
TestCompleted = onGUIDelegate.Invoke(this);
|
||||
if (TestCompleted)
|
||||
onGUIDelegate = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static WrapperWindow GetWindow(Func<WrapperWindow, bool> onGUIDelegate, bool utility = false)
|
||||
{
|
||||
return GetWindow(onGUIDelegate, 800, 600, utility);
|
||||
}
|
||||
|
||||
public static WrapperWindow GetWindow(Func<WrapperWindow, bool> onGUIDelegate, int width, int height, bool utility = false)
|
||||
{
|
||||
WrapperWindow window;
|
||||
if (utility)
|
||||
window = EditorWindow.GetWindow<WrapperWindow>(true);
|
||||
else
|
||||
{
|
||||
window = ScriptableObject.CreateInstance<WrapperWindow>();
|
||||
window.hideFlags = HideFlags.DontSave;
|
||||
}
|
||||
|
||||
window.onGUIDelegate = onGUIDelegate;
|
||||
window.position = new Rect(0, 0, width, height);
|
||||
window.Show();
|
||||
s_MostRecentWrapperWindow = window;
|
||||
return window;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void CloseMostRecentWrapperWindow()
|
||||
{
|
||||
if (s_MostRecentWrapperWindow == null)
|
||||
return;
|
||||
s_MostRecentWrapperWindow.Close();
|
||||
s_MostRecentWrapperWindow = null;
|
||||
}
|
||||
|
||||
protected static void RegisterWrapperWindow(WrapperWindow window)
|
||||
{
|
||||
s_MostRecentWrapperWindow = window;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc31799bd6dc1f74a8adfee1acd05a9b
|
||||
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,151 @@
|
||||
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
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SelectShouldHoldThePreviousStateAfterDisablingAndEnabling()
|
||||
{
|
||||
TestButton button = m_PrefabRoot.GetComponentInChildren<TestButton>();
|
||||
button.onClick.AddListener(() => {
|
||||
button.Select();
|
||||
button.enabled = false;
|
||||
});
|
||||
button.OnPointerClick(new PointerEventData(m_PrefabRoot.GetComponentInChildren<EventSystem>()) { button = PointerEventData.InputButton.Left });
|
||||
Assert.False(button.enabled, "Expected button to not be enabled");
|
||||
button.enabled = true;
|
||||
Assert.True(button.isStateSelected, "Expected selected state to be true");
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ef2923b9c5521948a04299da53ae750
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
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; } }
|
||||
public bool isStateSelected { get { return currentSelectionState == SelectionState.Selected; } }
|
||||
|
||||
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>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasObject);
|
||||
}
|
||||
|
||||
private void SetUpCanvasGroupState()
|
||||
{
|
||||
m_CanvasGroup.enabled = false;
|
||||
m_CanvasGroup.ignoreParentGroups = false;
|
||||
m_ChildCanvasGroup.enabled = false;
|
||||
m_ChildCanvasGroup.ignoreParentGroups = false;
|
||||
m_GrandChildCanvasGroup.enabled = false;
|
||||
m_GrandChildCanvasGroup.ignoreParentGroups = false;
|
||||
|
||||
m_CanvasTwoGroup.enabled = false;
|
||||
m_CanvasTwoGroup.ignoreParentGroups = false;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupEffectSelfAndChildrenAlpha()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the child CanvasGroup. It and its children should now have the same alpha value.
|
||||
m_ChildCanvasGroup.enabled = true;
|
||||
|
||||
Assert.AreEqual(m_ChildAlpha, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_ChildAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnACanvasEffectAllChildrenAlpha()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Children under a different nest canvas should also obey the alpha
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasTwoRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Canvas CanvasGroup. All of the Canvas children should now have the same alpha value.
|
||||
m_CanvasGroup.enabled = true;
|
||||
|
||||
Assert.AreEqual(m_CanvasAlpha, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_CanvasAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Children under a different nest canvas should also obey the alpha
|
||||
Assert.AreEqual(m_CanvasAlpha, m_ChildCanvasTwoRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnLeafChildEffectOnlyThatChild()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Leaf child CanvasGroup. Only it should have a modified alpha
|
||||
m_GrandChildCanvasGroup.enabled = true;
|
||||
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_GrandChildAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnCanvasAndChildMultipleAlphaValuesCorrectly()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Canvas CanvasGroup. All of the Canvas children should now have the same alpha value.
|
||||
m_CanvasGroup.enabled = true;
|
||||
m_ChildCanvasGroup.enabled = true;
|
||||
Assert.AreEqual(m_CanvasAlpha * m_ChildAlpha, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_CanvasAlpha * m_ChildAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnCanvasAndChildWithChildIgnoringParentGroupMultipleAlphaValuesCorrectly()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Canvas CanvasGroup. All of the Canvas children should now have the same alpha value.
|
||||
m_CanvasGroup.enabled = true;
|
||||
m_ChildCanvasGroup.enabled = true;
|
||||
m_ChildCanvasGroup.ignoreParentGroups = true;
|
||||
Assert.AreEqual(m_ChildAlpha, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_ChildAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnCanvasAndChildrenWithAllChildrenIgnoringParentGroupMultipleAlphaValuesCorrectly()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(1.0f, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Canvas CanvasGroup. All of the Canvas children should now have the same alpha value.
|
||||
m_CanvasGroup.enabled = true;
|
||||
m_ChildCanvasGroup.enabled = true;
|
||||
m_GrandChildCanvasGroup.enabled = true;
|
||||
m_ChildCanvasGroup.ignoreParentGroups = true;
|
||||
m_GrandChildCanvasGroup.ignoreParentGroups = true;
|
||||
Assert.AreEqual(m_ChildAlpha, m_ChildCanvasRenderer.GetInheritedAlpha());
|
||||
Assert.AreEqual(m_GrandChildAlpha, m_GrandChildCanvasRenderer.GetInheritedAlpha());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnabledCanvasGroupOnNestedCanvasIgnoringParentGroupMultipleAlphaValuesCorrectly()
|
||||
{
|
||||
// Set up the states of the canvas groups for the tests.
|
||||
SetUpCanvasGroupState();
|
||||
|
||||
// With no enabled CanvasGroup the Alphas should be 1
|
||||
Assert.AreEqual(1.0f, m_ChildCanvasTwoRenderer.GetInheritedAlpha());
|
||||
|
||||
// Enable the Canvas CanvasGroup. All of the Canvas children should now have the same alpha value.
|
||||
m_CanvasGroup.enabled = true;
|
||||
m_CanvasTwoGroup.enabled = true;
|
||||
m_CanvasTwoGroup.ignoreParentGroups = true;
|
||||
Assert.AreEqual(m_CanvasAlpha, m_ChildCanvasTwoRenderer.GetInheritedAlpha());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a14a59f2a5c757e469c3e4e17b798c2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEditor;
|
||||
|
||||
[TestFixture]
|
||||
public class CanvasResizeCorrectlyForRenderTexture
|
||||
{
|
||||
Canvas m_Canvas;
|
||||
Camera m_Camera;
|
||||
RenderTexture m_RenderTexture;
|
||||
|
||||
[Test]
|
||||
public void CanvasResizeCorrectly()
|
||||
{
|
||||
var cameraGameObject = new GameObject("PreviewCamera", typeof(Camera));
|
||||
var canvasGameObject = new GameObject("Canvas", typeof(Canvas));
|
||||
m_Camera = cameraGameObject.GetComponent<Camera>();
|
||||
m_Canvas = canvasGameObject.GetComponent<Canvas>();
|
||||
|
||||
m_Canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
m_Canvas.worldCamera = m_Camera;
|
||||
var rectTransform = canvasGameObject.transform as RectTransform;
|
||||
m_Canvas.updateRectTransformForStandalone = StandaloneRenderResize.Disabled;
|
||||
m_RenderTexture = new RenderTexture(100, 100, 0);
|
||||
m_Camera.targetTexture = m_RenderTexture;
|
||||
|
||||
m_Camera.Render();
|
||||
|
||||
Assert.AreNotEqual(new Vector2(100, 100), rectTransform.sizeDelta);
|
||||
|
||||
m_Canvas.updateRectTransformForStandalone = StandaloneRenderResize.Enabled;
|
||||
m_Camera.Render();
|
||||
Assert.AreEqual(new Vector2(100, 100), rectTransform.sizeDelta);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_Canvas.gameObject);
|
||||
GameObject.DestroyImmediate(m_Camera.gameObject);
|
||||
UnityEngine.Object.DestroyImmediate(m_RenderTexture);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4dbe29df1b294c4f8f0a2fb529d19fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,54 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[TestFixture]
|
||||
[Category("RegressionTest")]
|
||||
[Description("CoveredBugID = 734299")]
|
||||
public class CanvasScalerWithChildTextObjectDoesNotCrash
|
||||
{
|
||||
GameObject m_CanvasObject;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.ExecuteMenuItem("Window/General/Game");
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CanvasScalerWithChildTextObjectWithTextFontDoesNotCrash()
|
||||
{
|
||||
//This adds a Canvas component as well
|
||||
m_CanvasObject = new GameObject("Canvas");
|
||||
var canvasScaler = m_CanvasObject.AddComponent<CanvasScaler>();
|
||||
m_CanvasObject.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceCamera;
|
||||
|
||||
//the crash only reproduces if the text component is a child of the game object
|
||||
//that has the CanvasScaler component and if it has an actual font and text set
|
||||
var textObject = new GameObject("Text").AddComponent<UnityEngine.UI.Text>();
|
||||
textObject.font = Font.CreateDynamicFontFromOSFont("Arial", 14);
|
||||
textObject.text = "New Text";
|
||||
textObject.transform.SetParent(m_CanvasObject.transform);
|
||||
canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
canvasScaler.referenceResolution = new Vector2(1080, 1020);
|
||||
|
||||
//The crash happens when setting the referenceResolution to a small value
|
||||
canvasScaler.referenceResolution = new Vector2(9, 9);
|
||||
|
||||
//We need to wait a few milliseconds for the crash to happen, otherwise Debug.Log will
|
||||
//get executed and the test will pass
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
|
||||
Assert.That(true);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 13d161b14bb3ab74e8a9634e26fb7a5e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEditor;
|
||||
|
||||
[TestFixture]
|
||||
public class CanvasSizeCorrectInAwakeAndStart : IPrebuildSetup
|
||||
{
|
||||
const string k_SceneName = "CanvasSizeCorrectInAwakeAndStartScene";
|
||||
GameObject m_CanvasGameObject;
|
||||
Scene m_InitScene;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Action codeToExecute = delegate()
|
||||
{
|
||||
var canvasGO = new GameObject("CanvasToAddImage", typeof(Canvas));
|
||||
var imageGO = new GameObject("ImageOnCanvas", typeof(UnityEngine.UI.Image));
|
||||
imageGO.transform.localPosition = Vector3.one;
|
||||
imageGO.transform.SetParent(canvasGO.transform);
|
||||
imageGO.AddComponent<CanvasSizeCorrectInAwakeAndStartScript>();
|
||||
canvasGO.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
imageGO.SetActive(false);
|
||||
};
|
||||
CreateSceneUtility.CreateScene(k_SceneName, codeToExecute);
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_InitScene = SceneManager.GetActiveScene();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CanvasSizeIsCorrectInAwakeAndStart()
|
||||
{
|
||||
AsyncOperation operation = SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
|
||||
yield return operation;
|
||||
|
||||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
|
||||
m_CanvasGameObject = GameObject.Find("CanvasToAddImage");
|
||||
var imageGO = m_CanvasGameObject.transform.Find("ImageOnCanvas");
|
||||
imageGO.gameObject.SetActive(true);
|
||||
var component = imageGO.GetComponent<CanvasSizeCorrectInAwakeAndStartScript>();
|
||||
|
||||
yield return new WaitUntil(() => component.isAwakeCalled && component.isStartCalled);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasGameObject);
|
||||
SceneManager.SetActiveScene(m_InitScene);
|
||||
SceneManager.UnloadSceneAsync(k_SceneName);
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset("Assets/" + k_SceneName + ".unity");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec35c13a8280a8d4e817bc4afd8a95de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
public class CanvasSizeCorrectInAwakeAndStartScript : MonoBehaviour
|
||||
{
|
||||
public bool isStartCalled { get; private set; }
|
||||
public bool isAwakeCalled { get; private set; }
|
||||
|
||||
protected void Awake()
|
||||
{
|
||||
Assert.That(transform.position, Is.Not.EqualTo(Vector3.zero).Using(new Vector3EqualityComparer(0.0f)));
|
||||
isAwakeCalled = true;
|
||||
}
|
||||
|
||||
protected void Start()
|
||||
{
|
||||
Assert.That(transform.position, Is.Not.EqualTo(Vector3.zero).Using(new Vector3EqualityComparer(0.0f)));
|
||||
isStartCalled = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df1ba932d4ce4534e97a0f10c85cd3c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,84 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
[TestFixture]
|
||||
public class CheckMeshColorsAndColors32Match
|
||||
{
|
||||
GameObject m_CanvasGO;
|
||||
GameObject m_ColorMeshGO;
|
||||
GameObject m_Color32MeshGO;
|
||||
Texture2D m_ScreenTexture;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
// Create Canvas
|
||||
m_CanvasGO = new GameObject("Canvas");
|
||||
Canvas canvas = m_CanvasGO.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
// Create Color UI GameObject
|
||||
m_ColorMeshGO = new GameObject("ColorMesh");
|
||||
CanvasRenderer colorMeshCanvasRenderer = m_ColorMeshGO.AddComponent<CanvasRenderer>();
|
||||
RectTransform colorMeshRectTransform = m_ColorMeshGO.AddComponent<RectTransform>();
|
||||
colorMeshRectTransform.pivot = colorMeshRectTransform.anchorMin = colorMeshRectTransform.anchorMax = Vector2.zero;
|
||||
m_ColorMeshGO.transform.SetParent(m_CanvasGO.transform);
|
||||
|
||||
// Create Color32 UI GameObject
|
||||
m_Color32MeshGO = new GameObject("Color32Mesh");
|
||||
CanvasRenderer color32MeshCanvasRenderer = m_Color32MeshGO.AddComponent<CanvasRenderer>();
|
||||
RectTransform color32MeshRectTransform = m_Color32MeshGO.AddComponent<RectTransform>();
|
||||
color32MeshRectTransform.pivot = color32MeshRectTransform.anchorMin = color32MeshRectTransform.anchorMax = Vector2.zero;
|
||||
m_Color32MeshGO.transform.SetParent(m_CanvasGO.transform);
|
||||
|
||||
Material material = new Material(Shader.Find("UI/Default"));
|
||||
|
||||
// Setup Color mesh and add it to Color CanvasRenderer
|
||||
Mesh meshColor = new Mesh();
|
||||
meshColor.vertices = new Vector3[3] { new Vector3(0, 0, 0), new Vector3(0, 10, 0), new Vector3(10, 0, 0) };
|
||||
meshColor.triangles = new int[3] { 0, 1, 2 };
|
||||
meshColor.normals = new Vector3[3] { Vector3.zero, Vector3.zero, Vector3.zero };
|
||||
meshColor.colors = new Color[3] { Color.white, Color.white, Color.white };
|
||||
meshColor.uv = new Vector2[3] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 0) };
|
||||
|
||||
colorMeshCanvasRenderer.SetMesh(meshColor);
|
||||
colorMeshCanvasRenderer.SetMaterial(material, null);
|
||||
|
||||
// Setup Color32 mesh and add it to Color32 CanvasRenderer
|
||||
Mesh meshColor32 = new Mesh();
|
||||
meshColor32.vertices = new Vector3[3] { new Vector3(10, 0, 0), new Vector3(10, 10, 0), new Vector3(20, 0, 0) };
|
||||
meshColor32.triangles = new int[3] { 0, 1, 2 };
|
||||
meshColor32.normals = new Vector3[3] { Vector3.zero, Vector3.zero, Vector3.zero };
|
||||
meshColor32.colors32 = new Color32[3] { Color.white, Color.white, Color.white };
|
||||
meshColor32.uv = new Vector2[3] { new Vector2(0, 0), new Vector2(0, 1), new Vector2(1, 0) };
|
||||
|
||||
color32MeshCanvasRenderer.SetMesh(meshColor32);
|
||||
color32MeshCanvasRenderer.SetMaterial(material, null);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasGO);
|
||||
GameObject.DestroyImmediate(m_ScreenTexture);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CheckMeshColorsAndColors32Matches()
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
// Create a Texture2D
|
||||
m_ScreenTexture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
|
||||
m_ScreenTexture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
|
||||
m_ScreenTexture.Apply();
|
||||
|
||||
Color screenPixelColorForMeshColor = m_ScreenTexture.GetPixel(1, 0);
|
||||
Color screenPixelColorForMesh32Color = m_ScreenTexture.GetPixel(11, 0);
|
||||
|
||||
Assert.That(screenPixelColorForMesh32Color, Is.EqualTo(screenPixelColorForMeshColor).Using(new ColorEqualityComparer(0.0f)), "UI Mesh with Colors does not match UI Mesh with Colors32");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9390296e78291b543b2f4a9761ef8139
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,74 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[TestFixture]
|
||||
[UnityPlatform(include = new RuntimePlatform[] { RuntimePlatform.OSXEditor, RuntimePlatform.LinuxEditor, RuntimePlatform.WindowsEditor })]
|
||||
[Category("RegressionTest")]
|
||||
[Description("CoveredBugID = 904415")]
|
||||
public class CoroutineWorksIfUIObjectIsAttached
|
||||
{
|
||||
GameObject m_CanvasMaster;
|
||||
GameObject m_ImageObject;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_CanvasMaster = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GraphicRaycaster));
|
||||
m_ImageObject = new GameObject("Image", typeof(Image));
|
||||
m_ImageObject.SetActive(false);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CoroutineWorksOnAttachingUIObject()
|
||||
{
|
||||
// Generating Basic scene
|
||||
m_CanvasMaster.AddComponent<CoroutineObject>();
|
||||
|
||||
yield return null;
|
||||
|
||||
m_ImageObject.transform.SetParent(m_CanvasMaster.transform);
|
||||
m_ImageObject.AddComponent<BugObject>();
|
||||
m_ImageObject.SetActive(true);
|
||||
|
||||
yield return null;
|
||||
yield return null;
|
||||
yield return null;
|
||||
|
||||
Assert.That(m_CanvasMaster.GetComponent<CoroutineObject>().coroutineCount, Is.GreaterThan(1), "The Coroutine wasn't supposed to stop but continue to run, something made it stopped");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasMaster);
|
||||
GameObject.DestroyImmediate(m_ImageObject);
|
||||
}
|
||||
}
|
||||
|
||||
public class BugObject : MonoBehaviour
|
||||
{
|
||||
void Awake()
|
||||
{
|
||||
GameObject newObject = new GameObject("NewGameObjectThatTriggersBug");
|
||||
newObject.transform.SetParent(transform);
|
||||
newObject.AddComponent<Text>();
|
||||
}
|
||||
}
|
||||
|
||||
public class CoroutineObject : MonoBehaviour
|
||||
{
|
||||
public int coroutineCount { get; private set; }
|
||||
|
||||
public IEnumerator Start()
|
||||
{
|
||||
// This coroutine should not stop and continue adding to the timer
|
||||
while (true)
|
||||
{
|
||||
coroutineCount++;
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8573c56c34e616248a3881b2c56280ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
class CreateSceneUtility
|
||||
{
|
||||
public static void CreateScene(string sceneName, Action delegateToExecute)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
string scenePath = "Assets/" + sceneName + ".unity";
|
||||
var initScene = SceneManager.GetActiveScene();
|
||||
var list = UnityEditor.EditorBuildSettings.scenes.ToList();
|
||||
var newScene = UnityEditor.SceneManagement.EditorSceneManager.NewScene(UnityEditor.SceneManagement.NewSceneSetup.DefaultGameObjects, UnityEditor.SceneManagement.NewSceneMode.Additive);
|
||||
GameObject.DestroyImmediate(Camera.main.GetComponent<AudioListener>());
|
||||
delegateToExecute();
|
||||
UnityEditor.SceneManagement.EditorSceneManager.SaveScene(newScene, scenePath);
|
||||
UnityEditor.SceneManagement.EditorSceneManager.UnloadSceneAsync(newScene);
|
||||
|
||||
list.Add(new UnityEditor.EditorBuildSettingsScene(scenePath, true));
|
||||
UnityEditor.EditorBuildSettings.scenes = list.ToArray();
|
||||
SceneManager.SetActiveScene(initScene);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: db339ef553721e94999125c0b9f909dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,102 @@
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
public class NestedCanvas : IPrebuildSetup
|
||||
{
|
||||
Object m_GO1;
|
||||
Object m_GO2;
|
||||
|
||||
const string kPrefabPath = "Assets/Resources/NestedCanvasPrefab.prefab";
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
|
||||
var rootGO = new GameObject("RootGO");
|
||||
|
||||
var rootCanvasGO = new GameObject("Canvas", typeof(Canvas), typeof(CanvasGroup));
|
||||
rootCanvasGO.transform.SetParent(rootGO.transform);
|
||||
|
||||
var nestedCanvas = new GameObject("Nested Canvas", typeof(Canvas), typeof(Image));
|
||||
nestedCanvas.transform.SetParent(rootCanvasGO.transform);
|
||||
|
||||
var nestedCanvasCamera = new GameObject("Nested Canvas Camera", typeof(Camera));
|
||||
nestedCanvasCamera.transform.SetParent(rootCanvasGO.transform);
|
||||
|
||||
var rootCanvas = rootCanvasGO.GetComponent<Canvas>();
|
||||
rootCanvas.renderMode = RenderMode.WorldSpace;
|
||||
rootCanvas.worldCamera = nestedCanvasCamera.GetComponent<Camera>();
|
||||
|
||||
if (!Directory.Exists("Assets/Resources/"))
|
||||
Directory.CreateDirectory("Assets/Resources/");
|
||||
|
||||
UnityEditor.PrefabUtility.SaveAsPrefabAsset(rootGO, kPrefabPath);
|
||||
GameObject.DestroyImmediate(rootGO);
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
[Description("[UI] Button does not interact after nested canvas is used(case 892913)")]
|
||||
public IEnumerator WorldCanvas_CanFindCameraAfterDisablingAndEnablingRootCanvas()
|
||||
{
|
||||
m_GO1 = Object.Instantiate(Resources.Load("NestedCanvasPrefab"));
|
||||
yield return null;
|
||||
|
||||
var nestedCanvasGo = GameObject.Find("Nested Canvas");
|
||||
var nestedCanvas = nestedCanvasGo.GetComponent<Canvas>();
|
||||
Assert.IsNotNull(nestedCanvas.worldCamera, "Expected the nested canvas worldCamera to NOT be null after loading the scene.");
|
||||
|
||||
nestedCanvasGo.transform.parent.gameObject.SetActive(false);
|
||||
nestedCanvasGo.transform.parent.gameObject.SetActive(true);
|
||||
Assert.IsNotNull(nestedCanvas.worldCamera, "Expected the nested canvas worldCamera to NOT be null after the parent canvas has been re-enabled.");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator WorldCanvas_CanFindTheSameCameraAfterDisablingAndEnablingRootCanvas()
|
||||
{
|
||||
m_GO2 = Object.Instantiate(Resources.Load("NestedCanvasPrefab"));
|
||||
yield return null;
|
||||
|
||||
var nestedCanvasGo = GameObject.Find("Nested Canvas");
|
||||
var nestedCanvas = nestedCanvasGo.GetComponent<Canvas>();
|
||||
var worldCamera = nestedCanvas.worldCamera;
|
||||
nestedCanvasGo.transform.parent.gameObject.SetActive(false);
|
||||
nestedCanvasGo.transform.parent.gameObject.SetActive(true);
|
||||
Assert.AreEqual(worldCamera, nestedCanvas.worldCamera, "Expected the same world camera to be returned after the root canvas was disabled and then re-enabled.");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator NestedCanvasHasProperInheritedAlpha()
|
||||
{
|
||||
GameObject root = (GameObject)Object.Instantiate(Resources.Load("NestedCanvasPrefab"));
|
||||
CanvasGroup group = root.GetComponentInChildren<CanvasGroup>();
|
||||
Image image = root.GetComponentInChildren<Image>();
|
||||
|
||||
group.alpha = 0.5f;
|
||||
|
||||
yield return null;
|
||||
|
||||
Assert.True(image.canvasRenderer.GetInheritedAlpha() == 0.5f);
|
||||
GameObject.DestroyImmediate(root);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_GO1);
|
||||
GameObject.DestroyImmediate(m_GO2);
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OneTimeTearDown()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset(kPrefabPath);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc8d686a4c18b8d49bb1db4150de0459
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
|
||||
public class NestedCanvasMaintainsCorrectSize : IPrebuildSetup
|
||||
{
|
||||
BridgeScriptForRetainingObjects m_BridgeComponent;
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var canvasGO = new GameObject("Canvas", typeof(Canvas));
|
||||
canvasGO.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
var nestedCanvasGO = new GameObject("NestedCanvas", typeof(Canvas));
|
||||
nestedCanvasGO.transform.SetParent(canvasGO.transform);
|
||||
|
||||
var rectTransform = (RectTransform)nestedCanvasGO.transform;
|
||||
rectTransform.anchorMin = Vector2.zero;
|
||||
rectTransform.anchorMax = Vector2.one;
|
||||
rectTransform.anchoredPosition = Vector2.zero;
|
||||
rectTransform.sizeDelta = new Vector2(-20f, -20f);
|
||||
|
||||
var bridgeObject = GameObject.Find(BridgeScriptForRetainingObjects.bridgeObjectName) ?? new GameObject(BridgeScriptForRetainingObjects.bridgeObjectName);
|
||||
var component = bridgeObject.GetComponent<BridgeScriptForRetainingObjects>() ?? bridgeObject.AddComponent<BridgeScriptForRetainingObjects>();
|
||||
component.canvasGO = canvasGO;
|
||||
component.nestedCanvasGO = nestedCanvasGO;
|
||||
|
||||
canvasGO.SetActive(false);
|
||||
nestedCanvasGO.SetActive(false);
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_BridgeComponent = GameObject.Find(BridgeScriptForRetainingObjects.bridgeObjectName).GetComponent<BridgeScriptForRetainingObjects>();
|
||||
m_BridgeComponent.canvasGO.SetActive(true);
|
||||
m_BridgeComponent.nestedCanvasGO.SetActive(true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NestedCanvasMaintainsCorrectSizeAtGameStart()
|
||||
{
|
||||
var rectTransform = (RectTransform)m_BridgeComponent.nestedCanvasGO.transform;
|
||||
Assert.That(rectTransform.anchoredPosition, Is.EqualTo(Vector2.zero));
|
||||
Assert.That(rectTransform.sizeDelta, Is.EqualTo(new Vector2(-20f, -20f)));
|
||||
Assert.That(rectTransform.anchorMin, Is.EqualTo(Vector2.zero));
|
||||
Assert.That(rectTransform.anchorMax, Is.EqualTo(Vector2.one));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_BridgeComponent.canvasGO);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be07f70ee67e6d74e851a9333719bbb6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.Profiling;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEditor;
|
||||
|
||||
[TestFixture]
|
||||
[UnityPlatform(include = new RuntimePlatform[] { RuntimePlatform.OSXEditor, RuntimePlatform.LinuxEditor, RuntimePlatform.WindowsEditor })]
|
||||
[Category("RegressionTest")]
|
||||
[Description("CoveredBugID = 883807, CoveredBugDescription = \"Object::GetInstanceID crash when trying to switch canvas\"")]
|
||||
public class NoActiveCameraInSceneDoesNotCrashEditor : IPrebuildSetup
|
||||
{
|
||||
Scene m_InitScene;
|
||||
const string k_SceneName = "NoActiveCameraInSceneDoesNotCrashEditorScene";
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Action codeToExecute = delegate()
|
||||
{
|
||||
UnityEditor.EditorApplication.ExecuteMenuItem("GameObject/UI/Legacy/Button");
|
||||
};
|
||||
|
||||
CreateSceneUtility.CreateScene(k_SceneName, codeToExecute);
|
||||
#endif
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_InitScene = SceneManager.GetActiveScene();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator EditorShouldNotCrashWithoutActiveCamera()
|
||||
{
|
||||
AsyncOperation operationResult = SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
|
||||
yield return operationResult;
|
||||
|
||||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
|
||||
|
||||
Profiler.enabled = true;
|
||||
Camera.main.gameObject.SetActive(false);
|
||||
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
Assert.That(Profiler.enabled, Is.True, "Expected the profiler to be enabled. Unable to test if the profiler will crash the editor if it is not enabled.");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
SceneManager.SetActiveScene(m_InitScene);
|
||||
SceneManager.UnloadSceneAsync(k_SceneName);
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset("Assets/" + k_SceneName + ".unity");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9c21cfda3336137438c3001d40564be0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Graphics
|
||||
{
|
||||
[Category("RegressionTest")]
|
||||
[Description("CoveredBugID = 1395695, CoveredBugDescription = \"RectMask2D hides all content when parented from other display to first dislpay in the Game view window\"")]
|
||||
public class RectMask2DReparentedToDifferentCanvas
|
||||
{
|
||||
GameObject m_GameObjectA;
|
||||
GameObject m_GameObjectB;
|
||||
Canvas m_CanvasA;
|
||||
Canvas m_CanvasB;
|
||||
RectMask2D m_Mask;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_GameObjectA = new GameObject("Canvas A");
|
||||
m_GameObjectB = new GameObject("Canvas B");
|
||||
m_CanvasA = m_GameObjectA.AddComponent<Canvas>();
|
||||
m_CanvasB = m_GameObjectB.AddComponent<Canvas>();
|
||||
|
||||
var rectMaskGameObject = new GameObject("RectMask2D");
|
||||
m_Mask = rectMaskGameObject.AddComponent<RectMask2D>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Object.DestroyImmediate(m_Mask.gameObject);
|
||||
Object.DestroyImmediate(m_GameObjectA);
|
||||
Object.DestroyImmediate(m_GameObjectB);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ReparentingRectMask2D_UpdatesCanvas()
|
||||
{
|
||||
m_Mask.transform.SetParent(m_GameObjectA.transform);
|
||||
Assert.AreSame(m_CanvasA, m_Mask.Canvas);
|
||||
|
||||
m_Mask.transform.SetParent(m_GameObjectB.transform);
|
||||
Assert.AreSame(m_CanvasB, m_Mask.Canvas, "Expected Canvas to be updated after parent changed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ba506934dc2ce14591a37f3b00dca92
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Graphics
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("RegressionTest")]
|
||||
[Description(
|
||||
"CoveredBugID = 782957, CoveredBugDescription = \"Some element from scroll view are invisible when they're masked with RectMask2D and sub-canvases\"")]
|
||||
public class RectMask2DWithNestedCanvasCullsUsingCorrectCanvasRect
|
||||
{
|
||||
GameObject m_RootCanvasGO;
|
||||
GameObject m_MaskGO;
|
||||
GameObject m_ImageGO;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_RootCanvasGO = new GameObject("Canvas");
|
||||
m_MaskGO = new GameObject("Mask", typeof(RectMask2D));
|
||||
m_ImageGO = new GameObject("Image");
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator RectMask2DShouldNotCullImagesWithCanvas()
|
||||
{
|
||||
//Root Canvas
|
||||
var canvas = m_RootCanvasGO.AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
// Rectmaskk2D
|
||||
var maskRect = m_MaskGO.GetComponent<RectTransform>();
|
||||
maskRect.sizeDelta = new Vector2(200, 200);
|
||||
|
||||
// Our image that will be in the RectMask2D
|
||||
var image = m_ImageGO.AddComponent<Image>();
|
||||
var imageRenderer = m_ImageGO.GetComponent<CanvasRenderer>();
|
||||
var imageRect = m_ImageGO.GetComponent<RectTransform>();
|
||||
m_ImageGO.AddComponent<Canvas>();
|
||||
imageRect.sizeDelta = new Vector2(10, 10);
|
||||
|
||||
m_MaskGO.transform.SetParent(canvas.transform);
|
||||
image.transform.SetParent(m_MaskGO.transform);
|
||||
imageRect.position = maskRect.position = Vector3.zero;
|
||||
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
|
||||
Assert.That(imageRenderer.cull, Is.False,
|
||||
"Expected image(with canvas) to not be culled by the RectMask2D but it was.");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_RootCanvasGO);
|
||||
GameObject.DestroyImmediate(m_MaskGO);
|
||||
GameObject.DestroyImmediate(m_ImageGO);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 735d54f21944f834f931716514c87a84
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using UnityEditor;
|
||||
|
||||
[TestFixture]
|
||||
public class RectTransformValidAfterEnable : IPrebuildSetup
|
||||
{
|
||||
const string kSceneName = "DisabledCanvasScene";
|
||||
const string kGameObjectName = "DisabledCanvas";
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
Action codeToExecute = delegate()
|
||||
{
|
||||
var canvasGameObject = new GameObject(kGameObjectName, typeof(Canvas));
|
||||
canvasGameObject.SetActive(false);
|
||||
canvasGameObject.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
canvasGameObject.GetComponent<RectTransform>().sizeDelta = new Vector2(0, 0);
|
||||
canvasGameObject.GetComponent<RectTransform>().anchoredPosition = new Vector2(0, 0);
|
||||
CanvasScaler canvasScaler = canvasGameObject.AddComponent<CanvasScaler>();
|
||||
canvasScaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
||||
canvasScaler.referenceResolution = new Vector2(1024, 768);
|
||||
};
|
||||
CreateSceneUtility.CreateScene(kSceneName, codeToExecute);
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator CheckRectTransformValidAfterEnable()
|
||||
{
|
||||
AsyncOperation operation = SceneManager.LoadSceneAsync(kSceneName, LoadSceneMode.Additive);
|
||||
yield return operation;
|
||||
|
||||
Scene scene = SceneManager.GetSceneByName(kSceneName);
|
||||
GameObject[] gameObjects = scene.GetRootGameObjects();
|
||||
GameObject canvasGameObject = null;
|
||||
foreach (GameObject gameObject in gameObjects)
|
||||
{
|
||||
if (gameObject.name == kGameObjectName)
|
||||
{
|
||||
canvasGameObject = gameObject;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Assert.IsNotNull(canvasGameObject);
|
||||
|
||||
RectTransform rectTransform = canvasGameObject.GetComponent<RectTransform>();
|
||||
canvasGameObject.SetActive(true);
|
||||
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
Rect rect = rectTransform.rect;
|
||||
Assert.Greater(rect.width, 0);
|
||||
Assert.Greater(rect.height, 0);
|
||||
|
||||
operation = SceneManager.UnloadSceneAsync(kSceneName);
|
||||
yield return operation;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
//Manually add Assets/ and .unity as CreateSceneUtility does that for you.
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.DeleteAsset("Assets/" + kSceneName + ".unity");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 811d999912a5f3f459a637aad029fbc8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,76 @@
|
||||
using NUnit.Framework;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
public class RectangleContainsScreenPointTest : MonoBehaviour
|
||||
{
|
||||
RectTransform m_RectTransform;
|
||||
Camera m_MainCamera;
|
||||
GameObject m_CanvasObject;
|
||||
GameObject m_RectObject;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
m_MainCamera = new GameObject("MainCamera").AddComponent<Camera>();
|
||||
m_MainCamera.transform.position = new Vector3(0, 1, -10);
|
||||
m_MainCamera.depth = -1;
|
||||
|
||||
m_CanvasObject = new GameObject("Canvas");
|
||||
Canvas m_canvas = m_CanvasObject.AddComponent<Canvas>();
|
||||
m_canvas.transform.localPosition = new Vector3(0, 1, 90);
|
||||
m_canvas.renderMode = RenderMode.ScreenSpaceCamera;
|
||||
m_canvas.worldCamera = m_MainCamera;
|
||||
|
||||
m_RectObject = new GameObject("RectTransformObject");
|
||||
m_RectTransform = m_RectObject.AddComponent<RectTransform>();
|
||||
m_RectTransform.SetParent(m_CanvasObject.transform, false);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Destroy(m_MainCamera.gameObject);
|
||||
Destroy(m_CanvasObject);
|
||||
Destroy(m_RectObject);
|
||||
Destroy(m_RectTransform);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RectangleContainsScreenPoint_ReturnsTrue_ForAllPointsInTheRectangle()
|
||||
{
|
||||
var fourCourners = new Vector3[4];
|
||||
m_RectTransform.GetWorldCorners(fourCourners);
|
||||
|
||||
var worldCorners = fourCourners
|
||||
.Select(p => m_MainCamera.WorldToScreenPoint(p))
|
||||
.ToArray();
|
||||
|
||||
var minValue = new Vector2(
|
||||
x: worldCorners.Min(p => p.x),
|
||||
y: worldCorners.Min(p => p.y));
|
||||
|
||||
var maxValue = new Vector2(
|
||||
x: worldCorners.Max(p => p.x),
|
||||
y: worldCorners.Max(p => p.y));
|
||||
|
||||
var steps = 10000;
|
||||
bool ErrorHit = false;
|
||||
|
||||
for (float i = 0; i < steps; i++)
|
||||
{
|
||||
var point = Vector2.Lerp(minValue, maxValue, i / steps);
|
||||
if (!RectTransformUtility.RectangleContainsScreenPoint(m_RectTransform, point, m_MainCamera))
|
||||
{
|
||||
ErrorHit = true;
|
||||
Assert.Fail("Rectangle does not Contains ScreenPoint");
|
||||
}
|
||||
}
|
||||
|
||||
if (!ErrorHit)
|
||||
{
|
||||
Assert.Pass();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 08a8587e5f07fb64f88a0cbe2ebe327e
|
||||
@@ -0,0 +1,83 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using NUnit.Framework;
|
||||
using System.Collections;
|
||||
using UnityEngine.UI;
|
||||
|
||||
[TestFixture]
|
||||
[Category("RegressionTest")]
|
||||
[Description("Case 723062")]
|
||||
public class SiblingOrderChangesLayout
|
||||
{
|
||||
GameObject m_CanvasGO;
|
||||
GameObject m_ParentGO;
|
||||
GameObject m_Child1GO;
|
||||
GameObject m_Child2GO;
|
||||
|
||||
[SetUp]
|
||||
public void TestSetup()
|
||||
{
|
||||
m_CanvasGO = new GameObject("Canvas", typeof(Canvas));
|
||||
m_ParentGO = new GameObject("ParentRenderer");
|
||||
m_Child1GO = CreateTextObject("ChildRenderer1");
|
||||
m_Child2GO = CreateTextObject("ChildRenderer2");
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.ExecuteMenuItem("Window/General/Game");
|
||||
#endif
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator ReorderingSiblingChangesLayout()
|
||||
{
|
||||
m_ParentGO.transform.SetParent(m_CanvasGO.transform);
|
||||
m_Child1GO.transform.SetParent(m_ParentGO.transform);
|
||||
m_Child2GO.transform.SetParent(m_ParentGO.transform);
|
||||
|
||||
m_ParentGO.AddComponent<CanvasRenderer>();
|
||||
m_ParentGO.AddComponent<RectTransform>();
|
||||
m_ParentGO.AddComponent<VerticalLayoutGroup>();
|
||||
m_ParentGO.AddComponent<ContentSizeFitter>();
|
||||
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
Vector2 child1Pos = m_Child1GO.GetComponent<RectTransform>().anchoredPosition;
|
||||
Vector2 child2Pos = m_Child2GO.GetComponent<RectTransform>().anchoredPosition;
|
||||
|
||||
Assert.That(child1Pos, Is.Not.EqualTo(child2Pos));
|
||||
Assert.That(m_Child1GO.GetComponent<CanvasRenderer>().hasMoved, Is.False, "CanvasRenderer.hasMoved should be false");
|
||||
|
||||
m_Child2GO.transform.SetAsFirstSibling();
|
||||
Canvas.ForceUpdateCanvases();
|
||||
|
||||
Assert.That(m_Child1GO.GetComponent<CanvasRenderer>().hasMoved, Is.True, "CanvasRenderer.hasMoved should be true");
|
||||
Vector2 newChild1Pos = m_Child1GO.GetComponent<RectTransform>().anchoredPosition;
|
||||
Vector2 newChild2Pos = m_Child2GO.GetComponent<RectTransform>().anchoredPosition;
|
||||
|
||||
Assert.That(newChild1Pos, Is.EqualTo(child2Pos), "Child1 should have moved to Child2's position");
|
||||
Assert.That(newChild2Pos, Is.EqualTo(child1Pos), "Child2 should have moved to Child1's position");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
GameObject.DestroyImmediate(m_CanvasGO);
|
||||
}
|
||||
|
||||
// Factory method for creating UI text objects taken from the original bug repro scene:
|
||||
private GameObject CreateTextObject(string name)
|
||||
{
|
||||
GameObject outputTextGameObject = new GameObject("OutputContent", typeof(CanvasRenderer));
|
||||
|
||||
RectTransform outputTextTransform = outputTextGameObject.AddComponent<RectTransform>();
|
||||
outputTextTransform.pivot = new Vector2(0.5f, 0);
|
||||
outputTextTransform.anchorMin = Vector2.zero;
|
||||
outputTextTransform.anchorMax = new Vector2(1, 0);
|
||||
outputTextTransform.anchoredPosition = Vector2.zero;
|
||||
outputTextTransform.sizeDelta = Vector2.zero;
|
||||
|
||||
Text outputText = outputTextGameObject.AddComponent<Text>();
|
||||
outputText.text = "Hello World!";
|
||||
outputTextGameObject.name = name;
|
||||
return outputTextGameObject;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c32df609537c54c46adf92992a673693
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bae197be297529d4fa735fbe7c91828d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,162 @@
|
||||
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(RectTransform), typeof(Dropdown));
|
||||
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);
|
||||
GameObject.DestroyImmediate(m_CameraGO);
|
||||
}
|
||||
|
||||
[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,151 @@
|
||||
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 GraphicRaycasterUsesGraphicPadding()
|
||||
{
|
||||
m_CanvasRectTrans.anchoredPosition3D = new Vector3(0, 0, 11);
|
||||
m_TextComponent.raycastPadding = new Vector4(-50, -50, -50, -50);
|
||||
m_Camera.farClipPlane = 12;
|
||||
yield return null;
|
||||
|
||||
var results = new List<RaycastResult>();
|
||||
var pointerEvent = new PointerEventData(m_EventSystem)
|
||||
{
|
||||
position = new Vector2((Screen.width / 2f) - 60, Screen.height / 2f)
|
||||
};
|
||||
|
||||
m_EventSystem.RaycastAll(pointerEvent, results);
|
||||
|
||||
Assert.IsNotEmpty(results, "Expected at least 1 result from a raycast outside the graphics RectTransform whose padding would make the click hit.");
|
||||
}
|
||||
|
||||
[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 ");
|
||||
}
|
||||
#if ENABLE_INPUT_SYSTEM && PACKAGE_INPUTSYSTEM
|
||||
[UnityTest]
|
||||
public IEnumerator GraphicRaycasterIgnoresEventsFromTheWrongDisplay()
|
||||
{
|
||||
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),
|
||||
displayIndex = 1,
|
||||
};
|
||||
|
||||
m_EventSystem.RaycastAll(pointerEvent, results);
|
||||
|
||||
Assert.IsEmpty(results, "Pointer event on display 1 was not ignored on display 0");
|
||||
}
|
||||
#endif
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Object.DestroyImmediate(m_Camera.gameObject);
|
||||
Object.DestroyImmediate(m_EventSystem.gameObject);
|
||||
Object.DestroyImmediate(m_Canvas.gameObject);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user