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