Example #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++)
            {
                effect dataeffect = new effect();
                dataeffect.id         = br.ReadInt32();
                dataeffect.effectname = br.ReadString();
                dataeffect.effecttype = br.ReadInt32();
                dataeffect.filename   = br.ReadString();
                dataeffect.isloop     = br.ReadBoolean();
                dataeffect.scale      = br.ReadSingle();
                if (_datas.ContainsKey(dataeffect.id))
                {
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误,主键重复:" + dataeffect.id);
                }
                _datas.Add(dataeffect.id, dataeffect);
            }
            br.Close();
            ms.Close();
        }
Example #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("effect严重错误,表头和表数据长度不一样");
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("effect严重错误,表头和表数据长度不一样");
                }
                effect dataeffect = new effect();
                if (!int.TryParse(values[0], out dataeffect.id))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[0] + " to int");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[0] + " to int" + " 第" + i + "行,第0列");
                }
                dataeffect.effectname = values[1];
                if (!int.TryParse(values[2], out dataeffect.effecttype))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[2] + " to int");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[2] + " to int" + " 第" + i + "行,第2列");
                }
                dataeffect.filename = values[3];
                int isloop = 0;
                if (!int.TryParse(values[4], out isloop))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[4] + " to int");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[4] + " to int" + " 第" + i + "行,第4列");
                }
                dataeffect.isloop = isloop == 1;

                if (!float.TryParse(values[5], out dataeffect.scale))
                {
#if UNITY_EDITOR
                    Debug.LogError("数据有误:" + values[5] + " to float");
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误:" + values[5] + " to float" + " 第" + i + "行,第5列");
                }
                if (datas.ContainsKey(dataeffect.id))
                {
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPaused = true;
#endif
                    throw new ArgumentException("数据有误,主键重复:" + dataeffect.id);
                }
                datas.Add(dataeffect.id, dataeffect);
            }
        }