码迷,mamicode.com
首页 > 编程语言 > 详细

unity读取csv表格进字典

时间:2017-12-16 14:43:42      阅读:416      评论:0      收藏:0      [点我收藏+]

标签:body   rem   color   debug   for   单利   csv   private   char   

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("读取成功");
}

 

unity读取csv表格进字典

标签:body   rem   color   debug   for   单利   csv   private   char   

原文地址:http://www.cnblogs.com/0315cz/p/8046351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!