Ejemplo n.º 1
0
        /**
         * @brief コンストラクタ
         */
        public Grid(Vector3 vec)
        {
            // 原点(右上)の座標を計算する
            Vector3 origin = (new Vector2(Board.Size.col / 2f, Board.Size.row / 2f) * Board.gridSize) - (new Vector2(Board.gridSize / 2f, Board.gridSize / 2f));

            vec = (-vec + origin + (Vector3)(CanvasAdapter.rectTransform.sizeDelta / 2f)) / Board.gridSize;

            this = new Grid(Mathf.RoundToInt(vec.y), Mathf.RoundToInt(vec.x), vec.z);
        }
Ejemplo n.º 2
0
        protected void Update()
        {
            if (Input.GetMouseButtonDown(0) && holdPiece == null)
            {
                Debug.Log("a");
                Grid mouseGrid = new Grid(Input.mousePosition);

                if (mouseGrid.row >= 0 && mouseGrid.row < Board.Size.row &&
                    mouseGrid.col >= 0 && mouseGrid.col < Board.Size.col)
                {
                    if (pieces[mouseGrid.row, mouseGrid.col] != null)
                    {
                        holdPiece = new HoldPiece();

                        holdPiece.grid = mouseGrid;
                    }
                }
            }

            if (Input.GetMouseButton(0) && holdPiece != null)
            {
                Debug.Log("b");
                pieces[holdPiece.grid.row, holdPiece.grid.col].position = Input.mousePosition + new Vector3(-Board.gridSize / 2f, Board.gridSize / 2f);

                holdPiece.index = pieces[holdPiece.grid.row, holdPiece.grid.col].rectTransform.GetSiblingIndex();
                pieces[holdPiece.grid.row, holdPiece.grid.col].rectTransform.SetAsLastSibling();
            }

            if (Input.GetMouseButtonUp(0) && holdPiece != null)
            {
                Debug.Log("c");
                Grid mouseGrid = new Grid(Input.mousePosition);
                pieces[holdPiece.grid.row, holdPiece.grid.col].grid = mouseGrid;
                pieces[holdPiece.grid.row, holdPiece.grid.col].rectTransform.SetSiblingIndex(holdPiece.index);

                if (holdPiece.grid != mouseGrid)
                {
                    pieces[mouseGrid.row, mouseGrid.col] = pieces[holdPiece.grid.row, holdPiece.grid.col];
                    pieces[holdPiece.grid.row, holdPiece.grid.col] = null;
                }

                holdPiece = null;
            }
        }