/// <summary> /// Gets the file path to save the canavs at. /// </summary> /// <returns></returns> private FilePanelResult GetSaveFilePath() { string path = EditorUtility.SaveFilePanelInProject("Save Bonsai Canvas", "NewBonsaiBT", "asset", "Select a destination to save the canvas."); if (string.IsNullOrEmpty(path)) { return(FilePanelResult.Fail(FilePanelError.Cancel)); } return(FilePanelResult.Ok(path)); }
/// <summary> /// Get the path from open file dialog. /// </summary> /// <returns></returns> private FilePanelResult GetCanvasOpenFilePath() { string path = EditorUtility.OpenFilePanel("Open Bonsai Canvas", "Assets/", "asset"); if (string.IsNullOrEmpty(path)) { return(FilePanelResult.Fail(FilePanelError.Cancel)); } // If the path is outside the project's asset folder. if (!path.Contains(Application.dataPath)) { return(FilePanelResult.Fail(FilePanelError.InvalidPath)); } return(FilePanelResult.Ok(path)); }
/// <summary> /// Prompts user to load a tree from file. /// </summary> /// <returns>The behaviour tree from the asset file. Null if load failed.</returns> public BehaviourTree LoadBehaviourTree() { FilePanelResult path = GetCanvasOpenFilePath(); if (path.Success) { var tree = LoadBehaviourTree(path.Value); if (tree == null) { OnLoadFailure(); } else { OnLoadSuccess(); } return(tree); } else { OnInvalidPathError(path.Error); return(null); } }