void SaveData() { string path = EditorUtility.SaveFilePanelInProject("儲存劇情檔案", "new story", "asset", ""); if (path == "") { return; } scriptable_story story = ScriptableObject.CreateInstance <scriptable_story> (); CharInfoCast(true, ref story.lst_charInfo); NodeInfoCast(true, ref story); AssetDatabase.CreateAsset(story, path); EditorUtility.SetDirty(story); }
void OpenFile() { string path = EditorUtility.OpenFilePanel("開啟劇情檔案", "", "asset"); if (path == "") { return; } path = path.Replace(Application.dataPath, "Assets"); scriptable_story story = AssetDatabase.LoadAssetAtPath <scriptable_story> (path); CharInfoCast(false, ref story.lst_charInfo); NodeInfoCast(false, ref story); rightPanel.SetNameArray(); rightPanel.SetQNodeList(); }
void ReadStoryAsset() { if (story == null) { story = Resources.Load <scriptable_story> ("DemoStory"); } foreach (StartNodeInfo info in story.lst_startNodeInfo) { Plot.Add(info.name, info.nextKey); } foreach (DialogueNodeInfo info in story.lst_dialogueNodeInfo) { dc_dialogues.Add(info.name, info.myDialSet); } foreach (QuestionNodeInfo info in story.lst_questionNodeInfo) { dc_questions.Add(info.name, info.myQuestion); } foreach (DivergeNodeInfo info in story.lst_divergeNodeInfo) { dc_diverges.Add(info.name, info.myDiverges); } }
void NodeInfoCast(bool node2Info, ref scriptable_story story) { if (node2Info) { //Cast Node to NodeInfo, used for saving. story.lst_startNodeInfo = new List <StartNodeInfo> (); story.lst_dialogueNodeInfo = new List <DialogueNodeInfo> (); story.lst_questionNodeInfo = new List <QuestionNodeInfo> (); story.lst_divergeNodeInfo = new List <DivergeNodeInfo> (); foreach (Node n in lst_node) { switch (n.GetType().ToString()) { case "StartNode": story.lst_startNodeInfo.Add(new StartNodeInfo(n)); break; case "DialogueNode": story.lst_dialogueNodeInfo.Add(new DialogueNodeInfo(n)); break; case "QuestionNode": story.lst_questionNodeInfo.Add(new QuestionNodeInfo(n)); break; case "DivergeNode": story.lst_divergeNodeInfo.Add(new DivergeNodeInfo(n)); break; default: break; } } } else { //Cast NodeInfo to Node, used for opening. //Create Nodes from nodeInfo. lst_node = new List <Node> (); foreach (StartNodeInfo info in story.lst_startNodeInfo) { lst_node.Add(info.Cast2Node(this)); } plotNodeCount = lst_node.Count; foreach (DialogueNodeInfo info in story.lst_dialogueNodeInfo) { lst_node.Add(info.Cast2Node(this)); } foreach (QuestionNodeInfo info in story.lst_questionNodeInfo) { lst_node.Add(info.Cast2Node(this)); } foreach (DivergeNodeInfo info in story.lst_divergeNodeInfo) { lst_node.Add(info.Cast2Node(this)); } //After all nodes are created, reconnect all links. foreach (StartNodeInfo info in story.lst_startNodeInfo) { info.Reconnect(this); } foreach (DialogueNodeInfo info in story.lst_dialogueNodeInfo) { info.Reconnect(this); } foreach (QuestionNodeInfo info in story.lst_questionNodeInfo) { info.Reconnect(this); } foreach (DivergeNodeInfo info in story.lst_divergeNodeInfo) { info.Reconnect(this); } } }