Exemplo n.º 1
0
 private void UpdateFinishAlign(int i, FieldScan fieldScan, FieldInput fieldInput, Vector2Int gamePosition)
 {
     fieldInput.phase        = EnumFieldInputPhase.None;
     fieldInput.swipeVec     = EnumSwipeVec.None;
     fieldInput.distPosition = Vector2Int.zero;
     fieldInputs[i]          = fieldInput;
 }
Exemplo n.º 2
0
 private void UpdateEnded(int i, FieldScan fieldScan, FieldInput fieldInput, Vector2Int gamePosition)
 {
     fieldInput.phase      = EnumFieldInputPhase.Align;
     fieldInput.alignVec   = GetAlignVec(fieldInput, fieldScan);
     fieldInput.alignDelta = GetAlignDelta(fieldInput.alignVec);
     fieldInput.isOnGrid   = CheckOnGrid(fieldInput.distPosition, fieldInput.swipeVec);
     // DebugPanel.Log($"fieldInput.alignVec", fieldInput.alignVec.ToString());
     // DebugPanel.Log($"fieldInput.alignDelta", fieldInput.alignDelta.ToString());
     fieldInputs[i] = fieldInput;
 }
Exemplo n.º 3
0
 private EnumPieceAlignVec GetAlignVec(FieldInput fieldInput, FieldScan fieldScan)
 {
     if ((Mathf.Abs(fieldScan.delta.x) > BorderSpeed && fieldInput.swipeVec == EnumSwipeVec.Horizontal) ||
         (Mathf.Abs(fieldScan.delta.y) > BorderSpeed && fieldInput.swipeVec == EnumSwipeVec.Vertical))
     {
         return(GetSlipAlignVec(fieldScan.delta, fieldInput.swipeVec));
     }
     else
     {
         return(GetBackAlignVec(fieldInput.distPosition, fieldInput.swipeVec));
     }
 }
Exemplo n.º 4
0
            private void UpdateAlign(int i, FieldScan fieldScan, FieldInput fieldInput, Vector2Int gamePosition)
            {
                Vector2Int newDistPosition = fieldInput.distPosition + fieldInput.alignDelta;

                if (CheckFinishAlign(fieldInput, newDistPosition))
                {
                    fieldInput.phase = EnumFieldInputPhase.FinishAlign;
                }

                fieldInput.distPosition = newDistPosition;
                fieldInput.isOnGrid     = CheckOnGrid(fieldInput.distPosition, fieldInput.swipeVec);
                fieldInputs[i]          = fieldInput;
            }
Exemplo n.º 5
0
            private void UpdateBegan(int i, FieldScan fieldScan, FieldInput fieldInput, Vector2Int gamePosition)
            {
                if (!CheckInfield(gamePosition))
                {
                    return;
                }

                fieldInput.phase         = EnumFieldInputPhase.Hold;
                fieldInput.gridPosition  = ConvertGridPosition(gamePosition);
                fieldInput.startPosition = gamePosition;
                fieldInput.swipeVec      = EnumSwipeVec.None;
                fieldInput.distPosition  = Vector2Int.zero;
                fieldInputs[i]           = fieldInput;
            }
Exemplo n.º 6
0
            private void UpdateMoved(int i, FieldScan fieldScan, FieldInput fieldInput, Vector2Int gamePosition)
            {
                if (fieldInput.phase != EnumFieldInputPhase.Hold)
                {
                    return;
                }

                Vector2 distPosition = (fieldScan.nowPosition - fieldScan.startPosition);

                DecideSwipeVec(ref fieldInput, distPosition);

                fieldInput.distPosition = new Vector2Int(
                    (int)(distPosition.x / PixelSize),
                    (int)(distPosition.y / PixelSize));
                fieldInput.isOnGrid = CheckOnGrid(fieldInput.distPosition, fieldInput.swipeVec);
                // DebugPanel.Log($"fieldInput.isOnGrid", fieldInput.isOnGrid.ToString());
                fieldInputs[i] = fieldInput;
            }
Exemplo n.º 7
0
        void Scan(ref FieldScan fieldScan)
        {
            TouchPhase phase = TouchPhase.Canceled;
            Vector2    pos   = Vector2.zero;

            if (Input.GetMouseButtonDown(0))
            {
                phase = TouchPhase.Began;
                pos   = (Vector2)Input.mousePosition;
            }
            else if (Input.GetMouseButton(0))
            {
                phase = TouchPhase.Moved;
                pos   = (Vector2)Input.mousePosition;
            }
            else if (Input.GetMouseButtonUp(0))
            {
                phase = TouchPhase.Ended;
                pos   = (Vector2)Input.mousePosition;
            }

            Vector2 lastPosition = fieldScan.nowPosition;
            Vector2 nowPosition  = pos + m_offset;

            fieldScan.phase       = phase;
            fieldScan.nowPosition = nowPosition;
            switch (phase)
            {
            case TouchPhase.Began:
                fieldScan.isTouch       = true;
                fieldScan.startPosition = nowPosition;
                break;

            case TouchPhase.Ended:
                fieldScan.isTouch = false;
                break;

            case TouchPhase.Moved:
                fieldScan.isTouch = true;
                fieldScan.delta   = nowPosition - lastPosition;
                break;
            }
        }