예제 #1
0
    public static Conversation createConversation(string fileName)
    {
        string jsonString = readTextFile (/*"Assets/Resources/"*/"Text/" + fileName/* + ".json"*/);
        var N = JSON.Parse (jsonString);

        string name = N ["name"].Value;
        string img = N ["img"].Value;

        List<Conversation> conversations = new List<Conversation>();
        List<Answer> answers = new List<Answer>();

        Conversation start = new Conversation (name, img);

        for (int i = 0; i < N["start"].Count; i++) {
            Message msg = createMessage(N["start"][i]);
            start.addMessage(msg);
        }

        conversations.Add(start);

        for (int i = 0; i < N["ans"].Count; i++) {
            Conversation conv = new Conversation(name, img);
            Answer ans = new Answer(N["ans"][i]["text"].Value, N["ans"][i]["url"].Value);
            Debug.Log(N["ans"][i]["url"].Value);

            for (int j = 0; j < N["ans"][i]["nans"].Count; j++) {
                Message msg = createMessage(N["ans"][i]["nans"][j]);
                conv.addMessage(msg);
            }

            conversations.Add(conv);
            ans.setNextConversation(conv);
            answers.Add(ans);
        }

        for (int i = 0; i < conversations.Count - 1; i++) {
            foreach (Answer ans in answers) {
                conversations[i].addAnswer(ans);
            }
        }

        return conversations [0];
    }