Replies: 1 comment 1 reply
-
Found it. Quite interesting. using Pancake.Scriptable;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;
namespace Pancake.SceneFlow
{
[EditorIcon("csharp")]
public class SceneLoader : GameComponent
{
[SerializeField] private ScriptableEventString changeSceneEvent;
private void Start() { changeSceneEvent.OnRaised += OnChangeScene; }
private void OnChangeScene(string sceneName)
{
foreach (var scene in GetAllLoadedScene())
{
if (!scene.name.Equals(Constant.PERSISTENT_SCENE))
{
Addressables.UnloadSceneAsync(Static.sceneHolder[scene.name]);
Static.sceneHolder.Remove(scene.name);
}
}
Addressables.LoadSceneAsync(sceneName, LoadSceneMode.Additive).Completed += OnAdditiveSceneLoaded;
}
private void OnAdditiveSceneLoaded(AsyncOperationHandle<SceneInstance> handle)
{
if (handle.Status == AsyncOperationStatus.Succeeded)
{
string sceneName = handle.Result.Scene.name;
Static.sceneHolder.Add(sceneName, handle);
App.Delay(0.016f, () => SceneManager.SetActiveScene(SceneManager.GetSceneByName(sceneName)));
}
}
private Scene[] GetAllLoadedScene()
{
int countLoaded = SceneManager.sceneCount;
var loadedScenes = new Scene[countLoaded];
for (var i = 0; i < countLoaded; i++)
{
loadedScenes[i] = SceneManager.GetSceneAt(i);
}
return loadedScenes;
}
}
} ScriptableEventString event passing brilliant. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How do I add a scene to the scene list.
It loads the Initialization Scene first, then opens up other scenes (No matter which scene you are in)
But if one wants to add a new Scene, how would one add it. I wanted to see if there was any script that's running next scene or new scene, but couldn't find where to configure to add new Scene.
I tried to see more, but it directs me to private repo link, maybe.
https://github.com/gamee-studio/game-foundation
It's kinda interesting what you people are building over here.
Beta Was this translation helpful? Give feedback.
All reactions