// 解析怪物 public static MonsterJson Parse(LitJson.JsonData data) { MonsterJson json = new MonsterJson(); try { json.MagicAttack = (int)data["MagicAttack"]; json.dropoutid = (int)data["dropoutid"]; json.skill = (string)data["skill"]; json.id = (int)data["id"]; json.speak = (int)data["speak"]; json.Dodge = (int)data["Dodge"]; json.Hit = (int)data["Hit"]; json.expbound = (int)data["expbound"]; json.resourceid = (int)data["resourceid"]; json.MagicDefense = (int)data["MagicDefense"]; json.PhysicalAttack = (int)data["PhysicalAttack"]; json.type = (int)data["type"]; json.viptype = (int)data["viptype"]; json.hp = (int)data["hp"]; json.difficulty = (int)data["difficulty"]; json.moveable = (int)data["moveable"]; json.nickname = (string)data["nickname"]; json.PhysicalDefense = (int)data["PhysicalDefense"]; json.icon = (int)data["icon"]; json.ordSkill = (int)data["ordSkill"]; json.Force = (int)data["Force"]; json.level = (int)data["level"]; json.descript = (string)data["descript"]; json.mp = (int)data["mp"]; json.Speed = (int)data["Speed"]; } catch {} return(json); }
void ReadFile() { string[] text = File.ReadAllLines(strFilePath + strFileName, System.Text.Encoding.Default); //파일열고 읽어 저장, 라인별로 배열에 저장됨 MonsterJson[] monsters = new MonsterJson[text.Length]; for (int i = 0; i < text.Length; ++i) { monsters[i] = JsonUtility.FromJson <MonsterJson>(text[i]); print(monsters[i].SpawnTime + ", " + monsters[i].SpawnPosX + ", " + monsters[i].SpawnSpeed); } /* 아래 방법은 왜 그런지 텍스트로 읽히지 않음 * StringReader sr = new StringReader(strFilePath + strFileName); * string input = ""; * * while (input != null) * { * input = sr.ReadLine(); * Debug.Log("1 " + input + "\n"); //Log [ 1 "파일경로" ] 라고 출력됨 * //Debug.Log("1 " + System.Text.Encoding.UTF8.GetBytes(input)); * } * sr.Close(); */ }
// Start is called before the first frame update void Start() { MonsterJson monster = new MonsterJson(1f, 5f, 5f); print(monster.SpawnTime + ", " + monster.SpawnPosX + ", " + monster.SpawnSpeed); json += JsonUtility.ToJson(monster) + "\n"; json += JsonUtility.ToJson(monster) + "\n"; print(json); //WriteFile(); //쓰기 ReadFile(); //읽기 }
public override void Parse(Object asset) { if (asset != null && asset is TextAsset) { TextAsset textAsset = (TextAsset)asset; string sJson = textAsset.text; LitJson.JsonReader jsonR = new LitJson.JsonReader(sJson); LitJson.JsonData jsonD = LitJson.JsonMapper.ToObject(jsonR); int iCount = jsonD.Count; for (int i = 0; i < iCount; i++) // 将解析到的数据放到dict { LitJson.JsonData itemData = jsonD[i]; if (itemData == null) { continue; } MonsterJson jsonItem = MonsterJson.Parse(itemData); m_jsons.Add(jsonItem.id, jsonItem); } Globals.It.BundleMgr.UnLoadBundleLocal(asset); } }
// Start is called before the first frame update public object getJsonObj(string jsonTag) { object jsonObj = null; switch (jsonTag) { case "monster": MonsterJson monsterJson = new MonsterJson(); jsonObj = monsterJson.getMonsterJson(); break; case "skill": SkillJson skillJson = new SkillJson(); jsonObj = skillJson.getSkillJson(); break; case "buff": BuffJson buffJson = new BuffJson(); jsonObj = buffJson.getBuffJson(); break; } return(jsonObj); }