using System;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class MessageText
{
private static MessageText instance;
/// <summary>
/// 单利模式
/// </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>
/// 初始化方法,从表格读取数据
/// </summary>
public MessageText()
{
TextAsset textAsset = 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("读取成功");
}
/// <summary>
/// 用户提示,弹窗显示内容
/// </summary>
/// <param name="id">要提示的内容的ID</param>
public void ShowMessage(int id)
{
string text = dictionary[id];
DialogTipsCtrl.Instance.ShowMessage(text);
Debug.Log("提示框提示内容:"+text);
}
}