示例#1
0
    public bool loadgame(int id)//加载存档函数
    {
        if (File.Exists(path + id))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(path + id, FileMode.Open);
            SaveBuild       save = (SaveBuild)bf.Deserialize(file);
            file.Close();

            Vector3i posTemp = new Vector3i();

            foreach (Chunkpos pos in save.chunkkey)
            {
                posTemp.x = pos.x; posTemp.y = pos.y; posTemp.z = pos.z;
                ChunkBuild chunkTemp = MapBuild.Instance.GetChunk(posTemp);
                for (int x = 0; x < ChunkBuild.width; x++)
                {
                    for (int y = 0; y < ChunkBuild.height; y++)
                    {
                        for (int z = 0; z < ChunkBuild.width; z++)
                        {
                            chunkTemp.blocks[x, y, z] = pos.blockType[x * 256 + y * 16 + z];
                        }
                    }
                }
                chunkTemp.CreateMesh();
            }
            return(true);
        }
        else
        {
            Debug.Log("No game saved!");
            return(false);
        }
    }
示例#2
0
    public SaveBuild createSave()
    {
        SaveBuild save      = new SaveBuild();
        Chunkpos  chunkTemp = new Chunkpos();

        save.mapID = DateTime.Now + "";

        foreach (ChunkBuild chunk in MapBuild.Instance.chunks.Values)
        {
            chunkTemp.x         = chunk.position.x;
            chunkTemp.y         = chunk.position.y;
            chunkTemp.z         = chunk.position.z;
            chunkTemp.blockType = new List <byte>();

            for (int x = 0; x < ChunkBuild.width; x++)
            {
                for (int y = 0; y < ChunkBuild.height; y++)
                {
                    for (int z = 0; z < ChunkBuild.width; z++)
                    {
                        chunkTemp.blockType.Add(chunk.blocks[x, y, z]);
                    }
                }
            }
            save.chunkkey.Add(chunkTemp);
        }

        return(save);
    }
示例#3
0
    public void savegame(int id)
    {
        SaveBuild save = createSave();

        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(path + id);

        bf.Serialize(file, save);
        file.Close();
    }
示例#4
0
 public string mapIDSaved(int id)
 {
     if (File.Exists(path + id))
     {
         BinaryFormatter bf   = new BinaryFormatter();
         FileStream      file = File.Open(path + id, FileMode.Open);
         SaveBuild       save = (SaveBuild)bf.Deserialize(file);
         file.Close();
         return(save.mapID);
     }
     else
     {
         return("No Saved!");
     }
 }