Using System;
Using Unityengine;
Using System.Collections;
Using System.Collections.Generic;
public class MessageText
{
private static MessageText instance;
<summary>
Simple Interest Mode
</summary>
<returns></returns>
public static MessageText Instance ()
{
if (instance! = NULL) return instance;
Instance=new MessageText ();
return instance;
}
Dictionary<int, string> Dictionary = new Dictionary<int, string> ();
//<summary>
//Initialize method, read data from table
//</summary>
Public MessageText ()
{
Textasset text Asset = resources.load<textasset> ("Csv/errorcode");
string[] textstrings = TextAsset.text.Split (new char[] {' \ r ', ' \ n '}, stringsplitoptions.removeemptyentries);
for (int i = 2; i < textstrings.length; i++)
{
if (textstrings[i] = = NULL | | textstrings.length = = 0)
{
Continue;
}
string[] strings = Textstrings[i]. Split (', ');
if (!dictionary. ContainsKey (Convert.ToInt32 (strings[0)))
{
Dictionary. ADD (Convert.ToInt32 (Strings[0]), strings[1]);
}
}
Debug.Log ("read succeeded");
}
<summary>
User prompts, pop-up window display content
</summary>
<param name= "id" > id</param> of the content to be prompted
public void showmessage (int id)
{
string text = Dictionary[id];
DialogTipsCtrl.Instance.ShowMessage (text);
Debug.Log ("Hint Box prompt content:" +text);
}
}
Unity reads data into a dictionary from a table