protected override void LoadTree(string path) { if (path == "") { return; } string contents = File.ReadAllText(path); CurrentTree = JsonUtility.FromJson <DialogueTreeEntity>(contents); nodes = new List <DialogueNode>(); dialogueTreeNode = (new DialogueTreeNode()).Initialize(CurrentTree); CurrentTree.dialogues.ForEach(entity => { nodes.Add(new DialogueNode().Initialize(entity)); }); OriginalName = CurrentTree.name; treeInitialized = true; Repaint(); GUI.FocusControl(null); }
protected void Uninitialize() { CurrentTree = null; treeInitialized = false; dialogueTreeNode = null; nodes = new List <DialogueNode>(); originalNodes = new List <DialogueNode>(); }
public void SyncNaming() { var entries = GetAllEntries(); //int changes = 0; Dictionary <string, Action> changes = new Dictionary <string, Action>(); entries.ForEach(entry => { if (entry.IndexOf(".json") == -1) { return; } string contents = File.ReadAllText(entry); DialogueTreeEntity tree = JsonUtility.FromJson <DialogueTreeEntity>(contents); string name = entry.Replace("\\", "/").Replace(Application.dataPath + "/" + Settings.dialogues_path + "/", "").Replace(".json", ""); if (name != tree.name) { // save back changes.Add(tree.name + " => " + name, () => { string nm = tree.name; tree.name = name; File.WriteAllText(entry, JsonUtility.ToJson(tree)); Debug.Log("Dialogue tree [" + nm + "] has been renamed to [" + name + "]"); }); } }); if (changes.Count > 0) { string text = "There're total of " + changes.Count + " name changes can be synchronized. Do you want to synchronize these tree names?\n"; foreach (var item in changes) { text += "\n" + item.Key; } if (EditorUtility.DisplayDialog("", text, "Yes", "No")) { foreach (var item in changes) { item.Value(); } } } else { Debug.Log("No changes detected."); } }
public CurrentDialogue(DialogueTreeEntity tree, DialogueEntity dialogue, List <string> selectedTexts, Dictionary <string, string> variables) { this.currentTextIndex = 0; this.tree = tree; this.dialogue = dialogue; //this.originalText = this.text = selectedText; this.originalTexts = this.texts = new List <string>(selectedTexts); this.InitializeSelections(); this.variables = variables; this.ApplyVariables(variables); }
public DialogueRuntime(DialogueTreeEntity dialogueTree, Dictionary <string, string> variables, Random random, ListenerRegistry listenerRegistry ) { this.dialogueTree = dialogueTree; this.variables = variables; this.random = random; this.listenerRegistry = listenerRegistry; this.InitializeTree(); }
protected override void InitializeTree(string category) { if (treeInitialized) { return; } OriginalName = ""; CurrentTree = new DialogueTreeEntity(); if (category != "") { CurrentTree.name = category.TrimEnd('/') + "/"; } // start dialogue node var node = (new DialogueTreeNode()).Initialize(CurrentTree); //windows.Add(node); dialogueTreeNode = node; // initialize first dialogue. DialogueEntity dialogue = new DialogueEntity() { id = UnityEngine.Random.Range(0, 1000000).ToString(), window = new WindowEntity() { x = 250f, y = 10f, width = 150f, height = 100 } }; nodes.Add((new DialogueNode()).Initialize(dialogue)); CurrentTree.SetInitialDialogue(dialogue); treeInitialized = true; }
public OptionSelection(DialogueTreeEntity tree, OptionEntity option, string text) { this.tree = tree; this.option = option; this.Text = text; }
public DialogueTreeNode Initialize(DialogueTreeEntity entity) { this.entity = entity; this.Window = new Rect(10f, 10f, 200f, 50f); return(this); }
public RuntimeBuilder(DialogueTreeEntity dialogueTree, Random random, ListenerRegistry listenerRegistry) : base(random) { this.dialogueTree = dialogueTree; this.variables = new Dictionary <string, string>(dialogueTree.variables.data); this.listenerRegistry = listenerRegistry; }
public RuntimeBuilder(DialogueTreeEntity dialogueTree, Random random) : base(random) { this.dialogueTree = dialogueTree; this.variables = new Dictionary <string, string>(dialogueTree.variables.data); }