コード例 #1
0
    void CheckUserInput()
    {
        time = time + Time.deltaTime;
        //holds

        /*if (Input.GetKeyDown(KeyCode.RightShift)
        || Input.GetKeyDown(KeyCode.LeftShift)
        ||  && FindObjectOfType<Game>().GetHoldTime())
        || {
        ||  enabled = false;
        ||  FindObjectOfType<Game>().SetNull(this);
        ||  transform.rotation = Quaternion.identity;
        ||  transform.position = FindObjectOfType<Game>().transform.position + 6 * Vector3.right + 9 * Vector3.up;
        ||  if (!FindObjectOfType<Game>().GetHold())
        ||  {
        ||      FindObjectOfType<Game>().SetHold(this);
        ||      FindObjectOfType<Spawner>().SpawnNext();
        ||  }
        ||  else
        ||  {
        ||      Tetromino t = FindObjectOfType<Game>().GetHoldTetromino();
        ||      t.enabled = true;
        ||      FindObjectOfType<Game>().SetHold(this);
        ||      if (t.whereSpawn)
        ||      {
        ||          t.transform.position += 38 * Vector3.up / 4
        + 9 * Vector3.right / 4 + Vector3.down / 4;
        +       }
        +       else
        +       {
        +           t.transform.position = 38 * Vector3.up / 4
        + 9 * Vector3.right / 4 + Vector3.left / 4;
        +       }
        +   }
        +   FindObjectOfType<Game>().SetHoldTime(false);
        +  }*/
        //go right (joystick right)
        if (MinigameInputHelper.GetHorizontalAxis(2) > 0 && time > nextMove)
        {
            nextMove            = time + nextMoveDelta;
            transform.position += Vector3.right / 2;
            if (!CheckIsValidPosition())
            {
                transform.position += Vector3.left / 2;
            }
            else
            {
                FindObjectOfType <Game_2>().UpdateGrid(this);
            }
            nextMove = nextMove - time;
            time     = 0.0F;
        }
        //go left (joystick left)
        else if (MinigameInputHelper.GetHorizontalAxis(2) < 0 && time > nextMove)
        {
            nextMove            = time + nextMoveDelta;
            transform.position += Vector3.left / 2;
            if (!CheckIsValidPosition())
            {
                transform.position += Vector3.right / 2;
            }
            else
            {
                FindObjectOfType <Game_2>().UpdateGrid(this);
            }
            nextMove = nextMove - time;
            time     = 0.0F;
        }
        //rotate (joystick up)
        else if (isVerticalReset && MinigameInputHelper.GetVerticalAxis(2) > 0)
        {
            transform.Rotate(0, 0, -90);
            foreach (Transform mino in transform)
            {
                mino.Rotate(0, 0, -90);
            }
            if (!CheckIsValidPosition())
            {
                transform.Rotate(0, 0, 90);
                foreach (Transform mino in transform)
                {
                    mino.Rotate(0, 0, 90);
                }
            }
            else
            {
                FindObjectOfType <Game_2>().UpdateGrid(this);
            }
        }
        //rotate other direction (other button)
        else if (MinigameInputHelper.IsButton2Down(2))
        {
            transform.Rotate(0, 0, 90);
            foreach (Transform mino in transform)
            {
                mino.Rotate(0, 0, 90);
            }
            if (!CheckIsValidPosition())
            {
                transform.Rotate(0, 0, -90);
                foreach (Transform mino in transform)
                {
                    mino.Rotate(0, 0, -90);
                }
            }
            else
            {
                FindObjectOfType <Game_2>().UpdateGrid(this);
            }
        }
        //hard drop (other button)
        else if (MinigameInputHelper.IsButton1Down(2))
        {
            while (CheckIsValidPosition())
            {
                transform.position += Vector3.down / 2;
            }
            transform.position += Vector3.up / 2;
            FindObjectOfType <Game_2>().UpdateGrid(this);
            enabled = false;

            FindObjectOfType <Game_2>().DecreaseAboveRows();

            FindObjectOfType <Spawner_2>().SpawnNext();
        }
        //go down (joystick down)
        else if (((MinigameInputHelper.GetVerticalAxis(2) < 0) || Time.time - fallTime >= fallSpeed) && time > nextMove)
        {
            nextMove            = time + nextMoveDelta;
            transform.position += Vector3.down / 2;
            fallTime            = Time.time;
            if (!CheckIsValidPosition())
            {
                transform.position += Vector3.up / 2;
                enabled             = false;
                FindObjectOfType <Game_2>().UpdateGrid(this);

                FindObjectOfType <Game_2>().DecreaseAboveRows();

                FindObjectOfType <Spawner_2>().SpawnNext();
                //FindObjectOfType<Spawner>().SpawnPreview();
            }
            else
            {
                FindObjectOfType <Game_2>().UpdateGrid(this);
            }
            nextMove = nextMove - time;
            time     = 0.0F;
        }

        isVerticalReset = !MinigameInputHelper.IsVerticalAxisInUse(2);
    }