public static void LoadFromBinanry(byte[] bytes) { System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes); System.IO.BinaryReader br = new System.IO.BinaryReader(ms); int length = br.ReadInt32(); for (int i = 0; i < length; i++) { br.ReadByte(); } int looplength = br.ReadInt32(); for (int i = 0; i < looplength; i++) { monster datamonster = new monster(); datamonster.id = br.ReadInt32(); datamonster.name = br.ReadString(); datamonster.level = br.ReadInt32(); datamonster.model = br.ReadString(); datamonster.head = br.ReadString(); datamonster.learnedskilllist = br.ReadString(); datamonster.movespeed = br.ReadInt32(); datamonster.idle = br.ReadString(); datamonster.run = br.ReadString(); datamonster.death = br.ReadString(); datamonster.hit = br.ReadString(); datamonster.maxhp = br.ReadInt32(); datamonster.maxmp = br.ReadInt32(); datamonster.basedamage = br.ReadInt32(); datamonster.basedefense = br.ReadInt32(); datamonster.BodyModify = br.ReadSingle(); datamonster.AnimationSpeed = br.ReadSingle(); datamonster.IsBoss = br.ReadInt32(); datamonster.hpbarheight = br.ReadSingle(); datamonster.nameheight = br.ReadSingle(); datamonster.ringradius = br.ReadSingle(); if (_datas.ContainsKey(datamonster.id)) { #if UNITY_EDITOR UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误,主键重复:" + datamonster.id); } _datas.Add(datamonster.id, datamonster); } br.Close(); ms.Close(); }
public static void LoadFromString(string data) { string content = data; string[] lines = content.Split('\n'); for (int i = 3; i < lines.Length; i++) { string line = lines[i]; line = line.Replace("\r", ""); if (string.IsNullOrEmpty(line)) { continue; } string[] values = line.Split('\t'); if (values.Length != memberCount) { Debug.LogError("monster严重错误,表头和表数据长度不一样"); #if UNITY_EDITOR UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("monster严重错误,表头和表数据长度不一样"); } monster datamonster = new monster(); if (!int.TryParse(values[0], out datamonster.id)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[0] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[0] + " to int" + " 第" + i + "行,第0列"); } datamonster.name = values[1]; if (!int.TryParse(values[2], out datamonster.level)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[2] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[2] + " to int" + " 第" + i + "行,第2列"); } datamonster.model = values[3]; datamonster.head = values[4]; datamonster.learnedskilllist = values[5]; if (!int.TryParse(values[6], out datamonster.movespeed)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[6] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[6] + " to int" + " 第" + i + "行,第6列"); } datamonster.idle = values[7]; datamonster.run = values[8]; datamonster.death = values[9]; datamonster.hit = values[10]; if (!int.TryParse(values[11], out datamonster.maxhp)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[11] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[11] + " to int" + " 第" + i + "行,第11列"); } if (!int.TryParse(values[12], out datamonster.maxmp)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[12] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[12] + " to int" + " 第" + i + "行,第12列"); } if (!int.TryParse(values[13], out datamonster.basedamage)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[13] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[13] + " to int" + " 第" + i + "行,第13列"); } if (!int.TryParse(values[14], out datamonster.basedefense)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[14] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[14] + " to int" + " 第" + i + "行,第14列"); } if (!float.TryParse(values[15], out datamonster.BodyModify)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[15] + " to float"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[15] + " to float" + " 第" + i + "行,第15列"); } if (!float.TryParse(values[16], out datamonster.AnimationSpeed)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[16] + " to float"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[16] + " to float" + " 第" + i + "行,第16列"); } if (!int.TryParse(values[17], out datamonster.IsBoss)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[17] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[17] + " to int" + " 第" + i + "行,第17列"); } if (!float.TryParse(values[18], out datamonster.hpbarheight)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[18] + " to float"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[18] + " to float" + " 第" + i + "行,第18列"); } if (!float.TryParse(values[19], out datamonster.nameheight)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[19] + " to float"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[19] + " to float" + " 第" + i + "行,第19列"); } if (!float.TryParse(values[20], out datamonster.ringradius)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[20] + " to float"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[20] + " to float" + " 第" + i + "行,第20列"); } if (datas.ContainsKey(datamonster.id)) { #if UNITY_EDITOR UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误,主键重复:" + datamonster.id); } datas.Add(datamonster.id, datamonster); } }