Esempio n. 1
0
    private void DrawSaveAndLoadButtons()
    {
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Load", GUILayout.ExpandWidth(false)))
        {
            string path = EditorUtility.OpenFilePanel("Graph To open", Application.dataPath, "asset");

            if (path.Length != 0)
            {
                Load(path);
            }
        }


        if (graph.GraphName == null || graph.GraphName == "" || graph.GraphName == DummyName)
        {
            return;
        }
        if (GUILayout.Button("Compile To C#", GUILayout.ExpandWidth(false)))
        {
            ValidateGraph();
            if (!isValidGraph)
            {
                return;
            }

            //string folderPath = EditorUtility.SaveFolderPanel("Save Code To Folder", "", "");
            string path = EditorUtility.SaveFilePanelInProject("Compile Graph", graph.GraphName, "cs",
                                                               "Please enter a file name to save the compiled graph to");
            //Debug.Log($"Folder Path: {folderPath}");
            //Debug.Log(path);

            if (path.Length != 0)
            {
                using (var writer = new StreamWriter(path))
                {
                    graph.Write(writer);
                    Close();
                }
            }

            //Temp save current graph
            string tempPath = MakeRelativePath(Application.dataPath + "/TempGraphStorage.asset");
            Save(tempPath);

            Debug.Log("Window Will Be Reopened after compilation, just wait paitently");

            //close window
            Close();

            AssetDatabase.Refresh();
        }

        if (GUILayout.Button("New Compile To C#", GUILayout.ExpandWidth(false)))
        {
            ValidateGraph();
            if (!isValidGraph)
            {
                return;
            }

            string folderPath = EditorUtility.SaveFolderPanel("Save Code To Folder", "", "");
            //string path = EditorUtility.SaveFilePanelInProject("Compile Graph", graph.GraphName, "cs",
            //    "Please enter a file name to save the compiled graph to");
            //Debug.Log($"Folder Path: {folderPath}");
            //Debug.Log(path);

            if (folderPath.Length != 0)
            {
                graph.WriteToCSharp(folderPath);
                Close();
            }

            //Temp save current graph
            string tempPath = MakeRelativePath(Application.dataPath + "/TempGraphStorage.asset");
            Save(tempPath);

            Debug.Log("Window Will Be Reopened after compilation, just wait paitently");

            //close window
            Close();

            AssetDatabase.Refresh();
        }

        if (GUILayout.Button("Save", GUILayout.ExpandWidth(false)))
        {
            string path = EditorUtility.SaveFilePanelInProject("Save Graph", graph.GraphName, "asset",
                                                               "Please enter a file name to save the graph to");

            if (path.Length != 0)
            {
                Save(path);
            }
        }

        EditorGUILayout.EndHorizontal();
    }