Maze / Library /PackageCache /com.unity.ugui@1.0.0 /Tests /Runtime /Canvas /NoActiveCameraInSceneDoesNotCrashEditor.cs
| using System; | |
| using UnityEngine; | |
| using UnityEngine.TestTools; | |
| using NUnit.Framework; | |
| using System.Collections; | |
| using UnityEngine.Profiling; | |
| using UnityEngine.SceneManagement; | |
| using UnityEditor; | |
| [] | |
| [] { RuntimePlatform.OSXEditor, RuntimePlatform.LinuxEditor, RuntimePlatform.WindowsEditor })] | |
| [] | |
| [] | |
| public class NoActiveCameraInSceneDoesNotCrashEditor : IPrebuildSetup | |
| { | |
| Scene m_InitScene; | |
| const string k_SceneName = "NoActiveCameraInSceneDoesNotCrashEditorScene"; | |
| public void Setup() | |
| { | |
| Action codeToExecute = delegate() | |
| { | |
| UnityEditor.EditorApplication.ExecuteMenuItem("GameObject/UI/Legacy/Button"); | |
| }; | |
| CreateSceneUtility.CreateScene(k_SceneName, codeToExecute); | |
| } | |
| [] | |
| public void TestSetup() | |
| { | |
| m_InitScene = SceneManager.GetActiveScene(); | |
| } | |
| [] | |
| 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."); | |
| } | |
| [] | |
| public void TearDown() | |
| { | |
| SceneManager.SetActiveScene(m_InitScene); | |
| SceneManager.UnloadSceneAsync(k_SceneName); | |
| AssetDatabase.DeleteAsset("Assets/" + k_SceneName + ".unity"); | |
| } | |
| } | |