Ejemplo n.º 1
0
        private string GetLastLoadedScene(string defaultImage = null)
        {
            if (!LastLoadedScenes.TryGetValue(_currentSceneFolder, out var nextImage))
            {
                nextImage = defaultImage.IsNullOrEmpty() ? ScenePaths.FirstOrDefault() : defaultImage;
            }

            return(string.IsNullOrEmpty(nextImage)
                ? nextImage
                : PathUtils.NormalizePath(Path.Combine(_currentSceneFolder, nextImage)));
        }
 // Loading scenes by path is more secure
 // since two scenes might have the same name
 // but the path is allways unique
 public void LoadScene(string path)
 {
     if (string.IsNullOrEmpty(path))
     {
         Debug.LogError("Given path is null or empty!", this);
         return;
     }
     if (!ScenePaths.Contains(path))
     {
         Debug.LogError("Given path " + path + " is invalid!", this);
         return;
     }
     // Load the Scene here e.g. using
     SceneManager.LoadSceneAsync(path);
 }
            internal static void StudioInitInfoPost(SceneLoadScene __instance)
            {
                try
                {
                    _sceneLoadScene       = __instance;
                    _currentSceneFolder   = string.Empty;
                    ScenePaths            = SceneUtils.GetSceneLoaderPaths(__instance);
                    _normalizedScenePaths = null;
                    ScenePaths.SafeProc(0,
                                        p => _currentSceneFolder = PathUtils.NormalizePath(Path.GetDirectoryName(p)));
                    Instance.SafeProc(i => i.ScrollToLastLoadedScene(__instance));
                }

                catch (Exception err)
                {
                    Logger.LogException(err, __instance, nameof(StudioInitInfoPost));
                }
            }
Ejemplo n.º 4
0
        /// <summary>Loads the last loaded scene from the currently active folder</summary>
        /// <returns>`true` if scene was loaded, otherwise `false`</returns>
        private bool LoadLastLoadedScene()
        {
            var navigated       = false;
            var clearNavigation = !_navigationInProgress;

            _navigationInProgress = true;
            try
            {
                if (!LastLoadedScenes.TryGetValue(_currentSceneFolder, out var nextImage))
                {
                    nextImage = ScenePaths.LastOrDefault();
                }

                if (nextImage != default)
                {
                    nextImage = PathUtils.NormalizePath(Path.Combine(_currentSceneFolder, nextImage));

                    if (File.Exists(nextImage))
                    {
                        _currentScenePathCandidate = nextImage;
                        StartCoroutine(Singleton <Studio.Studio> .Instance.LoadSceneCoroutine(nextImage));
                        navigated = true;
                    }
                }
            }
            finally
            {
                if (!navigated)
                {
                    Logger.Log(BepInLogLevel.Message | BepInLogLevel.Error,
                               $"Error loading last scene from {_currentSceneFolder}");
                    if (clearNavigation)
                    {
                        _navigationInProgress = false;
                    }
                }
            }

            return(navigated);
        }