Example #1
0
 /// <summary>
 /// 强制写入Blocks
 /// </summary>
 public void WriteBlocks()
 {
     saveDelay.SetDelay(5000, WriteBlocks);
     try
     {
         string     root     = Data.RootPath + "/" + MapName + "/blocks.bin";
         List_Block lisblock = new List_Block();
         lisblock.blocks = blocks.ToArray();
         if (File.Exists(root))
         {
             File.Delete(root);
         }
         Stream          file      = new FileStream(root, FileMode.Create, FileAccess.Write);
         BinaryFormatter binFormat = new BinaryFormatter();
         binFormat.Serialize(file, lisblock);
         file.Close();
         file.Dispose();
     }
     catch { }
 }
Example #2
0
        /// <summary>
        /// 强制读取Blocks
        /// </summary>
        public void ReadBlocks()
        {
            string     root = Data.RootPath + MapName + "/blocks.bin";
            List_Block lisblock;

            if (!File.Exists(root))
            {
                lisblock        = new List_Block();
                lisblock.blocks = new Block[0];
            }
            else
            {
                Stream          file      = new FileStream(root, FileMode.Open, FileAccess.Read);
                BinaryFormatter binFormat = new BinaryFormatter();
                lisblock = (List_Block)binFormat.Deserialize(file);
                file.Close();
                file.Dispose();
            }
            blocks = new List <Block>(lisblock.blocks);
        }