Ejemplo n.º 1
0
    // Gets called when ChunkGenerator needs information about it's Perlin Noise offset relevant to the game
    // Based on chunk position
    private ChunkPerlinOffsets GetPerlinOffset(Vector3 chunkGenerator)
    {
        ChunkPerlinOffsets newPerlinOffsets = new ChunkPerlinOffsets();

        newPerlinOffsets.chunkOffsetX = chunkPerlinOffsets.chunkOffsetX + chunkGenerator.x / chunkDistance;
        newPerlinOffsets.chunkOffsetZ = chunkPerlinOffsets.chunkOffsetZ + chunkGenerator.z / chunkDistance;
        return(newPerlinOffsets);
    }
Ejemplo n.º 2
0
 // Gets called only if the chunk is not loaded in saved data
 // Generation is delayed
 public IEnumerator GenerateChunk(ChunkPerlinOffsets chunkPerlinOffsets)
 {
     perlinOffsetX = chunkPerlinOffsets.chunkOffsetX;
     perlinOffsetZ = chunkPerlinOffsets.chunkOffsetZ;
     for (int x = 0; x < chunkHeight; x++)
     {
         for (int z = 0; z < chunkWidth; z++)
         {
             float columnHeight = GenerateHeight(x, z);
             for (int y = 0; y < columnHeight; y++)
             {
                 Vector3  newCubeLocation = transform.position + new Vector3(x, y, z) + generationOffset;
                 CubeType cubeType        = ProcessCubeType(y);
                 if (!cubeEditorTable.ContainsKey(newCubeLocation))
                 {
                     CreateCube(basicCubePrefab, newCubeLocation, cubeType);
                 }
             }
         }
         yield return(new WaitForSeconds(generationSeconds));
     }
     isLoaded = true;
 }