Exemplo n.º 1
0
    public void ReuseChunk(Chunk _chunk, intVector3 _position)
    {
        // intVector3 voxel_world_position = new intVector3(_x, _y, _z);//the coordinates of chunk in the world

        if (_chunk == null)
        {
            CreateChunk(_position.x, _position.y, _position.z);
        }

        _chunk.transform.position   = _position;
        _chunk.voxel_world_position = _position;

        _chunk.gameObject.SetActive(true);

        _chunk.voxel_world         = this;
        _chunk.transform.parent    = transform;
        _chunk.name                = "World Chunk";
        _chunk.gameObject.isStatic = true;

        chunks.Add(_position, _chunk);//store chunk in dictionary by its position
        _chunk = terrain_generator.GenerateChunk(_chunk);

        _chunk.SetVoxelsUnEdited();
        VoxelWorldSaver.Load(_chunk);
    }
Exemplo n.º 2
0
    public void CreateChunk(int _x, int _y, int _z)
    {
        intVector3 voxel_world_position = new intVector3(_x, _y, _z);//the coordinates of chunk in the world

        if (chunks.ContainsKey(voxel_world_position))
        {
            return;
        }

        GameObject chunk_object = Instantiate(chunk_prefab, new Vector3(voxel_world_position.x,
                                                                        voxel_world_position.y, voxel_world_position.z), Quaternion.Euler(Vector3.zero));//create chunk

        //set chunk parameters
        Chunk chunk = chunk_object.GetComponent <Chunk>();

        chunk.voxel_world_position = voxel_world_position;
        chunk.voxel_world          = this;
        chunk.transform.parent     = transform;
        chunk.name = "World Chunk";
        chunk.gameObject.isStatic = true;

        chunks.Add(voxel_world_position, chunk);//store chunk in dictionary by its position
        chunk = terrain_generator.GenerateChunk(chunk);

        chunk.SetVoxelsUnEdited();
        VoxelWorldSaver.Load(chunk);
    }
Exemplo n.º 3
0
 public void SaveWorld()
 {
     foreach (KeyValuePair <intVector3, Chunk> chunk in chunks)
     {
         VoxelWorldSaver.SaveChunk(chunk.Value);//save chunk
     }
 }
Exemplo n.º 4
0
    private void LoadExistingSaves()
    {
        string[] world_saves = VoxelWorldSaver.GetAllWorldSaves();

        foreach (string save in world_saves)
        {
            LoadWorldElement load_button = Instantiate(load_world_button, scroll_view_content.transform).GetComponent <LoadWorldElement>();
            load_button.WorldName = save;
        }
    }
Exemplo n.º 5
0
    public void DestroyChunk(int _x, int _y, int _z)
    {
        Chunk chunk = null;

        if (!chunks.TryGetValue(new intVector3(_x, _y, _z), out chunk))//if not in dictionary leave
        {
            return;
        }

        VoxelWorldSaver.SaveChunk(chunk);          //save chunk
        Destroy(chunk.gameObject);                 //destroy chunk
        chunks.Remove(new intVector3(_x, _y, _z)); //remove entry from dictionary
    }
Exemplo n.º 6
0
    public Chunk RemoveChunk(Chunk _chunk)
    {
        Chunk chunk = null;

        if (!chunks.TryGetValue(new intVector3(_chunk.voxel_world_position.x, _chunk.voxel_world_position.y, _chunk.voxel_world_position.z), out chunk))//if not in dictionary leave
        {
            return(null);
        }

        VoxelWorldSaver.SaveChunk(chunk);                                                                                           //save chunk
        chunks.Remove(new intVector3(_chunk.voxel_world_position.x, _chunk.voxel_world_position.y, _chunk.voxel_world_position.z)); //remove entry from dictionary

        chunk.gameObject.SetActive(false);
        chunk.ClearMeshData();
        chunk.edited   = false;
        chunk.rendered = false;
        return(chunk);
    }
Exemplo n.º 7
0
 public void DeleteWorld()
 {
     VoxelWorldSaver.DeleteSave(world_name);
     Destroy(this.gameObject);
 }