private void UndoInit()
 {
     Transform[] children = TransformUtil.GetChildren(transform);
     transform.DetachChildren();
     LoopUtil.LoopAction((i) => Destroy(children[i].gameObject), children.Length);
     inited = false;
 }
    private void SetColor(Tetramino.TetraminoType type)
    {
        int childCount;

        SpriteRenderer[] spriteRenderers =
            GetComponentUtil.GetComponentsInChildren <SpriteRenderer>(transform, out childCount);
        LoopUtil.LoopAction((i) => spriteRenderers[i].color = TetraminoUtil.Color(type), childCount);
    }
Пример #3
0
 public static void ApplyLocalPoses(Transform[] transforms, Vector2[] poses)
 {
     if (transforms.Length != poses.Length)
     {
         Debug.Log(transforms.Length + " : " + poses.Length);
         throw new System.Exception("transforms.Length != poses.Length");
     }
     LoopUtil.LoopAction((i) => transforms[i].localPosition = poses[i], transforms.Length);
 }
    public void SetOpacity(float opacity)
    {
        int childCount;

        SpriteRenderer[] spriteRenderers =
            GetComponentUtil.GetComponentsInChildren <SpriteRenderer>(transform, out childCount);
        LoopUtil.LoopAction((i) =>
                            spriteRenderers[i].color =
                                ColorUtil.ColorWithOpacity(spriteRenderers[i].color, opacity), childCount);
    }
Пример #5
0
    private void _UpdateBlocks()
    {
        var xCount = blocks.GetLength(0);
        var yCount = blocks.GetLength(1);

        LoopUtil.LoopAction((x, y) =>
        {
            blockGameObjects[x, y].SetActive(blocks[x, y] != null);
        }
                            , xCount, yCount);
    }
Пример #6
0
    // makes cells occupied by tetramino impassable
    public void FreezeTetraminoArea(TetraminoMono tetraminoMono)
    {
        Tetramino tetramino = tetraminoMono.tetramino;

        Vector2Int[] absPoses = tetramino.AbsPoses;
        LoopUtil.LoopAction((i) =>
        {
            this[absPoses[i]] =
                new WallBlock(BlockType.Unspecified, tetraminoMono.GetChildGameObject(i));
        }
                            , absPoses.Length);
        DisplayBlocks.UpdateBlocks();
    }
Пример #7
0
    void Start()
    {
        var xCount = blocks.GetLength(0);
        var yCount = blocks.GetLength(1);

        blockGameObjects = new GameObject[xCount, yCount];
        LoopUtil.LoopAction((x, y) =>
        {
            blockGameObjects[x, y] = Instantiate
                                         (prefab, new Vector2(x, y), Quaternion.identity, transform);
        }
                            , xCount, yCount);
        _UpdateBlocks();
    }
Пример #8
0
    public void Rotate(int rotationCount)
    {
        float sign = Mathf.Sign(rotationCount);
        int   abs  = Mathf.Abs(rotationCount);

        rotationCount = abs % 4;
        if (sign > 0)
        {
            LoopUtil.LoopAction((i) => RotateClockwise(), rotationCount);
        }
        else if (sign < 0)
        {
            LoopUtil.LoopAction((i) => RotateAntiClockwise(), rotationCount);
        }
    }
    // Start is called before the first frame update
    void Start()
    {
        PrintChildrenCount();
        var children = TransformUtil.GetChildren(transform);

        LoopUtil.LoopAction(
            (i) =>
        {
            children[i].parent = null;
            Destroy(children[i].gameObject);
        }, children.Length);
        PrintChildrenCount();
        LoopUtil.LoopAction((i) => new GameObject().transform.parent = transform, 1);
        PrintChildrenCount();
    }
Пример #10
0
    private void SetColor(Tetramino.TetraminoType type)
    {
        int childCount;

        SpriteRenderer[] spriteRenderers = GetSpriteRenderers(transform, out childCount);
        #region old version
        //for (int i = 0; i < 4; i++)
        //{
        //    Transform child = transform.GetChild(i);
        //    SpriteRenderer spriteRenderer = child.GetComponent<SpriteRenderer>();
        //    spriteRenderer.color = TetraminoUtil.Color(type);
        //}
        #endregion
        LoopUtil.LoopAction((i) => spriteRenderers[i].color = TetraminoUtil.Color(type), childCount);
    }
Пример #11
0
    void Start()
    {
        var xCount = blocks.GetLength(0);
        var yCount = blocks.GetLength(1);

        blockGameObjects = new GameObject[xCount, yCount];
        LoopUtil.LoopAction((x, y) =>
        {
            blockGameObjects[x, y] = Instantiate
                                         (prefab, new Vector2(x, y), Quaternion.identity, transform);
            if (blocks[x, y] == null)
            {
                blockGameObjects[x, y].SetActive(false);
            }
        }
                            , xCount, yCount);
    }
Пример #12
0
    // makes cells occupied by tetramino impassable
    public void FreezeTetraminoArea(TetraminoMono tetraminoMono)
    {
        //foreach (Vector2Int pos in )
        //{
        //    blocks[pos.x, pos.y] = new WallBlock(BlockType.Unspecified);
        //}
        Tetramino tetramino = tetraminoMono.tetramino;

        Vector2Int[] absPoses = tetramino.AbsPoses;
        LoopUtil.LoopAction((i) =>
        {
            blocks[absPoses[i].x, absPoses[i].y] =
                new WallBlock(BlockType.Unspecified, tetraminoMono.GetChildGameObject(i));
        }
                            , absPoses.Length);
        DisplayBlocks.UpdateBlocks();
    }
Пример #13
0
    public void SetOpacity(float opacity)
    {
        int childCount;

        SpriteRenderer[] spriteRenderers = GetSpriteRenderers(transform, out childCount);
        LoopUtil.LoopAction((i) =>
                            spriteRenderers[i].color =
                                ColorUtil.ColorWithOpacity(spriteRenderers[i].color, opacity), childCount);
        #region old version
        //for(int i = 0; i < 4; i++)
        //{
        //    Transform child = transform.GetChild(i);
        //    SpriteRenderer spriteRenderer = child.GetComponent<SpriteRenderer>();
        //    spriteRenderer.color = ColorUtil.ColorWithOpacity(spriteRenderer.color, opacity);
        //}
        #endregion
    }
Пример #14
0
    private void _UpdateBlocks()
    {
        var xCount = blocks.GetLength(0);
        var yCount = blocks.GetLength(1);

        LoopUtil.LoopAction((x, y) =>
        {
            if (blocks[x, y] == null)
            {
                blockGameObjects[x, y].SetActive(false);
            }
            else
            {
                blockGameObjects[x, y].SetActive(true);
            }
        }
                            , xCount, yCount);
    }
Пример #15
0
    // 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);
    }
Пример #16
0
 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);
 }