Esempio n. 1
0
 private void LoadJson(string path)
 {
     using (StreamReader r = new StreamReader(Path.Combine(Engine.ContentDirectory, path + ".json")))
     {
         string readJson = r.ReadToEnd();
         dialogueJson = JsonConvert.DeserializeObject <DialogueJson>(readJson);
     }
 }
Esempio n. 2
0
    static Dictionary <string, Dialogue> LoadDialogues()
    {
        Dictionary <string, Dialogue> dialogues = new Dictionary <string, Dialogue>();

        string dialogueFileContent = GetFileContent(Application.dataPath + DIALOGUES_PATH);
        int    currentPosition = 1;
        string key, jsonEntry;

        while (TryGetNextEntry(dialogueFileContent, ref currentPosition, out key, out jsonEntry))
        {
            DialogueJson dialogueRaw = JsonUtility.FromJson <DialogueJson>(jsonEntry);
            Dialogue     dialogue;
            if (dialogues.TryGetValue(key, out dialogue) == false)
            {
                dialogue = new Dialogue();
                dialogues.Add(key, dialogue);
            }

            dialogue.DialogueBody = dialogueRaw.DialogueBody;
            OptionJson[] answersRaw = dialogueRaw.Options;
            if (answersRaw != null)
            {
                Option[] dialogueOptions = new Option[answersRaw.Length];
                for (int i = 0; i < answersRaw.Length; i++)
                {
                    var optionRaw = answersRaw[i];
                    var option    = new Option();
                    option.OptionText = optionRaw.OptionText;
                    string   nextDialogueKey = optionRaw.NextDialogue;
                    Dialogue nextDialogue;

                    if (dialogues.TryGetValue(nextDialogueKey, out nextDialogue) == false)
                    {
                        nextDialogue = new Dialogue();
                        dialogues.Add(nextDialogueKey, nextDialogue);
                    }

                    option.NextDialogue = nextDialogue;
                    option.Hint         = optionRaw.Hint;

                    dialogueOptions[i] = option;
                }
                dialogue.Options = dialogueOptions;
            }
            else
            {
                dialogue.Options = new Option[0];
            }
        }


        return(dialogues);
    }
Esempio n. 3
0
    public static Dictionary <string, Dialogue> LoadDialogues()
    {
        Dictionary <string, Dialogue> dialogues = new Dictionary <string, Dialogue>();

        string jsonFileContent = File.ReadAllText(Application.dataPath + PATH).Replace("\t", "").Replace("\n", "").Replace("\r", "");
        int    currentPosition = 1;
        string key, jsonEntry;

        while (TryGetNextEntry(jsonFileContent, ref currentPosition, out key, out jsonEntry))
        {
            DialogueJson dialogueRaw = JsonUtility.FromJson <DialogueJson>(jsonEntry);
            Dialogue     dialogue;
            if (dialogues.TryGetValue(key, out dialogue) == false)
            {
                dialogue = new Dialogue();
                dialogues.Add(key, dialogue);
            }

            dialogue.DialogueText = dialogueRaw.DialogueText;
            AnswerJson[] answersRaw      = dialogueRaw.Answers;
            Answer[]     dialogueAnswers = new Answer[answersRaw.Length];
            for (int i = 0; i < answersRaw.Length; i++)
            {
                var answerRaw = answersRaw[i];
                var answer    = new Answer();
                answer.AnswerText = answerRaw.AnswerText;
                string   nextDialogueKey = answerRaw.NextDialogue;
                Dialogue nextDialogue;

                if (dialogues.TryGetValue(nextDialogueKey, out nextDialogue) == false)
                {
                    nextDialogue = new Dialogue();
                    dialogues.Add(nextDialogueKey, nextDialogue);
                }

                answer.NextDialogue = nextDialogue;
                dialogueAnswers[i]  = answer;
            }
            dialogue.Answers = dialogueAnswers;
        }


        return(dialogues);
    }