Пример #1
0
        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++)
            {
                battletarget databattletarget = new battletarget();
                databattletarget.id         = br.ReadInt32();
                databattletarget.columntype = br.ReadInt32();
                databattletarget.weight1    = br.ReadString();
                databattletarget.weight2    = br.ReadString();
                databattletarget.weight3    = br.ReadString();
                databattletarget.weight4    = br.ReadString();
                databattletarget.weight5    = br.ReadString();
                if (_datas.ContainsKey(databattletarget.id))
                {
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误,主键重复:" + databattletarget.id);
                }
                _datas.Add(databattletarget.id, databattletarget);
            }
            br.Close();
            ms.Close();
        }
Пример #2
0
        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("battletarget严重错误,表头和表数据长度不一样");
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("battletarget严重错误,表头和表数据长度不一样");
                }
                battletarget databattletarget = new battletarget();
                if (!int.TryParse(values[0], out databattletarget.id))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[0] + " to int");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[0] + " to int" + " 第" + i + "行,第0列");
                }
                if (!int.TryParse(values[1], out databattletarget.columntype))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[1] + " to int");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[1] + " to int" + " 第" + i + "行,第1列");
                }
                databattletarget.weight1 = values[2];
                databattletarget.weight2 = values[3];
                databattletarget.weight3 = values[4];
                databattletarget.weight4 = values[5];
                databattletarget.weight5 = values[6];
                if (datas.ContainsKey(databattletarget.id))
                {
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误,主键重复:" + databattletarget.id);
                }
                datas.Add(databattletarget.id, databattletarget);
            }
        }