public static bool SaveXML() { Debug.Log("exporting..."); if (mainEditor == null || mainEditor.nodes == null || mainEditor.nodes.Count < 1) { Debug.Log("EXPORT ERROR: Story Editor reference unhooked or empty story!"); return(false); } // open the file explorer save window if on a new file string path = EditorUtility.SaveFilePanel("Export Story Entry", ProjectPathManager.LastExportPath, "entry", "xml"); if (string.IsNullOrEmpty(path)) { Debug.Log("canceled save"); return(false); } // --- start building the entry --- try { Dictionary <Node, int> nodeMap = new Dictionary <Node, int>(); // give all the nodes a NID before connecting them int entryNID = NodePrepass(nodeMap, mainEditor.nodes); // build the story entry StoryNodeEntry storyEntry = GenerateStoryEntry(nodeMap, mainEditor.nodes, entryNID); // write to disk XmlSerializer serializer = new XmlSerializer(typeof(StoryNodeEntry)); using (StreamWriter stream = new StreamWriter(path, false, Encoding.ASCII)) { serializer.Serialize(stream, storyEntry); } } catch (UnityException e) { while (!EditorUtility.DisplayDialog("EXPORT FAILED", e.Message, "I will fix it like a good boi")) { ; } return(false); } // success! Debug.Log("exported to: " + path); ProjectPathManager.LastExportPath = path; return(true); }
private static StoryNodeEntry GenerateStoryEntry(Dictionary <Node, int> nodeMap, List <Node> nodes, int entryNID) { StoryNodeEntry storyEntry = new StoryNodeEntry(); storyEntry.nodeEntries = GenerateNodeEntries(nodeMap, nodes); storyEntry.entryNID = entryNID; List <string> flags = new List <string>(); for (int i = 0; i < mainEditor.localFlagsMenu.items.Count; i++) { flags.Add(mainEditor.localFlagsMenu.items[i].text); } storyEntry.localFlags = flags; return(storyEntry); }