private void LoadBundle()
        {
            AssetBundle returnedBundle;
            AssetBundleCreateRequest assetBundleCreateRequest = SwitchAssetBundle.LoadBundle(mCurrentBundle.mSceneBundle, out returnedBundle, out mCurrentBundleName, async: true);

            if (assetBundleCreateRequest == null)
            {
                mCurrentPhase = LoadingScenePhase.kSceneLoad;
                return;
            }
            mBundleLoader = assetBundleCreateRequest;
            mCurrentPhase = LoadingScenePhase.kBundleLoadWait;
        }
        private void LoadNextRequired()
        {
            if (mCurrentBundle.mRequires == null || mCurrentRequired == mCurrentBundle.mRequires.Length)
            {
                mCurrentPhase = LoadingScenePhase.kBundleLoad;
                return;
            }
            AssetBundle returnedBundle;
            AssetBundleCreateRequest assetBundleCreateRequest = SwitchAssetBundle.LoadBundle(mCurrentBundle.mRequires[mCurrentRequired], out returnedBundle, out mCurrentRequiredName, async: true);

            mCurrentRequired++;
            if (assetBundleCreateRequest == null)
            {
                LoadNextRequired();
                return;
            }
            mBundleLoader = assetBundleCreateRequest;
            mCurrentPhase = LoadingScenePhase.kRequiredFileLoadWait;
        }
示例#3
0
    private IEnumerator LoadLevel(string levelId, ulong levelNumber, int checkpointNumber, int checkpointSubObjectives, Action onComplete, WorkshopItemSource levelType)
    {
        bool localLevel = false;

        NetScope.ClearAllButPlayers();
        BeforeLoad();
        skyColor       = RenderSettings.ambientLight;
        skyboxMaterial = RenderSettings.skybox;
        state          = GameState.LoadingLevel;
        bool isBundle = !string.IsNullOrEmpty(levelId) || (levelNumber > 16 && levelNumber != ulong.MaxValue);

        if (isBundle)
        {
            if (string.IsNullOrEmpty(levelId))
            {
                bool loaded2 = false;
                WorkshopRepository.instance.levelRepo.GetLevel(levelNumber, levelType, delegate(WorkshopLevelMetadata l)
                {
                    workshopLevel = l;
                    loaded2       = true;
                });
                while (!loaded2)
                {
                    yield return(null);
                }
            }
            else
            {
                localLevel    = levelId.StartsWith("lvl:");
                workshopLevel = WorkshopRepository.instance.levelRepo.GetItem(levelId);
            }
            RatingMenu.instance.LoadInit();
            if (!localLevel && workshopLevel != null)
            {
                App.StartPlaytimeForItem(workshopLevel.workshopId);
                RatingMenu.instance.QueryRatingStatus(workshopLevel.workshopId);
            }
        }
        App.StartPlaytimeLocalPlayers();
        if (currentLevelNumber != (int)levelNumber)
        {
            Level oldLevel = currentLevel;
            SubtitleManager.instance.SetProgress(ScriptLocalization.TUTORIAL.LOADING);
            Application.backgroundLoadingPriority = ThreadPriority.Low;
            string sceneName = string.Empty;
            currentLevelType = levelType;
            switch (levelType)
            {
            case WorkshopItemSource.BuiltIn:
                sceneName = levels[levelNumber];
                break;

            case WorkshopItemSource.EditorPick:
                Debug.Log("Loading editor pick level");
                sceneName = editorPickLevels[(uint)levelNumber];
                break;
            }
            Debug.Log("scename = " + sceneName);
            if (!isBundle)
            {
                if (string.IsNullOrEmpty(sceneName))
                {
                    sceneName = levels[levelNumber];
                }
            }
            else
            {
                if (!localLevel && workshopLevel != null)
                {
                    bool loaded = false;
                    WorkshopRepository.instance.levelRepo.LoadLevel(workshopLevel.workshopId, delegate(WorkshopLevelMetadata l)
                    {
                        workshopLevel = l;
                        loaded        = true;
                    });
                    while (!loaded)
                    {
                        yield return(null);
                    }
                }
                bundle = null;
                if (workshopLevel != null)
                {
                    bundle = FileTools.LoadBundle(workshopLevel.dataPath);
                }
                if (bundle == null)
                {
                    SubtitleManager.instance.ClearProgress();
                    Debug.Log("Level load failed.");
                    App.instance.ServerFailedToLoad();
                    SignalManager.EndReset();
                    yield break;
                }
                string[] scenePath = bundle.GetAllScenePaths();
                if (string.IsNullOrEmpty(sceneName))
                {
                    sceneName = Path.GetFileNameWithoutExtension(scenePath[0]);
                }
            }
            instance.HasSceneLoaded = false;
            SwitchAssetBundle.LoadingCurrentScene loader2 = SwitchAssetBundle.LoadSceneAsync(sceneName);
            if (loader2 == null)
            {
                AsyncOperation sceneLoader2 = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
                while (!sceneLoader2.isDone || !instance.HasSceneLoaded)
                {
                    yield return(null);
                }
                sceneLoader2 = null;
                SubtitleManager.instance.SetProgress(ScriptLocalization.TUTORIAL.LOADING, 1f, 1f);
                currentLevelNumber = (int)levelNumber;
            }
            else
            {
                while (!loader2.isDone || !instance.HasSceneLoaded)
                {
                    yield return(null);
                }
                loader2 = null;
                SubtitleManager.instance.SetProgress(ScriptLocalization.TUTORIAL.LOADING, 1f, 1f);
                currentLevelNumber = (int)levelNumber;
            }
        }
        if (currentLevel == null)
        {
            SignalManager.EndReset();
            onComplete?.Invoke();
            yield break;
        }
        if (isBundle)
        {
            FixupLoadedBundle(SceneManager.GetActiveScene());
            bundle.Unload(unloadAllLoadedObjects: false);
        }
        if (currentLevelNumber >= 0 && !isBundle)
        {
            HumanAnalytics.instance.LoadLevel(levels[currentLevelNumber], (int)levelNumber, checkpointNumber, 0f);
        }
        FixAssetBundleImport();
        AfterLoad(checkpointNumber, checkpointSubObjectives);
        if (NetGame.isLocal)
        {
            if (levelType == WorkshopItemSource.BuiltIn && currentLevelNumber < levelCount - 1)
            {
                GameSave.PassCheckpointCampaign((uint)currentLevelNumber, checkpointNumber, checkpointSubObjectives);
            }
            if (levelType == WorkshopItemSource.EditorPick)
            {
                GameSave.PassCheckpointEditorPick((uint)currentLevelNumber, checkpointNumber, checkpointSubObjectives);
            }
        }
        onComplete?.Invoke();
    }