예제 #1
0
    IEnumerator LoadSceneAsync(string name)
    {
        if (!Action.ReferenceEquals(LoadSceneEnterCallBack, null))
        {
            LoadSceneEnterCallBack();
        }
        ClearCache();
        AlreadyLoadScene = false;
        AsyncOperation unloadScene = SceneManager.LoadSceneAsync("Empty", LoadSceneMode.Single);

        while (!AsyncOperation.ReferenceEquals(unloadScene, null) && !unloadScene.isDone)
        {
            yield return(new WaitForEndOfFrame());
        }
        LoadingProgress = 0;
        int            targetProgress = 0;
        AsyncOperation asyncScene     = SceneManager.LoadSceneAsync(name);

        if (!AsyncOperation.ReferenceEquals(asyncScene, null) && !asyncScene.isDone)
        {
            asyncScene.allowSceneActivation = false;
            while (asyncScene.progress < 0.9f)
            {
                targetProgress = (int)asyncScene.progress * 100;
                yield return(new WaitForEndOfFrame());

                //smooth
                while (LoadingProgress < targetProgress)
                {
                    ++LoadingProgress;
                    yield return(new WaitForEndOfFrame());
                }
            }
            CurrentMapName = name;
            SetSceneSetting(name);
            while (LoadingProgress < targetProgress - 2)
            {
                ++LoadingProgress;
                yield return(new WaitForEndOfFrame());
            }
            LoadingProgress = 100;
            asyncScene.allowSceneActivation = true;
            AlreadyLoadScene = true;
            if (!Action.ReferenceEquals(LoadSceneOverCallBack, null))
            {
                LoadSceneOverCallBack();
            }
        }
    }