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++) { skill dataskill = new skill(); dataskill.id = br.ReadInt32(); dataskill.skillname = br.ReadString(); dataskill.level = br.ReadInt32(); dataskill.image = br.ReadString(); dataskill.targettype = br.ReadInt32(); dataskill.damage = br.ReadInt32(); dataskill.skillpriority = br.ReadInt32(); dataskill.manacost = br.ReadInt32(); dataskill.castrange = br.ReadSingle(); dataskill.casttime = br.ReadInt32(); dataskill.colddown = br.ReadInt32(); dataskill.cancelCastIfTargetDied = br.ReadInt32(); dataskill.skilltype = br.ReadInt32(); dataskill.AreaCenterType = br.ReadInt32(); dataskill.TargetNum = br.ReadInt32(); dataskill.TargetRangeType = br.ReadInt32(); dataskill.TargetRange = br.ReadInt32(); dataskill.Angle = br.ReadInt32(); dataskill.TargetChooseType = br.ReadInt32(); dataskill.SelfMoveType = br.ReadInt32(); dataskill.SelfMoveDistance = br.ReadInt32(); dataskill.SelfMoveSpeed = br.ReadInt32(); dataskill.bullet = br.ReadInt32(); dataskill.bulletspeed = br.ReadInt32(); dataskill.attackaction = br.ReadString(); dataskill.InstantSkillAction = br.ReadInt32(); dataskill.ContinuousSkillAction = br.ReadInt32(); dataskill.AttackEffect = br.ReadInt32(); dataskill.TargetEffect = br.ReadInt32(); dataskill.EffectModify = br.ReadSingle(); if (_datas.ContainsKey(dataskill.id)) { #if UNITY_EDITOR UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误,主键重复:" + dataskill.id); } _datas.Add(dataskill.id, dataskill); } 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("skill严重错误,表头和表数据长度不一样"); #if UNITY_EDITOR UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("skill严重错误,表头和表数据长度不一样"); } skill dataskill = new skill(); if (!int.TryParse(values[0], out dataskill.id)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[0] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[0] + " to int" + " 第" + i + "行,第0列"); } dataskill.skillname = values[1]; if (!int.TryParse(values[2], out dataskill.level)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[2] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[2] + " to int" + " 第" + i + "行,第2列"); } dataskill.image = values[3]; if (!int.TryParse(values[4], out dataskill.targettype)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[4] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[4] + " to int" + " 第" + i + "行,第4列"); } if (!int.TryParse(values[5], out dataskill.damage)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[5] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[5] + " to int" + " 第" + i + "行,第5列"); } if (!int.TryParse(values[6], out dataskill.skillpriority)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[6] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[6] + " to int" + " 第" + i + "行,第6列"); } if (!int.TryParse(values[7], out dataskill.manacost)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[7] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[7] + " to int" + " 第" + i + "行,第7列"); } if (!float.TryParse(values[8], out dataskill.castrange)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[8] + " to float"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[8] + " to float" + " 第" + i + "行,第8列"); } if (!int.TryParse(values[9], out dataskill.casttime)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[9] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[9] + " to int" + " 第" + i + "行,第9列"); } if (!int.TryParse(values[10], out dataskill.colddown)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[10] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[10] + " to int" + " 第" + i + "行,第10列"); } if (!int.TryParse(values[11], out dataskill.cancelCastIfTargetDied)) { #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 dataskill.skilltype)) { #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 dataskill.AreaCenterType)) { #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 dataskill.TargetNum)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[14] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[14] + " to int" + " 第" + i + "行,第14列"); } if (!int.TryParse(values[15], out dataskill.TargetRangeType)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[15] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[15] + " to int" + " 第" + i + "行,第15列"); } if (!int.TryParse(values[16], out dataskill.TargetRange)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[16] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[16] + " to int" + " 第" + i + "行,第16列"); } if (!int.TryParse(values[17], out dataskill.Angle)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[17] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[17] + " to int" + " 第" + i + "行,第17列"); } if (!int.TryParse(values[18], out dataskill.TargetChooseType)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[18] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[18] + " to int" + " 第" + i + "行,第18列"); } if (!int.TryParse(values[19], out dataskill.SelfMoveType)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[19] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[19] + " to int" + " 第" + i + "行,第19列"); } if (!int.TryParse(values[20], out dataskill.SelfMoveDistance)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[20] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[20] + " to int" + " 第" + i + "行,第20列"); } if (!int.TryParse(values[21], out dataskill.SelfMoveSpeed)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[21] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[21] + " to int" + " 第" + i + "行,第21列"); } if (!int.TryParse(values[22], out dataskill.bullet)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[22] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[22] + " to int" + " 第" + i + "行,第22列"); } if (!int.TryParse(values[23], out dataskill.bulletspeed)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[23] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[23] + " to int" + " 第" + i + "行,第23列"); } dataskill.attackaction = values[24]; if (!int.TryParse(values[25], out dataskill.InstantSkillAction)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[25] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[25] + " to int" + " 第" + i + "行,第25列"); } if (!int.TryParse(values[26], out dataskill.ContinuousSkillAction)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[26] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[26] + " to int" + " 第" + i + "行,第26列"); } if (!int.TryParse(values[27], out dataskill.AttackEffect)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[27] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[27] + " to int" + " 第" + i + "行,第27列"); } if (!int.TryParse(values[28], out dataskill.TargetEffect)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[28] + " to int"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[28] + " to int" + " 第" + i + "行,第28列"); } if (!float.TryParse(values[29], out dataskill.EffectModify)) { #if UNITY_EDITOR Debug.LogError("数据有误:" + values[29] + " to float"); UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误:" + values[29] + " to float" + " 第" + i + "行,第29列"); } if (datas.ContainsKey(dataskill.id)) { #if UNITY_EDITOR UnityEditor.EditorApplication.isPaused = true; #endif throw new ArgumentException("数据有误,主键重复:" + dataskill.id); } datas.Add(dataskill.id, dataskill); } }