public ActionContainer Save() { GraphSaveUtility saveUtility = GraphSaveUtility.GetInstance(graphView); ActionContainer saved = null; if (graphView.IsCachedFile) { return(saveUtility.SaveGraph(DefaultCacheName)); } if (graphView.IsDirty) { if (string.IsNullOrEmpty(graphView.LoadedFileName) || string.IsNullOrWhiteSpace(graphView.LoadedFileName)) { return(SaveAs()); } saved = saveUtility.SaveGraph(graphView.LoadedFileName); if (saved) { graphView.LoadedFileName = saved.ContainerName; graphView.SetDirty(false); graphView.IsCachedFile = false; } } return(saved); }
private void RequestDataOperation(bool save) { if (string.IsNullOrEmpty(_fileName)) { EditorUtility.DisplayDialog("Invalid file name!", "Please enter a vaild file name.", "OK"); } var saveUtility = GraphSaveUtility.GetInstance(_graphView); if (save) { saveUtility.SaveGraph(_fileName); } else { saveUtility.LoadGraph(_fileName); } }
private bool Load(string fileName) { if (string.IsNullOrEmpty(fileName)) { EditorUtility.DisplayDialog("Invalid file name", "Please enter a valid file name.", "OK"); return(false); } var saveUtility = GraphSaveUtility.GetInstance(graphView); // if loads cache file, shouldn't set the graphview to not dirty. if (saveUtility.LoadGraph(fileName) && !graphView.IsCachedFile) { graphView.SetDirty(false); } return(true); }
public void OnPasteElementsOption(string a, string b) { if (nodeCopyCache.Count == 0) { return; } var graphContainer = GraphSaveUtility.GetInstance(targetGraphView).GetNodesContainer(); foreach (var node in nodeCopyCache) { var baseNode = (BaseNode)node; var nodeData = baseNode.CopyData(false); // Offset pasted node nodeData.position.y += baseNode.GetPosition().height + nodePasteOffset; switch (nodeData.nodeType) { case NodeType.DialogueNode: var dialogueNodeOriginal = node as DialogueNode; DialogueNodeData dialogueData = dialogueNodeOriginal.CopyData(); var dialogueNode = new DialogueNode(targetGraphView, nodeData, dialogueData); targetGraphView.AddElement(dialogueNode); break; case NodeType.ChoiceNode: var choiceNodeOriginal = node as ChoiceNode; ChoiceNodeData choiceData = choiceNodeOriginal.CopyData(); var choicePorts = graphContainer.nodeLinks.ToList().Where(x => x.thisNodeGuid == nodeData.guid).ToList(); var choiceNode = new ChoiceNode(targetGraphView, nodeData, choiceData, choicePorts); targetGraphView.AddElement(choiceNode); break; case NodeType.EndNode: var endNode = new BaseNode(nodeData.nodeType, targetGraphView, nodeData.position, nodeData.guid); targetGraphView.AddElement(endNode); break; } } }
public ActionContainer SaveAs() { GraphSaveUtility saveUtility = GraphSaveUtility.GetInstance(graphView); ActionContainer saved; string path = EditorUtility.SaveFilePanelInProject("Save As", "Module", "asset", "Please save file."); if (string.IsNullOrEmpty(path) || string.IsNullOrWhiteSpace(path)) { return(null); } saved = saveUtility.SaveGraph(path, true); if (saved) { //Was able to save graphView.LoadedFileName = saved.ContainerName; graphView.SetDirty(false); graphView.IsCachedFile = false; } return(saved); }
private void GenerateToolbar() { var toolbar = new Toolbar(); ObjectField objectField = new ObjectField(); Toggle gridCheckbox = new Toggle(); ToolbarMenu fileMenu = new ToolbarMenu { text = "File", style = { width = 50 } }; #region File Menu //Should iterate through ActionModuleGroup fileMenu.menu.AppendAction("New Module", action => { if (string.IsNullOrEmpty(graphView.LoadedFileName)) { objectField.value = null; graphView.CreateEmptyNewGraph(); } }); fileMenu.menu.AppendSeparator(); fileMenu.menu.AppendAction("Save", action => { ActionContainer actionContainer; if (string.IsNullOrEmpty(graphView.LoadedFileName)) { actionContainer = Save(); if (actionContainer) { objectField.SetValueWithoutNotify(actionContainer); } return; } actionContainer = Save(); if (actionContainer) { objectField.SetValueWithoutNotify(actionContainer); } }); fileMenu.menu.AppendAction("Save As", action => { var actionContainer = SaveAs(); if (actionContainer) { objectField.SetValueWithoutNotify(actionContainer); } }); bool isGridActive = false; fileMenu.menu.AppendSeparator(); fileMenu.menu.AppendAction("Activate Grid", action => { isGridActive = !isGridActive; graphView.ToggleGrid(!isGridActive); }, action => { if (isGridActive) { return(DropdownMenuAction.Status.Normal); } return(DropdownMenuAction.Status.Checked); }); #endregion #region Object Loader objectField.objectType = typeof(ActionContainer); objectField.RegisterCallback <ChangeEvent <Object> >(evt => { if (evt.newValue == null) { objectField.SetValueWithoutNotify(evt.previousValue); return; } var saveUtility = GraphSaveUtility.GetInstance(graphView); //if dirty if (!graphView.IsDirty) { //clears and loadGraph saveUtility.LoadGraph((ActionContainer)evt.newValue); string loadedName = ((ActionContainer)evt.newValue).ContainerName; graphView.LoadedFileName = loadedName; graphView.SetName(loadedName); return; } //Graph is dirty int option = EditorUtility.DisplayDialogComplex("Unsaved Changes", "Do you want to save the changes you made before?", "Save", "Cancel", "Don't Save"); switch (option) { case 1: //Cancel objectField.SetValueWithoutNotify(evt.previousValue); break; case 0: // Save graphView.SetDirty(!(saveUtility.SaveGraph(graphView.LoadedFileName) != null && saveUtility.LoadGraph((ActionContainer)evt.newValue))); break; case 2: // Don't Save. graphView.SetDirty(!saveUtility.LoadGraph((ActionContainer)evt.newValue)); break; } }); #endregion toolbar.Add(fileMenu); toolbar.Add(objectField); //Adds toolbar to window rootVisualElement.Add(toolbar); }