Пример #1
0
    public void PopulateGround()
    {
        Column lastCreatedColumn = null;

        for (int i = 0; i < groundWidth; i++)
        {
            columns [i].indexInColumnsList = i;
            GroundPiece lastSpawnedPiece = null;

            for (int i2 = 0; i2 < groundHeight; i2++)
            {
                GroundPiece newGroundPiece = (GroundPiece)Instantiate(seedGroundPiece);
                columns [i].groundPieces.Add(newGroundPiece);

                rows [i2].groundPieces.Add(newGroundPiece);
                rows [i2].indexInRowsList = i2;

                Vector3 newPos = newGroundPiece.transform.position;

                if (lastSpawnedPiece != null)
                {
                    newPos.y = lastSpawnedPiece.transform.position.y - lastSpawnedPiece.bounds().size.y;
                }

                if (lastCreatedColumn != null)
                {
                    newPos.x = lastCreatedColumn.groundPieces [0].transform.position.x + lastCreatedColumn.groundPieces [0].bounds().size.x;
                }

                newGroundPiece.transform.position = newPos;
                newGroundPiece.transform.SetParent(transform);

                newGroundPiece.column        = columns [i];
                newGroundPiece.indexInColumn = i2;

                newGroundPiece.row        = rows [i2];
                newGroundPiece.indexInRow = i;

                //		if (i == 0 && i == groundWidth - 1)
                //			newGroundPiece.groundRotationAngle = 0;

                spawnedGroundPieces.Add(newGroundPiece);

                newGroundPiece.indexInGrid = spawnedGroundPieces.Count - 1;
                lastSpawnedPiece           = newGroundPiece;

                if (i > 5 && i < groundWidth - 5 && i2 > 5 && i2 < groundHeight - 5)
                {
                    groundPiecesWhereSnakesCanSpawn.Add(newGroundPiece);
                }
            }

            lastCreatedColumn = columns [i];
        }
    }