예제 #1
0
    private IEnumerator LoadLevel(int levelIndex)
    {
        UIManager uiManager = ServiceLocator.Instance.GetServiceOfType <UIManager>(SERVICE_TYPE.UIMANAGER);

        GameHUD hud = uiManager.GetUIScreenForId <GameHUD>(ScreenIds.sGameScreen);

        if (hud != null)
        {
            //start level load transition HERE!
            hud.StartGameLoad();
            while (!hud.IsGameLoadPresentationDone())
            {
                yield return(0);
            }
            //load level scene
            string sceneToLoad = string.Format("{0} {1}", allLevelsData[levelIndex].worldName, allLevelsData[levelIndex].levelName);
            Debug.LogFormat("Scene to load:{0}", sceneToLoad);
            AsyncOperation operation = SceneManager.LoadSceneAsync(sceneToLoad);

            while (!operation.isDone)
            {
                yield return(0);
            }

            //TODO: Init world HERE!

            //start level load transition END HERE!
            hud.FinishGameLoad();
            while (!hud.IsGameLoadFinishDone())
            {
                yield return(0);
            }
            //show GameHUD
            ServiceLocator.Instance.GetServiceOfType <UIManager>(SERVICE_TYPE.UIMANAGER).SwitchToScreenWithId(ScreenIds.sGameScreen);



            currentLevel = levelIndex;
        }
    }