using System; using System.Collections; using UnityEditor; namespace UnityEngine.TestTools { /// /// Implements . A new instance of the class is a yield instruction to exit Play Mode. /// public class ExitPlayMode : IEditModeTestYieldInstruction { /// /// Gets the value of ExpectDomainReload /// public bool ExpectDomainReload { get; } /// /// Gets the value of ExpectedPlaymodeState /// public bool ExpectedPlaymodeState { get; private set; } /// /// Sets ExpectDomainReload and ExpectedPlaymodeState to false. /// public ExitPlayMode() { ExpectDomainReload = false; ExpectedPlaymodeState = false; } /// /// Performs the multi-step instruction of exiting PlayMode. /// /// An IEnumerator with the async steps. /// An exception is thrown if the editor is not in PlayMode. public IEnumerator Perform() { if (!EditorApplication.isPlayingOrWillChangePlaymode) { throw new Exception("Editor is already in EditMode"); } EditorApplication.isPlaying = false; while (EditorApplication.isPlaying) { yield return null; } } } }