/// <summary> /// Generate collections with related scenes' names for loading and load them /// </summary> /// <param name="sceneData"></param> /// <param name="sceneLoadDistance"></param> /// <returns></returns> private HashSet <string> GetScenesShouldBeLoaded(IG_SceneData sceneData, int sceneLoadDistance) { _scenesShouldBeLoaded.Clear(); GetScenesShouldBeLoadedInternal(sceneData, sceneLoadDistance); _scenesShouldBeLoaded.Add(PersistentSceneName); return(_scenesShouldBeLoaded); }
private void GetScenesShouldBeLoadedInternal(IG_SceneData sceneData, int sceneLoadDistance) { if (sceneLoadDistance > _graphSceneData.DefaultMaxDistance) { return; } sceneLoadDistance++; // Add scenes from current sceneData HashSet <string> scenesConnected = new HashSet <string>(sceneData.ScenesConnected); _scenesShouldBeLoaded.UnionWith(scenesConnected); _scenesShouldBeLoaded.UnionWith(new HashSet <string>(sceneData.ScenesTransition)); foreach (var sceneName in scenesConnected) { IG_SceneData cSceneData = _graphSceneData.ScenesDataAll.Find(x => x.name == sceneName); GetScenesShouldBeLoadedInternal(cSceneData, sceneLoadDistance); } }
private void ChangeCurrentScene(string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Additive) { if (string.IsNullOrEmpty(sceneName) || sceneName == _currentSceneName) { return; } _currentSceneName = sceneName; // Saving the name of current scene _scenesLoaded = GetLoadedScenes(); // Searching if we have scenes loaded for some reason _graphSceneData.ScenesDataLoaded = new HashSet <IG_SceneData>(_graphSceneData.ScenesDataAll); //_graphSceneData.ScenesDataLoaded.IntersectWith(_scenesLoaded); Action action = () => ActivateScene(_currentSceneName); // If isn't loaded, load. Then make current scene active if (!_scenesLoaded.Contains(_currentSceneName)) { StartCoroutine(LoadSceneAsync(_currentSceneName, loadSceneMode, action)); } // --- After loading main scene, load optional additional scenes up to SceneLoadDistance, keeping track of them in the near list: if (Debugging) { Debug.Log("Loading scenes connected with: " + _currentSceneName); } IG_SceneData sceneData = _graphSceneData.ScenesDataAll.Find(x => x.SceneName == _currentSceneName); // Get Scene Data for current scene // LoadScenes(GetScenesShouldBeLoaded(sceneData, 1)); // UnloadScene any scenes not in the near list UnloadScenesExcessive(); }