Ejemplo n.º 1
0
    // Generates the features to be instantiated as children of the chunk
    void GenerateChunkPopulation()
    {
        float[,] chunkFeatureMap = world.featureGenerator.GenerateObjectNutrientsMap(world.chunkSize, world.chunkSize, chunkPos);

        for (int chunkTileY = 0; chunkTileY < world.chunkSize; chunkTileY++)
        {
            for (int chunkTileX = 0; chunkTileX < world.chunkSize; chunkTileX++)
            {
                SpawnableFeature spawnableFeature = world.featureGenerator.getSpawnableFeature(chunkFeatureMap[chunkTileX, chunkTileY], chunkBiomeLayers[chunkTileX, chunkTileY], (chunkPos * world.chunkSize) + new Vector2Int(chunkTileX, chunkTileY));

                chunkSpawnableFeatures[chunkTileX, chunkTileY] = spawnableFeature;
            }
        }
    }
Ejemplo n.º 2
0
    // Populates the chunk with features
    void PopulateChunk()
    {
        float chunkWorldSpaceInterval = (float)(world.chunkSize * world.tileSize) / 100;
        float featureSpaceInterval = chunkWorldSpaceInterval / (float)world.chunkSize;

        for (int chunkTileY = 0; chunkTileY < world.chunkSize; chunkTileY++)
        {
            for (int chunkTileX = 0; chunkTileX < world.chunkSize; chunkTileX++)
            {
                SpawnableFeature chunkSpawnableFeature = chunkSpawnableFeatures[chunkTileX, chunkTileY];

                if (chunkSpawnableFeature != null)
                {
                    Vector2Int worldPos = (chunkPos * 16) + new Vector2Int(chunkTileX, chunkTileY);

                    float rndXOffset = Random.Range(-chunkSpawnableFeature.randomOffset, chunkSpawnableFeature.randomOffset);
                    float rndYOffset = Random.Range(-chunkSpawnableFeature.randomOffset, chunkSpawnableFeature.randomOffset);

                    GameObject tileObject = Instantiate(chunkSpawnableFeature.feature.gameObject, Vector2.zero, Quaternion.identity, transform); // Spawning the object in the chunk
                    tileObject.transform.localPosition = new Vector2(chunkTileX + rndXOffset + 0.5f, chunkTileY + rndYOffset + 0.5f) * featureSpaceInterval; // The +0.5 is performed to centre the feature to the centre of the tile
                }
            }
        }
    }