Page 1 of 1

SceneTransitionManager - Loading Method

Posted: Wed Dec 15, 2021 6:50 pm
by VoodooDetective
Hey there! I was just wondering if you might consider adding a method like this to SceneTransitionManager:

Code: Select all

 public virtual void OnLoading(float progress) { }
Something that could be called from SaveSystem:

Code: Select all

        private static IEnumerator LoadSceneInternalTransitionCoroutine(string sceneName)
        {
            yield return instance.StartCoroutine(sceneTransitionManager.LeaveScene());
            if (sceneName.StartsWith("index:"))
            {
                var index = SafeConvert.ToInt(sceneName.Substring("index:".Length));
                m_currentAsyncOperation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(index);
            }
            else
            {
                m_currentAsyncOperation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName);
            }
            while (m_currentAsyncOperation != null && !m_currentAsyncOperation.isDone)
            {
                sceneTransitionManager.OnLoading(m_currentAsyncOperation.progress);
                yield return null;
            }
            sceneTransitionManager.OnLoading(1f);
            m_currentAsyncOperation = null;
            instance.StartCoroutine(sceneTransitionManager.EnterScene());
        }

Or maybe there's already a way to do this? I just realized I had started a coroutine that had the exact same while loop waiting for the loading to finish.

Re: SceneTransitionManager - Loading Method

Posted: Wed Dec 15, 2021 7:45 pm
by Tony Li
Hi,

If you want to update a progress bar or something while it's loading, check PixelCrushers.SaveSystem.currentAsyncOperation. Example:

Code: Select all

IEnumerator UpdateProgressBar()
{
    while (!SaveSystem.currentAsyncOperation.isDone)
    {
        progressBar.value = SaveSystem.currentAsyncOperation.progress;
    }
}

Re: SceneTransitionManager - Loading Method

Posted: Wed Dec 15, 2021 10:33 pm
by VoodooDetective
Ah gotcha, that's what I had been doing, but thought it was odd to spawn a new coroutine to do the same work monitoring the status of the async operation. But it's not a big deal, just a thought.

Re: SceneTransitionManager - Loading Method

Posted: Thu Dec 16, 2021 8:31 am
by Tony Li
Fair enough -- I have just enough time to add that to version 2.2.23 before it ships.

Re: SceneTransitionManager - Loading Method

Posted: Sat Dec 18, 2021 1:11 pm
by VoodooDetective
Wow, awesome! Thank you!