示例#1
0
        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);
        }
示例#2
0
 protected void Uninitialize()
 {
     CurrentTree      = null;
     treeInitialized  = false;
     dialogueTreeNode = null;
     nodes            = new List <DialogueNode>();
     originalNodes    = new List <DialogueNode>();
 }
示例#3
0
        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.");
            }
        }
示例#4
0
 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);
 }
示例#5
0
 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();
 }
示例#6
0
        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;
        }
示例#7
0
 public OptionSelection(DialogueTreeEntity tree, OptionEntity option, string text)
 {
     this.tree   = tree;
     this.option = option;
     this.Text   = text;
 }
示例#8
0
 public DialogueTreeNode Initialize(DialogueTreeEntity entity)
 {
     this.entity = entity;
     this.Window = new Rect(10f, 10f, 200f, 50f);
     return(this);
 }
示例#9
0
 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;
 }
示例#10
0
 public RuntimeBuilder(DialogueTreeEntity dialogueTree, Random random) : base(random)
 {
     this.dialogueTree = dialogueTree;
     this.variables    = new Dictionary <string, string>(dialogueTree.variables.data);
 }