Skip to content

Commit

Permalink
Merge pull request #89 from nowsprinting/fix/scene_manager_helper
Browse files Browse the repository at this point in the history
Add specify LoadSceneParameters
  • Loading branch information
nowsprinting committed Jun 23, 2024
2 parents ddc4574 + 18a3601 commit 30554f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Runtime/Attributes/LoadSceneAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Runtime.CompilerServices;
using NUnit.Framework.Interfaces;
using TestHelper.RuntimeInternals;
using UnityEngine.SceneManagement;
using UnityEngine.TestTools;

namespace TestHelper.Attributes
Expand Down Expand Up @@ -45,7 +46,8 @@ public LoadSceneAttribute(string path, [CallerFilePath] string callerFilePath =
public IEnumerator BeforeTest(ITest test)
{
// ReSharper disable once ExplicitCallerInfoArgument
yield return SceneManagerHelper.LoadSceneAsync(ScenePath, CallerFilePath);
yield return SceneManagerHelper.LoadSceneAsync(ScenePath, LoadSceneMode.Single, LocalPhysicsMode.None,
CallerFilePath);
}

/// <inheritdoc />
Expand Down
18 changes: 12 additions & 6 deletions RuntimeInternals/SceneManagerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,18 @@ public static class SceneManagerHelper
/// And package name using `name` instead of `displayName`, when scenes in the package.
/// (e.g., `Packages/com.nowsprinting.test-helper/Tests/Scenes/Scene.unity`)
/// </param>
/// <param name="mode">See LoadSceneMode. Not used when called from Edit Mode tests</param>
/// <param name="physicsMode">See SceneManagement.LocalPhysicsMode. Not used when called from Edit Mode tests</param>
/// <returns></returns>
/// <remarks>
/// When loading the scene that is not in "Scenes in Build", use <see cref="TestHelper.Attributes.BuildSceneAttribute"/>.
/// </remarks>
[SuppressMessage("ReSharper", "InvalidXmlDocComment")]
public static IEnumerator LoadSceneAsync(string path, [CallerFilePath] string callerFilePath = null)
public static IEnumerator LoadSceneAsync(
string path,
LoadSceneMode mode = LoadSceneMode.Single,
LocalPhysicsMode physicsMode = LocalPhysicsMode.None,
[CallerFilePath] string callerFilePath = null)
{
var existScenePath = GetExistScenePath(path, callerFilePath);
AsyncOperation loadSceneAsync = null;
Expand All @@ -51,21 +57,21 @@ public static IEnumerator LoadSceneAsync(string path, [CallerFilePath] string ca
if (Application.isPlaying)
{
// Play Mode tests running in Editor
loadSceneAsync = EditorSceneManager.LoadSceneAsyncInPlayMode(
existScenePath,
new LoadSceneParameters(LoadSceneMode.Single));
loadSceneAsync = EditorSceneManager.LoadSceneAsyncInPlayMode(existScenePath,
new LoadSceneParameters(mode, physicsMode));
}
else
{
// Edit Mode tests
EditorSceneManager.OpenScene(existScenePath);
EditorSceneManager.OpenScene(existScenePath); // Note: Not accept LoadSceneParameters as an argument
}
#endif
}
else
{
// Play Mode tests running on Player
loadSceneAsync = SceneManager.LoadSceneAsync(existScenePath);
loadSceneAsync = SceneManager.LoadSceneAsync(existScenePath,
new LoadSceneParameters(mode, physicsMode));
}

yield return loadSceneAsync;
Expand Down

0 comments on commit 30554f1

Please sign in to comment.