Ejemplo n.º 1
0
    public void GenerateTerrain(float leadAmount)
    {
        //Track the right and left sides of the screen so we know how much terrain to generate
        Vector3 rightSide = Camera.main.ViewportToWorldPoint(new Vector3(1, 0, -Camera.main.transform.position.z));
        Vector3 leftSide  = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, -Camera.main.transform.position.z));
        float   endX      = rightSide.x + leadAmount;

        while (TerrainManager.VertexGen.CurrentTerrainRule != null && TerrainManager.GetFarthestX() < endX)
        {
            TerrainManager.Generate(endX);
            //Update our prefabs with the current terrain info
            PrefabManager.PlacePrefabs(TerrainManager);

            TerrainManager.Cleanup(leftSide.x - leadAmount);
            PrefabManager.Cleanup(leftSide.x - leadAmount);
        }

        //Only need this when we are no longer generating any new terrain but still need to do the final object cleanup
        if (TerrainManager.VertexGen.CurrentTerrainRule == null && TerrainManager.Pool != null && TerrainManager.Pool.TerrainPieces.Count > 0)
        {
            TerrainManager.Cleanup(leftSide.x);
            PrefabManager.Cleanup(leftSide.x);
        }
    }