Skip to content

Commit

Permalink
Merge dd81050 into 286cc2c
Browse files Browse the repository at this point in the history
  • Loading branch information
nowsprinting committed Oct 22, 2023
2 parents 286cc2c + dd81050 commit 244dec6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
28 changes: 19 additions & 9 deletions Runtime/Attributes/CreateSceneAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,31 @@ public CreateSceneAttribute(bool camera = false, bool light = false)
public IEnumerator BeforeTest(ITest test)
{
_newSceneName = $"Scene of {TestContext.CurrentContext.Test.FullName}";
#if UNITY_EDITOR
if (EditorApplication.isPlaying)

if (Application.isEditor)
{
var scene = SceneManager.CreateScene(_newSceneName);
SceneManager.SetActiveScene(scene);
#if UNITY_EDITOR
if (Application.isPlaying)
{
// Play Mode tests running in Editor
var scene = SceneManager.CreateScene(_newSceneName);
SceneManager.SetActiveScene(scene);
}
else
{
// Edit Mode tests
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
scene.name = _newSceneName;
}
#endif
}
else
{
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene);
scene.name = _newSceneName;
}
#else
// Play Mode tests running on Player
var scene = SceneManager.CreateScene(_newSceneName);
SceneManager.SetActiveScene(scene);
#endif
}

if (_camera)
{
var camera = new GameObject("Main Camera").AddComponent<Camera>();
Expand Down
32 changes: 20 additions & 12 deletions Runtime/Attributes/LoadSceneAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace TestHelper.Attributes
///
/// Notes:
/// - Load scene run after <c>OneTimeSetUp</c> and before <c>SetUp</c>
/// - For the process of including a Scene not in "Scenes in Build" to a build for player, see: <see cref="TestHelper.Editor.TemporaryBuildScenesUsingInTest"/>
/// - For the process of including a Scene not in "Scenes in Build" to a build for player, see: <see cref="Editor.TemporaryBuildScenesUsingInTest"/>
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class LoadSceneAttribute : NUnitAttribute, IOuterUnityTestAction
Expand All @@ -50,22 +50,30 @@ public LoadSceneAttribute(string path)
public IEnumerator BeforeTest(ITest test)
{
AsyncOperation loadSceneAsync = null;
#if UNITY_EDITOR
if (EditorApplication.isPlaying)

if (Application.isEditor)
{
// Use EditorSceneManager at run on Unity-editor
loadSceneAsync = EditorSceneManager.LoadSceneAsyncInPlayMode(
ScenePath,
new LoadSceneParameters(LoadSceneMode.Single));
#if UNITY_EDITOR
if (Application.isPlaying)
{
// Play Mode tests running in Editor
loadSceneAsync = EditorSceneManager.LoadSceneAsyncInPlayMode(
ScenePath,
new LoadSceneParameters(LoadSceneMode.Single));
}
else
{
// Edit Mode tests
EditorSceneManager.OpenScene(ScenePath);
}
#endif
}
else
{
EditorSceneManager.OpenScene(ScenePath);
// Play Mode tests running on Player
loadSceneAsync = SceneManager.LoadSceneAsync(ScenePath);
}
#else
// Use ITestPlayerBuildModifier to change the "Scenes in Build" list before run on player
loadSceneAsync = SceneManager.LoadSceneAsync(ScenePath);
#endif

yield return loadSceneAsync;
}

Expand Down

0 comments on commit 244dec6

Please sign in to comment.