39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
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
|
|
}
|
|
} |