Ejemplo n.º 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++)
            {
                spawnmonster dataspawnmonster = new spawnmonster();
                dataspawnmonster.id               = br.ReadInt32();
                dataspawnmonster.mapid            = br.ReadInt32();
                dataspawnmonster.stage            = br.ReadInt32();
                dataspawnmonster.arrindex         = br.ReadInt32();
                dataspawnmonster.baseid           = br.ReadInt32();
                dataspawnmonster.spawnx           = br.ReadSingle();
                dataspawnmonster.spawny           = br.ReadSingle();
                dataspawnmonster.spawnz           = br.ReadSingle();
                dataspawnmonster.RelativePosition = br.ReadString();
                if (_datas.ContainsKey(dataspawnmonster.id))
                {
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误,主键重复:" + dataspawnmonster.id);
                }
                _datas.Add(dataspawnmonster.id, dataspawnmonster);
            }
            br.Close();
            ms.Close();
        }
Ejemplo n.º 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("spawnmonster严重错误,表头和表数据长度不一样");
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("spawnmonster严重错误,表头和表数据长度不一样");
                }
                spawnmonster dataspawnmonster = new spawnmonster();
                if (!int.TryParse(values[0], out dataspawnmonster.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 dataspawnmonster.mapid))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[1] + " to int");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[1] + " to int" + " 第" + i + "行,第1列");
                }
                if (!int.TryParse(values[2], out dataspawnmonster.stage))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[2] + " to int");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[2] + " to int" + " 第" + i + "行,第2列");
                }
                if (!int.TryParse(values[3], out dataspawnmonster.arrindex))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[3] + " to int");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[3] + " to int" + " 第" + i + "行,第3列");
                }
                if (!int.TryParse(values[4], out dataspawnmonster.baseid))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[4] + " to int");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[4] + " to int" + " 第" + i + "行,第4列");
                }
                if (!float.TryParse(values[5], out dataspawnmonster.spawnx))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[5] + " to float");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[5] + " to float" + " 第" + i + "行,第5列");
                }
                if (!float.TryParse(values[6], out dataspawnmonster.spawny))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[6] + " to float");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[6] + " to float" + " 第" + i + "行,第6列");
                }
                if (!float.TryParse(values[7], out dataspawnmonster.spawnz))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[7] + " to float");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[7] + " to float" + " 第" + i + "行,第7列");
                }
                dataspawnmonster.RelativePosition = values[8];
                if (datas.ContainsKey(dataspawnmonster.id))
                {
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误,主键重复:" + dataspawnmonster.id);
                }
                datas.Add(dataspawnmonster.id, dataspawnmonster);
            }
        }