/// <summary> /// WARNING: This assumes the path has already been validated to exist. /// </summary> /// <param name="pathToScript"></param> private void OpenScript(string pathToScript) { StreamReader reader = new StreamReader(pathToScript); string fileString = reader.ReadToEnd(); reader.Close(); if (string.IsNullOrEmpty(fileString)) { EditorPrefs.SetString(lastOpenScriptKey, ""); Debug.Log("File is empty or invalid: " + pathToScript); return; } try { ScenimaticScript script = JsonUtility.FromJson <ScenimaticScript>(fileString); scenimaticGraph = new ScenimaticScriptGraph(); if (window == null) { CreateWindows(); } window.position = new Rect(script.savedScreenPos, script.savedScreenSize); scenimaticGraph.Initialize(script); } catch (System.Exception e) { EditorPrefs.SetString(lastOpenScriptKey, ""); Debug.LogError("Error parsing JSON in " + pathToScript + ":\n" + e.Message); return; } if (zoomer == null) { zoomer = new ZoomWindow(); } zoomer.Reset(scenimaticGraph.zoomerSettings); EditorPrefs.SetString(lastOpenScriptKey, pathToScript); sceneFileName = Path.GetFileNameWithoutExtension(pathToScript); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.SetDirty(this); }
private void NewScene() { sceneFileName = null; var di = Directory.CreateDirectory( Directory.GetCurrentDirectory() + "/" + userScenimaticFolder); ScenimaticScript script = new ScenimaticScript("New Scene", CreateNewBranch(new Vector2(400, 0))); scenimaticGraph = new ScenimaticScriptGraph(); scenimaticGraph.Initialize(script); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.SetDirty(this); }