配置表的处理方式
来源:互联网 发布:vb.net 高级编程 pdf 编辑:程序博客网 时间:2024/06/18 13:29
1.配置文件放在StreamingAssets文件夹下,二进制文件都放在StreamingAssets文件夹下
2.资源加载器
3.每个表对应一个类:类中由属性+方法(加载表方法/根据ID获取表信息方法)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
public class TableLoader : MonoBehaviour {
private static TableLoader instance;
public static TableLoader Instance
{
get
{
if (instance == null)
{
instance = new GameObject("TableLoader").AddComponent<TableLoader>();
}
return instance;
}
}
public void LoadTable(string tableName, Action<string> action)
{
string path = Path.Combine(Application.streamingAssetsPath, tableName);
StartCoroutine(LoadText(path, action));
}
IEnumerator LoadText(string path, Action<string> action)
{
string text = string.Empty;
if (path.Contains("://"))
{
WWW www = new WWW(path);
yield return www;
text = www.text;
}
else
{
if (File.Exists(path))
text = File.ReadAllText(path);
else
{
Debug.LogError("can not find table,path=" + path);
yield break;
}
}
if (action != null)
action(text);
}
}
public class TestInfo
{
public int ID;
public string name;
public static List<TestInfo> TestInfos = new List<TestInfo>();
public static void LoadTestInfo()
{
TableLoader.Instance.LoadTable("TestInfo.txt", (text) =>
{
Debug.LogError(text);
});
}
void HandleLines(string text)
{
text = text.Trim();
StringReader sr = new StringReader(text);
string line = null;
while ((line = sr.ReadLine()) != null)
{
HandleLine(line);
}
}
void HandleLine(string line)
{
TestInfo ti = new TestInfo();
string[] items = line.Split(',');
ti.ID = int.Parse(items[0]);
ti.name = items[1];
TestInfos.Add(ti);
}
public static TestInfo GetTestInfo(int ID)
{
TestInfo ti = null;
foreach (var item in TestInfos)
{
if (item.ID == ID)
{
ti = item;
break;
}
}
if (ti == null)
Debug.LogError("can not find TestInfo,ID=" + ID);
return ti;
}
}
- 配置表的处理方式
- StrutsTestCase配置的常见问题及其多级Action的处理方式
- spring采用基于xml配置方式进行事务的处理
- Spring MVC中对Annotation配置方式的处理流程
- jboss7中配置get方式的编码处理
- Kubernetes 针对资源紧缺处理方式的配置
- Sqlserver的表连接查询处理方式
- 处理问题的方式
- 多线程的处理方式
- 不良资产的处理方式
- 时间的处理方式
- 异常的处理方式
- java的处理方式
- gradle 的配置(多渠道打包,改包名,测试环境vs正式环境处理方式,配置宏)
- 几个开源项目配置信息的存储和处理的方式
- spring利用扫描方式对bean的处理(对任何版本如何获取xml配置信息的处理)
- 可编程的配置方式
- fpga的配置方式
- spring mvc InitBinder 遇到的坑接收不了参数
- Android设计模式之(3)----原型模式
- Krpano插件--event事件注释
- Bootstrap Table使用整理(一)
- TensorFlow 训练 MNIST 数据
- 配置表的处理方式
- ESXi对接iscsi存储操作指南
- Insertion Sort List
- E
- CI框架cli命令行
- cookie & session
- [web前端学习笔记]定位的盒子居中显示
- Windows服务(Windows Service,system权限)程序显示界面与用户交互(xp,win7通用)
- Go语言学习之mime包(the way to go)