WaitForDomainReload.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections;
  3. using UnityEditor;
  4. namespace UnityEngine.TestTools
  5. {
  6. public class WaitForDomainReload : IEditModeTestYieldInstruction
  7. {
  8. public WaitForDomainReload()
  9. {
  10. ExpectDomainReload = true;
  11. }
  12. public bool ExpectDomainReload { get;  }
  13. public bool ExpectedPlaymodeState { get; }
  14. public IEnumerator Perform()
  15. {
  16. EditorApplication.UnlockReloadAssemblies();
  17. // Detect if AssetDatabase.Refresh was called (true) or if it will be called on next tick
  18. bool isAsync = EditorApplication.isCompiling;
  19. yield return null;
  20. if (!isAsync)
  21. {
  22. EditorApplication.LockReloadAssemblies();
  23. throw new Exception("Expected domain reload, but it did not occur");
  24. }
  25. while (EditorApplication.isCompiling)
  26. {
  27. yield return null;
  28. }
  29. if (EditorUtility.scriptCompilationFailed)
  30. {
  31. EditorApplication.LockReloadAssemblies();
  32. throw new Exception("Script compilation failed");
  33. }
  34. }
  35. }
  36. }