예제 #1
0
    /*
     * Spawn the tile, set it up according to the Terrain parameters,
     * and parent it to the FarmTerrain for grouping purposes
     */
    private void SpawnGroundTileAtRowAndCol(Vector3 localOrigin, float row, float col)
    {
        // Tile edges should align with the terrain, not their centers, so we must shift them by their "radius"
        Vector3 TILE_OFFSET = new Vector3(GroundTile.SIZE_XZ / 2.0f, GroundTile.SIZE_Y / 2.0f, GroundTile.SIZE_XZ / 2.0f);
        // Convert row and column to local x and z coordinates
        Vector3 xyzPosition = new Vector3(row * GroundTile.SIZE_XZ, 0, col * GroundTile.SIZE_XZ);

        GameObject tile = (GameObject)Instantiate(groundTilePrefab,
                                                  (localOrigin + TILE_OFFSET + xyzPosition), Quaternion.identity);

        tile.transform.parent = transform;

        // Turn this tile into a grass or dirt tile based on settings
        GroundTile tileScript = tile.GetComponent <GroundTile> ();

        if (RBRandom.PercentageChance(grassPercent))
        {
            tileScript.SetState(GroundTile.GroundState.Grass);
            // Check if we should spawn a wildflower
            if (RBRandom.PercentageChance(wildflowerSpawnPercent))
            {
                SpawnWildFruitOnTile(tile);
            }
        }
        else
        {
            tileScript.SetState(GroundTile.GroundState.Dirt);
        }
    }