コード例 #1
0
    //https://stackoverflow.com/questions/27547122/c-sharp-override-with-different-parameters
    //https://stackoverflow.com/questions/5414515/c-sharp-passing-a-method-as-a-parameter-to-another-method
    public void StartDialogue(string dialoguename, Action _callback)
    {
        _instance.transform.gameObject.SetActive(true);
        _Dialogue.Clear();
        string fileFullPath = Path.Combine(SavePath, dialoguename);

        //fileFullPath = Path.Combine(fileFullPath, dialoguename + fileExtension);
        fileFullPath = Path.Combine(SavePath, dialoguename);
        if ((Directory.Exists(fileFullPath)))
        {
            Debug.Log("無此對話");
            return;
        }
        //IT TAKE ME A WHOLE NIGHT. MOTHER FXCKER
        //https://answers.unity.com/questions/1411034/textasset-return-null.html
        TextAsset DialogueText = (TextAsset)Resources.Load(fileFullPath, typeof(TextAsset));

        Debug.Log(dialoguename + "," + DialogueText);
        int count = 0;

        foreach (string s in DialogueText.text.Split('\n'))
        {
            try {
                _Dialogue.Enqueue(JsonUtility.FromJson <Dialogue>(s));
                count += 1;
            }
            catch (Exception e) {
                Debug.Log(e.Message + ',' + fileFullPath + ',' + count.ToString());
                return;
            }
        }

        /*
         * System.IO.StreamReader file = new System.IO.StreamReader(fileFullPath);
         * while ((line = file.ReadLine()) != null) {
         *      if (line[0] == '#') {
         *              continue;
         *      }
         *      try {
         *              _Dialogue.Enqueue(JsonUtility.FromJson<Dialogue>(line));
         *      }
         *      catch (Exception e) {
         *              Debug.Log(e.Message);
         *              return;
         *      }
         * }
         * file.Close();
         */
        Callback = _callback;
        ContinueButton.GetComponentInChildren <Text>().text = "Continue>>";
        DisplayNextSentence();
    }
コード例 #2
0
    public void DisplayNextSentence()
    {
        if (_Dialogue.Count == 0)
        {
            EndDialogue();
            return;
        }

        else if (_Dialogue.Count == 1)
        {
            ContinueButton.GetComponentInChildren <Text>().text = "End>>";
        }
        Dialogue currentDialogue = _Dialogue.Dequeue();

        nameText.text = currentDialogue.name;
        string sentence = currentDialogue.sentence;

        SetImage(currentDialogue);
        StopAllCoroutines();
        ContinueButton.SetActive(false);
        StartCoroutine(TypeSentence(sentence));
    }