I have a scene that acts as a loading screen of sorts for my main scene.
![alt text][1]
[1]: /storage/temp/165877-startbuttons.png
When this scene loads, I start an AsyncOperation to load the main scene. The "PLAY" button acts as an indicator of main scene's loading progress. When the main scene's loading progress reaches 0.9, the button activates, and pressing the button will load the remaining 0.1 progress and change to the main scene.
The other buttons load and change to other scenes when pressed. However, these scenes, also using AsyncOperation to load, do not start loading, being held up by the main scene's AsyncOperation. Is there any way to stop the main scene's AsyncOperation so that the other scenes can load?
For reference, my code is:
The Play button:
private void Start()
{
m_button.enabled = false;
m_slider.value = 0f;
StartCoroutine(LoadMainScene());
}
public void ActivateMainScene()
{
if (!GlobalTracker.Instance.SceneLoading)
{
m_canGoToMainScene = true;
}
}
private IEnumerator LoadMainScene()
{
//Start an asynchronous operation to load the main game scene
AsyncOperation async = SceneManager.LoadSceneAsync(m_mainGameBuildIndex);
async.allowSceneActivation = false;
//While the asynchronous operation to load the new scene is not yet complete, continue
//waiting until it's done.
while (!async.isDone)
{
//If another scene starts loading...
if(GlobalTracker.Instance.SceneLoading)
{
//Stop loading the main scene
}
m_slider.value = async.progress * (10f / 9f);
if (async.progress >= 0.9f)
{
m_button.enabled = true;
m_slider.value = 1f;
//Boolean activated by OnClick
if (m_canGoToMainScene)
{
async.allowSceneActivation = true;
}
}
yield return null;
}
}
The other buttons:
//Triggered by OnClick
//Activate the Load coroutine with the provided BuildIndex and activate the loading GameObject
public void LoadScene(int scene)
{
if (!ier_Load && !GlobalTracker.Instance.SceneLoading)
{
StartCoroutine(Load(scene));
m_loadingSymbol.SetActive(true);
}
}
private bool ier_Load = false; //Whether there is currently a scene loading
//Load the scene with the provided BuildIndex
private IEnumerator Load(int scene)
{
ier_Load = true;
GlobalTracker.Instance.SceneLoading = true;
//Start an asynchronous operation to load the scene that was passed to the LoadNewScene
//coroutine.
AsyncOperation async = SceneManager.LoadSceneAsync(scene);
//While the asynchronous operation to load the new scene is not yet complete, continue
//waiting until it's done.
while (!async.isDone)
{
print(async.progress);
yield return null;
}
ier_Load = false;
}
↧