Geen omschrijving
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.

ExitPlayMode.cs 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections;
  3. using UnityEditor;
  4. namespace UnityEngine.TestTools
  5. {
  6. /// <summary>
  7. /// Implements <see cref="IEditModeTestYieldInstruction"/>. A new instance of the class is a yield instruction to exit Play Mode.
  8. /// </summary>
  9. public class ExitPlayMode : IEditModeTestYieldInstruction
  10. {
  11. /// <summary>
  12. /// Gets the value of ExpectDomainReload
  13. /// </summary>
  14. public bool ExpectDomainReload { get; }
  15. /// <summary>
  16. /// Gets the value of ExpectedPlaymodeState
  17. /// </summary>
  18. public bool ExpectedPlaymodeState { get; private set; }
  19. /// <summary>
  20. /// Sets ExpectDomainReload and ExpectedPlaymodeState to false.
  21. /// </summary>
  22. public ExitPlayMode()
  23. {
  24. ExpectDomainReload = false;
  25. ExpectedPlaymodeState = false;
  26. }
  27. /// <summary>
  28. /// Performs the multi-step instruction of exiting PlayMode.
  29. /// </summary>
  30. /// <returns>An IEnumerator with the async steps.</returns>
  31. /// <exception cref="Exception">An exception is thrown if the editor is not in PlayMode.</exception>
  32. public IEnumerator Perform()
  33. {
  34. if (!EditorApplication.isPlayingOrWillChangePlaymode)
  35. {
  36. throw new Exception("Editor is already in EditMode");
  37. }
  38. EditorApplication.isPlaying = false;
  39. while (EditorApplication.isPlaying)
  40. {
  41. yield return null;
  42. }
  43. }
  44. }
  45. }