Example #1
0
    private void generateDoodad(Doodad doodad, Vector3 pos)
    {
        doodad.initialize();
        int availableHeight = 0;

        while ((pos.z + availableHeight < size.z) && !terrainTrack[offsetX % Mathf.RoundToInt(size.x), Mathf.RoundToInt(pos.z + availableHeight)])
        {
            availableHeight++;
        }

        if (doodad.foreground && (pos.z > 0))
        {
            return;
        }
        else if (doodad.underground && (pos.z > 0))
        {
            return;
        }
        else if (pos.z == 0)
        {
            return;
        }

        float   scale      = doodad.getRandomScale();
        Vector2 doodadSize = doodad.getSizeAtScale(scale);

        if (doodadSize.y <= availableHeight)
        {
            instantiateA(doodad, pos, scale);

            for (int width = 0; width < size.x; width++)
            {
                for (int height = 0; height < doodadSize.y; height++)
                {
                    terrainTrack[(offsetX + width) % Mathf.RoundToInt(size.x), Mathf.RoundToInt(pos.z + height)] = width < doodadSize.x;
                }
            }
        }
    }