Implement SceneManager with asynchronous load/unload routines ready for bootstrapper scene. Implement simple level switching

This commit is contained in:
Michal Pikulski
2025-09-01 22:51:52 +02:00
parent e3b7f219cf
commit a03b70a1ca
22 changed files with 1063 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using System;
using UnityEngine;
public class LevelSwitch : MonoBehaviour
{
@@ -8,6 +9,9 @@ public class LevelSwitch : MonoBehaviour
void Awake()
{
if (iconRenderer == null)
iconRenderer = GetComponent<SpriteRenderer>();
interactable = GetComponent<Interactable>();
if (interactable != null)
{
@@ -27,6 +31,8 @@ public class LevelSwitch : MonoBehaviour
#if UNITY_EDITOR
void OnValidate()
{
if (iconRenderer == null)
iconRenderer = GetComponent<SpriteRenderer>();
ApplySwitchData();
}
#endif
@@ -42,9 +48,15 @@ public class LevelSwitch : MonoBehaviour
}
}
private void OnInteracted()
private async void OnInteracted()
{
Debug.Log($"LevelSwitch.OnInteracted: Switching to level {switchData?.targetLevelSceneName}");
// TODO: Add scene loading logic here, e.g. UnityEngine.SceneManagement.SceneManager.LoadScene(switchData.targetLevelSceneName);
if (switchData != null && !string.IsNullOrEmpty(switchData.targetLevelSceneName))
{
// Optionally: show loading UI here
var progress = new Progress<float>(p => Debug.Log($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.SwitchSceneAsync(switchData.targetLevelSceneName, progress);
// Optionally: hide loading UI here
}
}
}