michalczemierowski / Unity--voxel-terrain-generator

3D game with procedural world made of cubes. (world generation/mesh creation/physx baking is multi threaded)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Voxel Terrain Generator

Unity Version: 2020.1.6f1

Features:

  • Procedurally generated terrain
  • Daylight cycle
  • Biomes with different grass colors
  • Terrain modification
  • Multithreading
  • Loading assets using Unity Addressable Asset System
  • Saving/Loading terrain
  • Items, tools, weapons
  • Menu, async scene loading
  • Inventory system
  • Living entities (early stage of development)

Screenshots:

Screenshot 0 Screenshot 0 Screenshot 0

Code examples

Easy to configure event listeners

IBlockUpdateListener - called when neighbour block is placed/removed

public class OnGrassBlockUpdate : MonoBehaviour, IBlockUpdateListener
{
    public BlockType GetBlockType()
    {
	    // Block type you want to listen for updates
        return BlockType.GRASS_BLOCK;
    }

    public void OnBlockUpdate(BlockEventData data, Dictionary<BlockFace, BlockEventData> neighbours, params int[] args)
    {
        // if above block is solid block
        if (WorldData.GetBlockState(neighbours[BlockFace.TOP].type) == BlockState.SOLID)
        {
            // replace current block with dirt in next update
            data.chunk.AddBlockToBuildList(data.position, BlockType.DIRT);
        }
    }
}

IBlockArrayDestroyListener - called when block is removed

public class OnAnyDestroy : MonoBehaviour, IBlockArrayDestroyListener
{
    public BlockType[] GetBlockTypes()
    {
        // register this event listener to all blocks
        return Utils.GetAllBlockTypes();
    }

    public void OnBlockDestroy(BlockEventData data, params int[] args)
    {
        BlockType type = data.blockType == BlockType.GRASS_BLOCK ? BlockType.DIRT : data.blockType;
        // instantiate particle at block position
        ParticleManager.InstantiateBlockDestroyParticle(ParticleType.BLOCK_DESTROY_PARTICLE, data.WorldPosition, type);
    }
}

About

3D game with procedural world made of cubes. (world generation/mesh creation/physx baking is multi threaded)

License:GNU General Public License v3.0


Languages

Language:C# 86.6%Language:ShaderLab 11.7%Language:HLSL 1.6%