Brak opisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NoActiveCameraInSceneDoesNotCrashEditor.cs 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.TestTools;
  4. using NUnit.Framework;
  5. using System.Collections;
  6. using UnityEngine.Profiling;
  7. using UnityEngine.SceneManagement;
  8. using UnityEditor;
  9. [TestFixture]
  10. [UnityPlatform(include = new RuntimePlatform[] { RuntimePlatform.OSXEditor, RuntimePlatform.LinuxEditor, RuntimePlatform.WindowsEditor })]
  11. [Category("RegressionTest")]
  12. [Description("CoveredBugID = 883807, CoveredBugDescription = \"Object::GetInstanceID crash when trying to switch canvas\"")]
  13. public class NoActiveCameraInSceneDoesNotCrashEditor : IPrebuildSetup
  14. {
  15. Scene m_InitScene;
  16. const string k_SceneName = "NoActiveCameraInSceneDoesNotCrashEditorScene";
  17. public void Setup()
  18. {
  19. #if UNITY_EDITOR
  20. Action codeToExecute = delegate()
  21. {
  22. UnityEditor.EditorApplication.ExecuteMenuItem("GameObject/UI/Legacy/Button");
  23. };
  24. CreateSceneUtility.CreateScene(k_SceneName, codeToExecute);
  25. #endif
  26. }
  27. [SetUp]
  28. public void TestSetup()
  29. {
  30. m_InitScene = SceneManager.GetActiveScene();
  31. }
  32. [UnityTest]
  33. public IEnumerator EditorShouldNotCrashWithoutActiveCamera()
  34. {
  35. AsyncOperation operationResult = SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
  36. yield return operationResult;
  37. SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
  38. Profiler.enabled = true;
  39. Camera.main.gameObject.SetActive(false);
  40. yield return new WaitForSeconds(0.1f);
  41. 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.");
  42. }
  43. [TearDown]
  44. public void TearDown()
  45. {
  46. SceneManager.SetActiveScene(m_InitScene);
  47. SceneManager.UnloadSceneAsync(k_SceneName);
  48. #if UNITY_EDITOR
  49. AssetDatabase.DeleteAsset("Assets/" + k_SceneName + ".unity");
  50. #endif
  51. }
  52. }