EnterPlayMode.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections;
  3. using UnityEditor;
  4. namespace UnityEngine.TestTools
  5. {
  6. public class EnterPlayMode : IEditModeTestYieldInstruction
  7. {
  8. public bool ExpectDomainReload { get; }
  9. public bool ExpectedPlaymodeState { get; private set; }
  10. public EnterPlayMode(bool expectDomainReload = true)
  11. {
  12. ExpectDomainReload = expectDomainReload;
  13. }
  14. public IEnumerator Perform()
  15. {
  16. if (EditorApplication.isPlaying)
  17. {
  18. throw new Exception("Editor is already in PlayMode");
  19. }
  20. if (EditorUtility.scriptCompilationFailed)
  21. {
  22. throw new Exception("Script compilation failed");
  23. }
  24. yield return null;
  25. ExpectedPlaymodeState = true;
  26. EditorApplication.UnlockReloadAssemblies();
  27. EditorApplication.isPlaying = true;
  28. while (!EditorApplication.isPlaying)
  29. {
  30. yield return null;
  31. }
  32. }
  33. }
  34. }