예제 #1
0
    // Removes the old level and loads in new level
    public Scene LoadLevel(string name, LoadSceneAction OnFinishLoad)
    {
        GameObject g = GameObject.Find("Tile Map");

        if (g != null)
        {
            Destroy(g);
        }
        StartCoroutine(LoadLevelAsync(name, OnFinishLoad));
        return(pastLevel);
    }
예제 #2
0
    // Loads scene and starts game once finished
    private IEnumerator LoadLevelAsync(string name, LoadSceneAction OnFinishLoad)
    {
        if (pastLevel.isLoaded)
        {
            AsyncOperation asyncUnloadLevel = SceneManager.UnloadSceneAsync(pastLevel);
            while (!asyncUnloadLevel.isDone)
            {
                yield return(null);
            }
        }
        Application.backgroundLoadingPriority = ThreadPriority.High;
        AsyncOperation asyncLoadLevel = SceneManager.LoadSceneAsync(name, LoadSceneMode.Additive);

        while (!asyncLoadLevel.isDone)
        {
            yield return(null);
        }
        pastLevel = SceneManager.GetSceneByName(name);
        if (OnFinishLoad != null)
        {
            OnFinishLoad.Invoke(pastLevel);
        }
    }