/// <summary> /// Resolves this SceneRef to a Scene, caching and reruning the result /// </summary> /// <returns></returns> public Scene resolve() { if (mIsInvalid) return null; if(mPath.Length == 0) { mIsInvalid = true; return null; } if (mResolvedScene == null) { mResolvedScene = SceneManager.Instance.getSceneByPath(mPath); if (mResolvedScene == null) mIsInvalid = true; } return mResolvedScene; }
/// <summary> /// Creates a new SceneManager and serializes it directly. /// </summary> /// <param name="scenes">A List of Scenes. The Scenes path has to be relative to the Assets/ directory</param> /// <param name="final">If true, the serilization will try to minimize the serialized file</param> static public void saveToStreamingAssets(Scene[] scenes, bool final) { SceneManager manager = new SceneManager(); foreach (Scene scene in scenes) { manager.mScenes.Add(scene.Path, scene); } Directory.CreateDirectory(Path.GetDirectoryName(getFilePath())); string json = JsonConvert.SerializeObject(manager, ((final)?Formatting.None : Formatting.Indented)); File.WriteAllText(getFilePath(), json); }
private void emitAfterSceneChangeEvent(Scene oldScene, Scene newScene) { if (afterSceneChange != null) { afterSceneChange(oldScene, newScene); } if (mCurrentScene != null) mCurrentScene.emitAfterSceneChangeToEvent(oldScene, newScene); }
private void emitBeforeSceneChangeEvent(Scene oldScene, Scene newScene) { if (mCurrentScene != null) mCurrentScene.emitBeforeSceneLeaveEvent(oldScene, newScene); if (newScene != null) newScene.emitBeforeSceneChangeToEvent(oldScene, newScene); if (beforeSceneChange != null) { beforeSceneChange(oldScene, newScene); } }
public Scene changeScene(Scene target) { if (target == null) { Debug.LogError("Could not changeScene, as no Scene was found (sene was null)"); return null; } Scene oldScene = mCurrentScene; emitBeforeSceneChangeEvent(oldScene, target); mCurrentScene = target; Application.LoadLevel(target.Index); emitAfterSceneChangeEvent(oldScene, target); return mCurrentScene; }
public static SceneRef fromScene(Scene scene) { if (scene == null) return null; SceneRef sceneref = new SceneRef(); sceneref.mPath = scene.Path; sceneref.mResolvedScene = scene; return sceneref; }
public void emitBeforeSceneChangeToEvent(Scene oldScene, Scene newScene) { if (beforeSceneChangeTo != null) { beforeSceneChangeTo(oldScene, newScene); } }
public void emitBeforeSceneLeaveEvent(Scene oldScene, Scene newScene) { if (beforeLeave != null) { beforeLeave(oldScene, newScene); } }
static public Scene[] fetchAllFromBuildSettings() { List<Scene> scenes = new List<Scene>(); int i = 0; //Walk through the build settings again to get the index of this foreach (var buildSetting in UnityEditor.EditorBuildSettings.scenes) { if (buildSetting.enabled) { Scene scene = new Scene(); scene.mIdx = i; scene.mPath = PathExtensions.getRelativePathTo(System.IO.Path.GetFullPath(buildSetting.path), Application.dataPath+"/"); scene.mGUID = UnityEditor.AssetDatabase.AssetPathToGUID(buildSetting.path); i++; scenes.Add(scene); } } return scenes.ToArray(); }
public void emitAfterSceneChangeToEvent(Scene oldScene, Scene newScene) { if (afterSceneChangeTo != null) { afterSceneChangeTo(oldScene, newScene); } }