SceneLoader

mail@pastecode.io avatar
unknown
java
2 months ago
873 B
14
Indexable
Never
public class SceneLoader : ISceneLoader
    {
        public async UniTask Load(string nextScene)
        {
            Application.backgroundLoadingPriority = ThreadPriority.High;
            AsyncOperationHandle<SceneInstance> handler =
                Addressables.LoadSceneAsync(nextScene, LoadSceneMode.Single, false);
            
            handler.Completed += handle =>
            {
                if (handle.Status == AsyncOperationStatus.Succeeded)
                {
                    Debug.Log($"Scene {nextScene} loaded successfully.");
                    handler.Result.ActivateAsync().ToUniTask();
                }
                else
                {
                    Debug.LogError($"Failed to load scene {nextScene}.");
                }
            };
            
            await handler.ToUniTask();
        }
    }
Leave a Comment