示例#1
0
        public static void Serialize(string filename)
        {
            BinaryFormatter formatter = new BinaryFormatter();
            Stream          stream    = new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
            MemoryStream    mstream   = new MemoryStream();

            formatter.Serialize(mstream, Data);
            byte[] mbyte = mstream.ToArray();
            byte[] tmp   = new byte[mbyte.Length];
            CsvHelper.Encode(mbyte, 0, tmp, 0, tmp.Length, ASCIIEncoding.ASCII.GetBytes("ABCDEFG2"));
            stream.Write(tmp, 0, tmp.Length);
            mstream.Close();
            stream.Close();
        }
示例#2
0
        public static void Deserialize(string filename, bool isAssetBundle = false)
        {
            TextAsset textAsset = null;

            if (isAssetBundle && AssetBundleMgr.ContainsFile(filename, "bytes"))
            {
                textAsset = AssetBundleMgr.Load(filename, "bytes") as TextAsset;
            }
            else
            {
                textAsset = Resources.Load(filename) as TextAsset;
            }
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    mstream   = new MemoryStream();

            byte[] tmp = new byte[textAsset.bytes.Length];
            CsvHelper.Encode(textAsset.bytes, 0, tmp, 0, tmp.Length, ASCIIEncoding.ASCII.GetBytes("ABCDEFG2"));
            mstream.Write(tmp, 0, tmp.Length);
            mstream.Position = 0;
            Data             = formatter.Deserialize(mstream) as Dictionary <int, HeroRecord>;
            mstream.Close();
        }