//TODO: Return bool instead of string. Pass the binary temp scene path with the callback. public string LoadNewScene(string path, TempSceneSaved callback) { if (EditorApplication.isPlayingOrWillChangePlaymode) { EditorUtility.DisplayDialog("Game is running", "You cannot load in Play-mode", "OK"); return(""); } if (path == null || path.Length == 0) { return(""); } string startPath = Application.dataPath; Debug.Log("Opening scene file: " + path + " current: " + EditorApplication.currentScene); //Make sure the file exists if (!File.Exists(path)) { Debug.LogError("File does not exist: " + path); return(""); } EditorApplication.NewScene(); Transform[] sceneObjects = Helper.GetObjectsOfType <Transform>(); foreach (Transform o in sceneObjects) { if (o != null && o.parent == null) { Debug.Log("Destroying object: " + o.name); GameObject.DestroyImmediate(o.gameObject); } } recursionGuard = path; LoadScene(path); string tmpScenePath = startPath.Substring(0, startPath.LastIndexOf('/')); string assetPath = path.Replace(startPath, ""); string[] subFolders = assetPath.Split('/'); Debug.Log("tmpScenePath: " + tmpScenePath + " assetPath: " + assetPath); //First, make sure we have a temp scenes folder tmpScenePath += "/TempScenes"; if (!Directory.Exists(tmpScenePath)) { Directory.CreateDirectory(tmpScenePath); } //Laat entry is the filename itself. for (int i = 0; i < subFolders.Length - 1; i++) { tmpScenePath += subFolders[i] + "/"; if (!Directory.Exists(tmpScenePath)) { Directory.CreateDirectory(tmpScenePath); } } string fileName = subFolders[subFolders.Length - 1]; fileName = fileName.Replace(".txt", ".unity"); string scenePath = tmpScenePath + fileName; Debug.Log("Saving binary unity scene at path: " + scenePath + " (" + path + ")"); //EditorApplication.SaveScene(scenePath); //EditorApplication.OpenScene(scenePath); //TextSceneMonitor.Instance.SetCurrentScene(path); //FIXME: Bugz0rs: Need to delay the save & reload or else prefabs will behave weirdly, // such as getting name reset if doing changes on the prefab and position reset // to prefab pos if hitting revert. TextSceneMonitor.Instance.DoSaveAndReload(scenePath, callback); return(scenePath); }
public static string Load(string path, TempSceneSaved callback) { return (new TextSceneDeserializer()).LoadNewScene(path, callback); }
public static string Load(string path, TempSceneSaved callback) { return((new TextSceneDeserializer()).LoadNewScene(path, callback)); }
//TODO: Return bool instead of string. Pass the binary temp scene path with the callback. public string LoadNewScene(string path, TempSceneSaved callback) { if (EditorApplication.isPlayingOrWillChangePlaymode) { EditorUtility.DisplayDialog("Game is running", "You cannot load in Play-mode", "OK"); return ""; } if (path == null || path.Length == 0) return ""; string startPath = Application.dataPath; Debug.Log("Opening scene file: " + path + " current: " + EditorApplication.currentScene); //Make sure the file exists if (!File.Exists(path)) { Debug.LogError("File does not exist: " + path); return ""; } EditorApplication.NewScene(); Transform[] sceneObjects = Helper.GetObjectsOfType<Transform>(); foreach (Transform o in sceneObjects) { if (o != null && o.parent == null) { Debug.Log("Destroying object: " + o.name); GameObject.DestroyImmediate(o.gameObject); } } recursionGuard = path; LoadScene(path); string tmpScenePath = startPath.Substring(0, startPath.LastIndexOf('/')); string assetPath = path.Replace(startPath, ""); string[] subFolders = assetPath.Split('/'); Debug.Log("tmpScenePath: " + tmpScenePath + " assetPath: " + assetPath); //First, make sure we have a temp scenes folder tmpScenePath += "/TempScenes"; if (!Directory.Exists(tmpScenePath)) Directory.CreateDirectory(tmpScenePath); //Laat entry is the filename itself. for (int i = 0; i < subFolders.Length-1; i++) { tmpScenePath += subFolders[i] + "/"; if (!Directory.Exists(tmpScenePath)) Directory.CreateDirectory(tmpScenePath); } string fileName = subFolders[subFolders.Length-1]; fileName = fileName.Replace(".txt", ".unity"); string scenePath = tmpScenePath + fileName; Debug.Log("Saving binary unity scene at path: " + scenePath + " (" + path + ")"); //EditorApplication.SaveScene(scenePath); //EditorApplication.OpenScene(scenePath); //TextSceneMonitor.Instance.SetCurrentScene(path); //FIXME: Bugz0rs: Need to delay the save & reload or else prefabs will behave weirdly, // such as getting name reset if doing changes on the prefab and position reset // to prefab pos if hitting revert. TextSceneMonitor.Instance.DoSaveAndReload(scenePath, callback); return scenePath; }