示例#1
0
    void Rotate(bool clockwise)
    {
        Rect r = selectionRect.GetSelectionRect();
        int  left = Mathf.RoundToInt(r.xMin), top = Mathf.RoundToInt(r.yMin),
             right = Mathf.RoundToInt(r.xMax), bottom = Mathf.RoundToInt(r.yMax);

        if (leftGrid.CanRotate(left, top, right, bottom) == false)
        {
            return;
        }

        isAnimating = true;
        System.Action done = () => {
            animator.RewindTweens();    // reset the tweens
            leftGrid.Rotate(left, top, right, bottom, clockwise);
            gridUpdated.Fire();
            this.isAnimating = false;   // animating end
            CheckForFalling();
        };

        if (clockwise)
        {
            // special case LT
            animator.AddTween(left, top, Vector3.right, false, done);
            for (int x = left + 1; x < right; x++)  // top row right (not LT)
            {
                animator.AddTween(x, top, Vector3.right);
            }
            for (int y = top; y < bottom; y++)  // right col down
            {
                animator.AddTween(right, y, Vector3.down);
            }
            for (int x = left + 1; x <= right; x++)  // bottom row left (not LB, inc RB)
            {
                animator.AddTween(x, bottom, Vector3.left);
            }
            for (int y = top + 1; y <= bottom; y++)  // left col up (not LT, inc LB)
            {
                animator.AddTween(left, y, Vector3.up);
            }
        }
        else
        {
            // special case LT
            animator.AddTween(left, top, Vector3.down, false, done);
            for (int x = left + 1; x <= right; x++)  // top row left (not LT)
            {
                animator.AddTween(x, top, Vector3.left);
            }
            for (int y = top + 1; y <= bottom; y++)  // right col up (not RT, inc RB)
            {
                animator.AddTween(right, y, Vector3.up);
            }
            for (int x = left; x < right; x++)  // bottom row left (not RB, inc LB)
            {
                animator.AddTween(x, bottom, Vector3.right);
            }
            for (int y = top + 1; y < bottom; y++)  // left col down (not LT, not LB)
            {
                animator.AddTween(left, y, Vector3.down);
            }
        }
    }