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("读取成功"); }
时间: 2024-10-30 05:19:12