Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Hashinu · Jul 27, 2019 at 07:43 PM · unity 2dunityeditorvisual studio

Why is my DialogueBoxObject not recognizing its dialogue?

I'm following a Visual Novel tutorial. I made an editor so I could easily change the dialogue and now I want it to be displayed on the screen when I start it. Now I added a public string dialogue in the DialogueBox class, and in the DialogueParser class I made the connection between the program and the text. I just can't find my mistake. I'm really bad at explaining, so here in short: Where I underlined in the Picture: It should Display some text from my text file Dialogue1.txt, but ist just empty and I don't know why. I would really appreciate it if you could help me!

Here's my code so far:

DialogueParser class

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEditor;
 using System.Text;
 using System.IO;
 using System.Text.RegularExpressions;
 using UnityEditor.SceneManagement;
 using System.Collections.Concurrent;
 using System.Linq;
 
 public class DialogeParser : MonoBehaviour
 {
     List<DialogueLine> lines;
         
 
     struct DialogueLine
     {
         public string name;
         public string content;
         public int pose;
 
         public DialogueLine (string n, string c,int p )
         {
             name = n;
             content = c;
             pose = p;
         }
     }
     // Start is called before the first frame update
     void Start()
     {
         string file = "Dialogue1";
         string sceneNum = EditorSceneManager.GetActiveScene().name;
         sceneNum = Regex.Replace(sceneNum, "(^ 0 - 9)", ""); // 1
         file += sceneNum; // file + SceneNum = Dialogue 1
         file += ".txt";
         lines = new List<DialogueLine>();
         LoadDialogue(file);
     }
 
     // Update is called once per frame
     void Update()
     {
         
     }
 
     public string GetName(int lineNumber)
     {
         if (lineNumber < lines.Count)
             return lines[lineNumber].name;
 
         return "";
     }
 
     public string GetContent(int lineNumber)
     {
         if (lineNumber < lines.Count)
             return lines[lineNumber].content;
 
         return "";
     }
 
     public int GetPose(int lineNumber)
     {
         if (lineNumber < lines.Count)
             return lines[lineNumber].pose;
 
         return 0;
     }
     void LoadDialogue(string filename)
     {
         string file = "Asset/Resources/" + filename;
         string line;
         StreamReader r = new StreamReader(file);
         using (r)
         {
             do
             {
                 line = r.ReadLine();
                 if (line!=null)
                 {
                     string[] line_values = SplitCsvLine (line);
                     DialogueLine line_entry = new  DialogueLine(line_values[0], line_values[1],int.Parse(line_values[2]));
                     lines.Add(line_entry);
                         
                 }
             }
             while (line != null);
             r.Close();
         }
     }
 
     // splits a CSV row 
     private string[] SplitCsvLine(string line)
     {
         string pattern = @"
      # Match one value in valid CSV string.
      (?!\s*$)                                      # Don't match empty last value.
      \s*                                           # Strip whitespace before value.
      (?:                                           # Group for value alternatives.
        '(?<val>[^'\\]*(?:\\[\S\s][^'\\]*)*)'       # Either $1: Single quoted string,
      | ""(?<val>[^""\\]*(?:\\[\S\s][^""\\]*)*)""   # or $2: Double quoted string,
      | (?<val>[^,'""\s\\]*(?:\s+[^,'""\s\\]+)*)    # or $3: Non-comma, non-quote stuff.
      )                                             # End group of value alternatives.
      \s*                                           # Strip whitespace after value.
      (?:,|$)                                       # Field ends on comma or EOS.
      ";
 
  

 string[] values = (from Match m in Regex.Matches(line, pattern,
             RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline)
                            select m.Groups[1].Value).ToArray();
 
         return values;
     }
 
 }

DialogueBox Class

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class DialogueBox : MonoBehaviour
 {
 
     DialogeParser parser;
     public string dialogue;
     int lineNum;
     public GUIStyle customStyle;
     // Start is called before the first frame update
     void Start()
     {
         dialogue = "";
         parser = GameObject.Find("DialogueParserObject").GetComponent<DialogeParser>();
         lineNum = 0;
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetMouseButtonDown(0))
         {
             dialogue = parser.GetContent(lineNum);
             lineNum++;
         }
     }
      void OnGUI()
     {
         dialogue = GUI.TextField(new Rect(100, 200, 600, 200),dialogue, customStyle);
     }
 
 }
 
 

       









alt text

2019-07-27-li-2.jpg (372.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

184 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

intellisense in Vis Studio still does not recognize or provide autocomplete for Unity namespace items. 0 Answers

Help with options menu in unity 0 Answers

Visual studio errors... once again 0 Answers

Can someone please help me fix the script? in unity3D to move forwards and backwards by swiping to the screen,Rotate and move forward script not working 0 Answers

Unity Shader Optimization? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges