Unity之使用csv文件
来源:互联网 发布:流畅的python 编辑:程序博客网 时间:2024/06/07 03:31
我们在做游戏时,可以通过在Excel/Number里将数据导出成csv文件,然后在程序里动态读取。
在Unity中可以把csv放到Resources目录或StreamingAsset目录里,然后以文本的方式加载.
网上的csv解析大多没有处理引号,逗号等特殊符号,要是我们在数据配置中还存有json,就需要用下面的代码
using System.Collections;using System.Collections.Generic;public class CSV {public static List<List<string>> Decode(string text){if (text == null)return null;List<List<string>> result = new List<List<string>>();List<string> line = new List<string>();string field = "";bool isInQuotation = false;//字符串模式bool isInField = true;//是否在读取Field,用来表示空Fieldint i = 0;while (i < text.Length){char ch = text[i];if (isInQuotation){if (ch == '"'){if (i < text.Length - 1 && text[i + 1] == '"')//重复"只算一个,切不结束字符串模式{field += '"';i++;}else{isInQuotation = false;}}else{field += ch;//字符串模式中所有字符都要加入}}else{switch (ch){case ',':line.Add(field);field = "";isInField = true;break;case '"':if (isInField)isInQuotation = true;//进入字符串模式elsefield += ch;break;case '\r':if (field.Length > 0 || isInField){line.Add(field);field = "";}result.Add(line);line =new List<string>();isInField = true;//下一行首先应该是数据if (i < text.Length - 1 && text[i + 1] == '\n')//跳过\r\ni++;break;default:isInField = false;field += ch;break;}}i++;}//收尾工作if (field.Length > 0 || isInField && line.Count > 0)//如果是isInField标记的单元格,则要保证这行有其他数据,否则单独一个空单元格的行是没有意义的line.Add(field);if (line.Count > 0)result.Add(line);return result;}}
0 0
- Unity之使用csv文件
- Unity读取.csv文件
- Unity CSV文件加载案例
- CSV文件及其使用
- CSV文件及其使用
- CSV文件及其使用
- 【Unity&I2】csv文件导入失败
- Unity ScriptableObject 自动导出 .csv文件
- Python_使用csv模块解析csv文件
- Python_使用csv模块解析csv文件
- 使用Apache Common CSV读写CSV文件
- python使用csv模块读写csv文件
- 使用commons-csv生成.csv文件
- VC之CSV文件操作
- php之读取csv文件!!!
- python之读写csv文件
- Spark 之 读写 csv文件
- 使用Java操作CSV文件
- 2006: [NOI2010]超级钢琴 ST表+优先队列
- 搜索专题 第二个·
- BestCoder Round #79 (div.2) hdu 5660 ,hdu 5661
- Google C++命名规范
- Tricks(三十一)—— 访问一个数组相邻的奇数位偶数位
- Unity之使用csv文件
- 2795: [Poi2012]A Horrible Poem hash
- 【1-3】pythondb增删改查
- 2179: FFT快速傅立叶 FFT
- 推荐!国外程序员整理的机器学习资源大全
- 2194: 快速傅立叶之二 FFT
- 3527: [Zjoi2014]力 FFT
- git分支原理命令图文解析
- 3720: Gty的妹子树 块状树