Skip to content

Commit

Permalink
Merge pull request #17 from mewlist/testable-scene-loading
Browse files Browse the repository at this point in the history
Testable scene loading
  • Loading branch information
mewlist authored Jan 26, 2024
2 parents 1c1350d + bb7aabc commit 9a81f46
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
19 changes: 18 additions & 1 deletion Runtime/Assets/Scene/SceneLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Mew.Core.TaskHelpers;
using UnityEngine;
using UnityEngine.SceneManagement;

#if USE_MEW_CORE_ASSETS
using UnityEngine.AddressableAssets;
#endif

#if UNITY_EDITOR
using UnityEditor.SceneManagement;
#endif

namespace Mew.Core.Assets
{
public class SceneLoader : IAsyncDisposable
Expand All @@ -36,6 +39,7 @@ public async ValueTask<Scene> LoadAsync(UnifiedScene unifiedScene, CancellationT
}
else
#endif
if (unifiedScene.SceneReference is not null && unifiedScene.SceneReference.IsValid)
{
#if UNITY_2023_2_OR_NEWER
await SceneManager.LoadSceneAsync(unifiedScene.SceneReference, parameters);
Expand All @@ -47,6 +51,19 @@ public async ValueTask<Scene> LoadAsync(UnifiedScene unifiedScene, CancellationT
var loadedScene = SceneManager.GetSceneAt(SceneManager.loadedSceneCount - 1);
handle = new SceneHandle(loadedScene);
}
#if UNITY_EDITOR
// for test use
else if (!string.IsNullOrEmpty(unifiedScene.EditorScenePath))
{
await EditorSceneManager.LoadSceneAsyncInPlayMode(unifiedScene.EditorScenePath , parameters ) ;
var loadedScene = SceneManager.GetSceneAt(SceneManager.loadedSceneCount - 1);
handle = new SceneHandle(loadedScene);
}
#endif
else
{
throw new ArgumentException("SceneReference is not valid.");
}

var scene = await handle.GetScene();

Expand Down
10 changes: 9 additions & 1 deletion Runtime/Assets/Scene/UnifiedScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class UnifiedScene
#endif
[field: SerializeField] public SceneReference SceneReference { get; set; }

#if UNITY_EDITOR
[field: SerializeField] public string EditorScenePath { get; set; }
#endif

public bool IsSceneReference => SceneReference?.IsValid ?? false;
public bool IsSceneAssetReference
Expand All @@ -41,6 +44,11 @@ public bool IsSceneResourceLocation
}
}

public bool IsValid => IsSceneReference || IsSceneAssetReference || IsSceneResourceLocation;
private bool IsValidInternal => IsSceneReference || IsSceneAssetReference || IsSceneResourceLocation;
#if UNITY_EDITOR
public bool IsValid => IsValidInternal || !string.IsNullOrEmpty(EditorScenePath);
#else
public bool IsValid => IsValidInternal;
#endif
}
}
2 changes: 1 addition & 1 deletion Runtime/MewLoop/MewLoopUnityInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct MewManualUpdate { }
public static class MewLoopUnityInitializer
{

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void Init()
{
Register<MewUnityEarlyUpdate, EarlyUpdate>();
Expand Down

0 comments on commit 9a81f46

Please sign in to comment.