SceneTransitionManager - Loading Method

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

SceneTransitionManager - Loading Method

Post 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.
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

Re: SceneTransitionManager - Loading Method

Post 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;
    }
}
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Re: SceneTransitionManager - Loading Method

Post 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.
User avatar
Tony Li
Posts: 22154
Joined: Thu Jul 18, 2013 1:27 pm

Re: SceneTransitionManager - Loading Method

Post by Tony Li »

Fair enough -- I have just enough time to add that to version 2.2.23 before it ships.
VoodooDetective
Posts: 222
Joined: Wed Jan 22, 2020 10:48 pm

Re: SceneTransitionManager - Loading Method

Post by VoodooDetective »

Wow, awesome! Thank you!
Post Reply