Init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class BootstrapSceneLoader : MonoBehaviour
|
||||
{
|
||||
private const string RequestedScenePathKey = "SceneBootstrapLoader.RequestedScenePath";
|
||||
|
||||
[SerializeField] private string fallbackSceneName = "";
|
||||
|
||||
private async void Start()
|
||||
{
|
||||
string requestedScenePath = GetRequestedScenePath();
|
||||
|
||||
string sceneToLoad = !string.IsNullOrWhiteSpace(requestedScenePath)
|
||||
? System.IO.Path.GetFileNameWithoutExtension(requestedScenePath)
|
||||
: fallbackSceneName;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(sceneToLoad))
|
||||
{
|
||||
Debug.LogWarning("BootstrapSceneLoader: No requested scene and no fallback scene set.");
|
||||
return;
|
||||
}
|
||||
|
||||
Scene activeScene = SceneManager.GetActiveScene();
|
||||
if (activeScene.name == sceneToLoad)
|
||||
return;
|
||||
|
||||
await SceneManager.LoadSceneAsync(sceneToLoad, LoadSceneMode.Single);
|
||||
}
|
||||
|
||||
private string GetRequestedScenePath()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
return UnityEditor.EditorPrefs.GetString(RequestedScenePathKey, string.Empty);
|
||||
#else
|
||||
return string.Empty;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user