コード例 #1
0
ファイル: BoardCreator.cs プロジェクト: WeArePawns/Articoding
    private void ManageInput()
    {
        //Save the current board
        if (Input.GetKeyDown(KeyCode.G))
        {
            SaveBoard();
        }
        else if (Input.GetKeyDown(KeyCode.Return))
        {
            BoardCell cell = board.GetBoardCell(cursorPos.x, cursorPos.y);
            if (cell != null)
            {
                //Select a new object
                if (selectedPos == -Vector2Int.one && cell.GetState() == BoardCell.BoardCellState.OCUPPIED)
                {
                    selectedPos    = cursorPos;
                    material.color = Color.blue;

                    selectedIndicator = Instantiate(indicatorPrefab, transform.parent);
                    selectedIndicator.transform.localPosition = new Vector3(cursorPos.x + offset.x, cursorPos.y + offset.y, 0);
                }
                //Move object to cursor
                else if (selectedPos != -Vector2Int.one)
                {
                    board.MoveBoardObject(selectedPos, cursorPos);
                    selectedPos = cursorPos;
                    if (selectedIndicator != null)
                    {
                        selectedIndicator.transform.localPosition = new Vector3(cursorPos.x + offset.x, cursorPos.y + offset.y, 0);
                    }
                }
            }
        }
        //Rotate the selectedObject E clockwise Q anti-clockwise
        else if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.Q))
        {
            if (selectedPos != -Vector2Int.one)
            {
                board.RotateBoardObject(selectedPos, Input.GetKeyDown(KeyCode.E) ? 1 : -1);
            }
        }

        //Deselect the current object
        else if (Input.GetKeyDown(KeyCode.Backspace))
        {
            DeselectObject();
        }
        //Delete the selected object
        else if (Input.GetKeyDown(KeyCode.X))
        {
            if (selectedPos != -Vector2Int.one)
            {
                board.RemoveBoardObject(selectedPos.x, selectedPos.y);
                DeselectObject();
            }
            else if (board.HasHint(cursorPos))
            {
                board.DeleteHint(cursorPos, 0);
            }
        }
        //Create new elements
        else if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            AddObject(0);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            AddObject(1);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            AddObject(2);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            AddObject(3);
        }
        else if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            AddObject(4);
        }
        //Create new cell types
        else if (Input.GetKeyDown(KeyCode.Keypad1))
        {
            ReplaceCell(0, cursorPos.x, cursorPos.y);
        }
        else if (Input.GetKeyDown(KeyCode.Keypad2))
        {
            ReplaceCell(1, cursorPos.x, cursorPos.y);
        }
        else if (Input.GetKeyDown(KeyCode.Keypad3))
        {
            ReplaceCell(2, cursorPos.x, cursorPos.y);
        }
        else if (Input.GetKeyDown(KeyCode.Keypad4))
        {
            ReplaceCell(3, cursorPos.x, cursorPos.y);
        }
        else if (Input.GetKeyDown(KeyCode.Keypad5))
        {
            ReplaceCell(4, cursorPos.x, cursorPos.y);
        }
        //Add hints
        else if (Input.GetKeyDown(KeyCode.J))
        {
            board.AddBoardHint(cursorPos, 1, 0);
        }
        else if (Input.GetKeyDown(KeyCode.K))
        {
            board.AddBoardHint(cursorPos, 1, 1);
        }
        else if (Input.GetKeyDown(KeyCode.L))
        {
            board.AddBoardHint(cursorPos, 1, 2);
        }
        //Rotate Hints
        else if (Input.GetKeyDown(KeyCode.U))
        {
            board.RotateHint(cursorPos, 1, 0);
        }
        else if (Input.GetKeyDown(KeyCode.I))
        {
            board.RotateHint(cursorPos, 1, 1);
        }
        else if (Input.GetKeyDown(KeyCode.O))
        {
            board.RotateHint(cursorPos, 1, 2);
        }
    }