Beispiel #1
0
        public void AddVoxel(Pos pos, Color32 color)
        {
            Pos          chunkPos   = pos.ContainingChunkCoordinates(chunkSize);
            Pos          posInChunk = pos.ToLocalChunkCoordinates(chunkSize);
            TerrainChunk terrainChunk;

            Debug.LogFormat("[VoxelTerrain] chunkPos: {0}, posInChunk: {1}", chunkPos, posInChunk);

            if (!terrainChunks.TryGetValue(chunkPos, out terrainChunk))
            {
                GameObject chunkObj = Instantiate(
                    chunkPrefab,
                    chunkPos,
                    chunkPrefab.transform.rotation,
                    chunksHodler
                    );

                terrainChunk = chunkObj.GetComponent <TerrainChunk>();
                terrainChunk.Init(chunkSize);

                terrainChunks.Add(chunkPos, terrainChunk);
            }

            terrainChunk.SetVoxel(posInChunk, Voxel.Type.Solid, color);
        }
Beispiel #2
0
        // NOTE: could check if all voxels are air and remove it.
        public void RemoveVoxel(Pos pos)
        {
            Pos          chunkPos   = pos.ContainingChunkCoordinates(chunkSize);
            Pos          posInChunk = pos.ToLocalChunkCoordinates(chunkSize);
            TerrainChunk terrainChunk;

            Debug.LogFormat("[VoxelTerrain] chunkPos: {0}, posInChunk: {1}", chunkPos, posInChunk);

            if (terrainChunks.TryGetValue(chunkPos, out terrainChunk))
            {
                terrainChunk.SetVoxel(posInChunk, Voxel.Type.Air, Color.black);
            }
        }