/// <summary> /// 装载数据 /// </summary> public void LoadData() { // 装载玩家属性 /* * L_Data root = L_DataPool.Instance.CreatChildData("Root","Root"); * * L_Data test1 = root.CreatChildData("Test1","Test1"); * test1.CreatChildData("Child1",(int)1001); * test1.CreatChildData("Child2",(float)1.002); * L_Data test2 = root.CreatChildData("Test2","Test2"); * test2.CreatChildData("Child3",(uint)1003); * test2.CreatChildData("Child4",(bool)false); * L_Data test3 = root.CreatChildData("Test3","Test3"); * test3.CreatChildData("Child5",'c'); * test3.CreatChildData("Child6",(byte)255); * * XmlTool.SaveData<L_Data>(root,"Assets/test.xml"); * * XmlTool.LoadData<L_Data>(ref root,"Assets/test.xml"); * XmlTool.SaveData<L_Data>(root,"Assets/test1.xml"); */ L_Data root = L_DataPool.Instance.CreatChildData("Root", "Root"); root = CSVTool.LoadCsv <L_Data>(root, "Test"); }
public virtual void InitData() { if (items.Count == 0 || items == null) { TextAsset textAsset = ResourceManager.Instance.LoadRes <TextAsset> (ResourceManager.ResourceType.Data, mPath); if (textAsset != null) { string dataStr = textAsset.text; Dictionary <string, Dictionary <string, string> > datas = CSVTool.Parse(dataStr); foreach (string id in datas.Keys) { TableItem item = new TableItem(); int idValue = int.Parse(id); item.id = idValue; item.name = datas[id]["name"]; item.account = int.Parse(datas[id]["account"]); item.price = float.Parse(datas[id]["price"]); item.data = datas[id]["data"]; items.Add(item); this.d("damon", item.ToString(), false); } } else { Debug.Log(mPath); } } }
private void InitData() { TextAsset textAsset = ResourceManager.Instance.LoadRes <TextAsset> (ResourceManager.ResourceType.Data, "table"); Dictionary <string, Dictionary <string, string> > dic = CSVTool.Parse(textAsset.text); foreach (string id in dic.Keys) { string name = dic[id]["name"]; string path = dic[id]["resPath"]; BaseTable baseTable = new BaseTable(name, path); mDic[mIndex++] = baseTable; } }
public override void OnSingletonInit() { base.OnSingletonInit(); TextAsset text = ResourceManager.Instance.LoadRes <TextAsset> (ResourceManager.ResourceType.Data, "npc"); if (text == null) { Debug.LogError("load npc data failed"); return; } mDic = CSVTool.Parse(text.text); foreach (string id in mDic.Keys) { BaseNPC npc = new BaseNPC(); npc.id = int.Parse(id); npc.name = mDic[id]["Name"]; npc.position = mDic[id]["Position"]; npc.task = mDic[id]["Task"]; npc.message = mDic[id]["Message"]; npc.resPath = mDic[id]["ResPath"]; npcs.Add(npc); } }
Dictionary <string, Dictionary <string, string> > GetTableData() { TextAsset text = ResourceManager.Instance.LoadRes <TextAsset> (ResourceManager.ResourceType.Data, "npc"); return(CSVTool.Parse(text.text)); }
void LoadLevel(string levelName) { ClearScene(); if (levelName == "") { levelName = "level_demo"; } string filepath = Application.streamingAssetsPath + "/Levels/" + levelName + ".csv"; var data = CSVTool.Read(filepath, Encoding.UTF8); int width = 0; foreach (var line in data) { width = Mathf.Max(width, line.Count); } int height = data.Count; for (int i = 0; i < data.Count; ++i) { for (int j = 0; j < data[i].Count; ++j) { string element = data[i][j]; if (element == "") { continue; } GameObject obj = Instantiate(gridPrefab); obj.transform.parent = transform; GridContainer container = obj.GetComponent <GridContainer>(); Vector2 location = new Vector2(j - width / 2, height / 2 - i); container.Init(this, location); containers.Add(HashLocation(container.Location), container); Packet.Type packetType = Packet.Type.Unk; Packet packet = null; if (element.StartsWith("ant")) { // ant related info bool packable = false, unpackable = false; Orientation antOri = Orientation.NONE; packetType = Packet.Type.Ant; string antInfo = element.Substring(3); if (antInfo.StartsWith("P")) { packable = true; antInfo = antInfo.Substring(1); } else if (antInfo.StartsWith("U")) { unpackable = true; antInfo = antInfo.Substring(1); } if (antInfo.Length >= 2) { switch (antInfo[1]) { case 'r': antOri = Orientation.RIGHT; break; case 'l': antOri = Orientation.LEFT; break; case 'u': antOri = Orientation.UP; break; case 'd': antOri = Orientation.DOWN; break; } } // not safe here packet = new Packet(packetType, container); packet.AntInit(packable, unpackable, antOri); } else { switch (element) { case "tar": packetType = Packet.Type.Target; break; case "pack": packetType = Packet.Type.Box; break; case "wall": packetType = Packet.Type.Wall; break; case "hole": packetType = Packet.Type.Hole; break; default: break; } if (packetType != Packet.Type.Unk) { packet = new Packet(packetType, container); } } if (packetType != Packet.Type.Unk) { GameObject pack = Instantiate(packetPrefab); pack.transform.parent = transform; var renderer = pack.GetComponent <PacketRenderer>(); renderer.Init(this, packet); if (packet.type == Packet.Type.Ant) { selectedPacketRenderer = renderer; } } } } }