void Start() { gameObject.GetComponent <Rigidbody2D>().gravityScale = 0; string filename = ""; CSVHelper.Instance().ReadCSVFile("configuration", (table) => { // 可以遍历整张表 foreach (CSVLine line in table) { foreach (KeyValuePair <string, string> item in line) { Debug.Log(string.Format("item key = {0} item value = {1}", item.Key, item.Value)); } } //可以拿到表中任意一项数据 filename = table["1"]["name"]; //Debug.Log(filename); outPath = Application.dataPath + filename + ".csv"; stdDev1 = float.Parse(table["2"]["name"]); stdDev2 = float.Parse(table["3"]["name"]); stdDev3 = float.Parse(table["4"]["name"]); stdDev4 = float.Parse(table["5"]["name"]); stdDev5 = float.Parse(table["6"]["name"]); carspeedY = float.Parse(table["7"]["name"]); }); //每次启动客户端删除之前保存的Log if (File.Exists(outPath)) { File.Delete(outPath); } }
/// <summary> /// 从配置表读取方块和怪物的信息 /// </summary> public void InitData() { CSVHelper.Instance().ReadCSVFile("CubeConfig", (table) => { // 可以遍历整张表 foreach (CSVLine line in table) { Consts.cubeList.Add(new BaseCube(Int32.Parse(line["cubeId"]), line["cubeName"], line["imgUrl"], line["describe"], line["tag"])); } readFinishCube = true; readFinsh = readFinishCube && readFinishAilist; }); CSVHelper.Instance().ReadCSVFile("monsterConfig", (table) => { // 可以遍历整张表 foreach (CSVLine line in table) { Consts.AIList.Add(new AIInfo(Int32.Parse(line["aiid"]), line["aiName"], line["imgUrl"], Int32.Parse(line["patrolDistance"]), Int32.Parse(line["patrolSpeed"]), Int32.Parse(line["followDistance"]), float.Parse(line["followSpeed"]), float.Parse(line["attackDistance"]), Int32.Parse(line["jumpHeight"]), Int32.Parse(line["attackPower"]), Int32.Parse(line["hp"]), bool.Parse(line["isStepDeath"]), bool.Parse(line["isHurtBlock"]), bool.Parse(line["isBurstBlock"]), bool.Parse(line["isGravityBlock"]), bool.Parse(line["attackOtherAi"]), bool.Parse(line["attackBlock"]), Int32.Parse(line["fallDeathHeight"]), line["describe"], line["attack"], line["health"], line["speed"])); } readFinishAilist = true; readFinsh = readFinishCube && readFinishAilist; }); }
void Update() { if (readFinish) { // 可以类似访问数据库一样访问配置表中的数据 CSVLine line = CSVHelper.Instance().SelectFrom("csv_test").WhereIDEquals(10011); Debug.Log(line["name"]); readFinish = false; } }
void Start() { CSVHelper.Instance().ReadCSVFile("csv_test", (table) => { readFinish = true; // 可以遍历整张表 foreach (CSVLine line in table) { foreach (KeyValuePair <string, string> item in line) { Debug.Log(string.Format("item key = {0} item value = {1}", item.Key, item.Value)); } } //可以拿到表中任意一项数据 Debug.Log(table["10011"]["id"]); }); }