// builds Tetris playing grid according to the data specified in Grid class
    private void BuildGrid()
    {
        Transform parent = transform;
        Color     color  = Color.white;
        float     offset = Grid.offset;
        int       xCount = Grid.gridSize.x;
        int       yCount = Grid.gridSize.y;

        LoopUtil.LoopAction(
            (x, y)
            =>
        {
            GameObject square =
                SquareUtil.InstantiateAndSetUpSquare(parent, offset * new Vector2(x, y), color);
            if (Grid.HideBlock(y))
            {
                square.SetActive(false);
            }
        },
            xCount, yCount);
    }
Beispiel #2
0
    void Start()
    {
        Sprite[] sprites = Resources.LoadAll <Sprite>(atlasName);
        Debug.Log(sprites.Length);
        int spriteIndex = 0;

        foreach (Sprite sprite in sprites)
        {
            string name = sprite.name;
            Debug.Log(name);

            SpriteRenderer spriteRenderer;
            GameObject     go = SquareUtil.InstantiateSquare(out spriteRenderer, name);

            spriteRenderer.sprite = sprite;

            go.transform.parent        = transform;
            go.transform.localPosition = GridUtil.PositionFromIndex(spriteIndex, gridWidth);
            spriteIndex++;
        }
    }
Beispiel #3
0
 public override string ToString() => SquareUtil.SquareToString(this);
 private static void InstantiateCells(Transform parent, float offset, Vector2Int[] poses, Color color)
 {
     LoopUtil.LoopAction((i) => SquareUtil.InstantiateAndSetUpSquare(parent, offset * (Vector2)poses[i], color),
                         poses.Length);
 }