Seneral / Node_Editor_Framework

A flexible and modular Node Editor Framework for creating node based displays and editors in Unity
https://nodeeditor.seneral.dev
MIT License
2k stars 415 forks source link

Save As can generate invalid paths #157

Closed metzsg closed 5 years ago

metzsg commented 6 years ago

When the user chooses "Save As" on a canvas that already has a savePath, the full savePath is given to UnityEditor's SaveFilePanellnProject as its starting path. If the user specifies a different name without changing directories, that name is added to the end of the full savePath (including original asset name), generating an exception when unity attempts to write to the path. It seems like SaveFileInPath expects only a directory as the path parameter.

I've solved by parsing the savePath a bit before input into SaveFilePanelInProject:

private void SaveCanvasAs()
{
    string panelPath = NodeEditor.editorPath + "Resources/Saves/";
    string panelFileName = "Node Canvas";
    if (canvasCache.nodeCanvas != null && !string.IsNullOrEmpty(canvasCache.nodeCanvas.savePath))
    {
        panelPath = canvasCache.nodeCanvas.savePath;
        string savedFileName = System.IO.Path.GetFileNameWithoutExtension(panelPath);
        if (!string.IsNullOrEmpty(savedFileName))
        {
            panelPath = panelPath.Substring(0, panelPath.LastIndexOf(savedFileName));
            panelFileName = savedFileName;
        }
    }
    string path = UnityEditor.EditorUtility.SaveFilePanelInProject("Save Node Canvas", panelFileName, "asset", "", panelPath);
    if (!string.IsNullOrEmpty(path))
        canvasCache.SaveNodeCanvas(path);
}
Seneral commented 6 years ago

Thanks, will include it. Somehow forgot about it:)

Seneral commented 5 years ago

Sorry for the immense delay. Just merged it