File size: 7,221 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | using System;
using UnityEngine.UI;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
[TestFixture]
[Category("RegressionTest")]
public class SceneWithNestedLayoutElementsLoad : IPrebuildSetup
{
Scene m_InitScene;
const string aspectRatioFitterSceneName = "AspectRatioFitter";
const string contentSizeFitterSceneName = "ContentSizeFitter";
const string layoutGroupSceneName = "LayoutGroup";
public void Setup()
{
#if UNITY_EDITOR
Action aspectRatioFitterSceneCreation = delegate()
{
var canvasGO = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler));
var panelGO = new GameObject("Panel", typeof(UnityEngine.UI.Image), typeof(AspectRatioFitter));
var imageGO = new GameObject("Image", typeof(UnityEngine.UI.RawImage), typeof(AspectRatioFitter));
panelGO.transform.SetParent(canvasGO.transform);
imageGO.transform.SetParent(panelGO.transform);
var panelARF = panelGO.GetComponent<AspectRatioFitter>();
panelARF.aspectMode = AspectRatioFitter.AspectMode.EnvelopeParent;
panelARF.aspectRatio = 1.98f;
var iamgeARF = imageGO.GetComponent<AspectRatioFitter>();
iamgeARF.aspectMode = AspectRatioFitter.AspectMode.None;
iamgeARF.aspectRatio = 1f;
new GameObject("GameObject", typeof(SceneWithNestedLayoutElementsLoadScript));
};
CreateSceneUtility.CreateScene(aspectRatioFitterSceneName, aspectRatioFitterSceneCreation);
Action contentSizeFitterSceneCreation = delegate()
{
var canvasGO = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler));
var panelGO = new GameObject("Panel", typeof(UnityEngine.UI.Image), typeof(ContentSizeFitter), typeof(LayoutElement));
var imageGO = new GameObject("Image", typeof(UnityEngine.UI.RawImage), typeof(ContentSizeFitter), typeof(LayoutElement));
panelGO.transform.SetParent(canvasGO.transform);
imageGO.transform.SetParent(panelGO.transform);
var panelCSF = panelGO.GetComponent<ContentSizeFitter>();
panelCSF.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
panelCSF.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
var panelLE = panelGO.GetComponent<LayoutElement>();
panelLE.preferredWidth = 200f;
panelLE.preferredHeight = 200f;
var imageCSF = imageGO.GetComponent<ContentSizeFitter>();
imageCSF.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
imageCSF.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
var imageLE = imageGO.GetComponent<LayoutElement>();
imageLE.preferredWidth = 100f;
imageLE.preferredHeight = 100f;
new GameObject("GameObject", typeof(SceneWithNestedLayoutElementsLoadScript));
};
CreateSceneUtility.CreateScene(contentSizeFitterSceneName, contentSizeFitterSceneCreation);
Action layoutGroupSceneCreation = delegate()
{
var canvasGO = new GameObject("Canvas", typeof(Canvas), typeof(CanvasScaler), typeof(GridLayoutGroup));
var panelGO = new GameObject("Panel (0)", typeof(UnityEngine.UI.Image), typeof(GridLayoutGroup), typeof(LayoutElement));
var imageGOOne = new GameObject("Image", typeof(UnityEngine.UI.RawImage), typeof(LayoutElement));
var imageGOTwo = new GameObject("Image", typeof(UnityEngine.UI.RawImage), typeof(LayoutElement));
panelGO.transform.SetParent(canvasGO.transform);
imageGOOne.transform.SetParent(panelGO.transform);
imageGOTwo.transform.SetParent(panelGO.transform);
var panelLE = panelGO.GetComponent<LayoutElement>();
panelLE.preferredWidth = 100f;
panelLE.preferredHeight = 100f;
var imageOneLE = imageGOOne.GetComponent<LayoutElement>();
imageOneLE.preferredWidth = 100f;
imageOneLE.preferredHeight = 100f;
var imageTwoLE = imageGOOne.GetComponent<LayoutElement>();
imageTwoLE.preferredWidth = 100f;
imageTwoLE.preferredHeight = 100f;
// Duplicate the first panel we created.
GameObject.Instantiate(panelGO, canvasGO.transform);
new GameObject("GameObject", typeof(SceneWithNestedLayoutElementsLoadScript));
};
CreateSceneUtility.CreateScene(layoutGroupSceneName, layoutGroupSceneCreation);
#endif
}
[UnityTest]
public IEnumerator SceneWithNestedAspectRatioFitterLoads()
{
AsyncOperation operation = SceneManager.LoadSceneAsync(aspectRatioFitterSceneName, LoadSceneMode.Additive);
yield return operation;
SceneManager.SetActiveScene(SceneManager.GetSceneByName(aspectRatioFitterSceneName));
var go = GameObject.Find("GameObject");
var component = go.GetComponent<SceneWithNestedLayoutElementsLoadScript>();
yield return new WaitUntil(() => component.isStartCalled);
operation = SceneManager.UnloadSceneAsync(aspectRatioFitterSceneName);
yield return operation;
}
[UnityTest]
public IEnumerator SceneWithNestedContentSizeFitterLoads()
{
AsyncOperation operation = SceneManager.LoadSceneAsync(contentSizeFitterSceneName, LoadSceneMode.Additive);
yield return operation;
SceneManager.SetActiveScene(SceneManager.GetSceneByName(contentSizeFitterSceneName));
var go = GameObject.Find("GameObject");
var component = go.GetComponent<SceneWithNestedLayoutElementsLoadScript>();
yield return new WaitUntil(() => component.isStartCalled);
operation = SceneManager.UnloadSceneAsync(contentSizeFitterSceneName);
yield return operation;
}
[UnityTest]
public IEnumerator SceneWithNestedLayoutGroupLoads()
{
AsyncOperation operation = SceneManager.LoadSceneAsync(layoutGroupSceneName, LoadSceneMode.Additive);
yield return operation;
SceneManager.SetActiveScene(SceneManager.GetSceneByName(layoutGroupSceneName));
var go = GameObject.Find("GameObject");
var component = go.GetComponent<SceneWithNestedLayoutElementsLoadScript>();
yield return new WaitUntil(() => component.isStartCalled);
operation = SceneManager.UnloadSceneAsync(layoutGroupSceneName);
yield return operation;
}
[SetUp]
public void TestSetup()
{
m_InitScene = SceneManager.GetActiveScene();
}
[TearDown]
public void TearDown()
{
SceneManager.SetActiveScene(m_InitScene);
}
[OneTimeTearDown]
public void OnTimeTearDown()
{
//Manually add Assets/ and .unity as CreateSceneUtility does that for you.
#if UNITY_EDITOR
AssetDatabase.DeleteAsset("Assets/" + aspectRatioFitterSceneName + ".unity");
AssetDatabase.DeleteAsset("Assets/" + contentSizeFitterSceneName + ".unity");
AssetDatabase.DeleteAsset("Assets/" + layoutGroupSceneName + ".unity");
#endif
}
}
|