Exemple #1
0
    private void OnBeginDrag()
    {
        //Wait for end of swap
        if (swiping || MovementAnimationSystem.IsAnimatingSomeObject() || GameplayController.Gameplay.InputBlocked)
        {
            return;
        }

        mouseBeginPositon = Input.mousePosition;

        Vector3 screenToWorldPoint = Camera.main.ScreenToWorldPoint(mouseBeginPositon);
        Vector3 mousePosition      = new Vector3(screenToWorldPoint.x, screenToWorldPoint.y, 0);

        //Check if and which item has been swiped
        foreach (SpriteRenderer spriteRenderer in spriteRenderers)
        {
            if (spriteRenderer.bounds.Contains(mousePosition))
            {
                swipedItem = lastSwipedItem = spriteRenderer.GetComponent <GridItem>();
            }
        }
    }
Exemple #2
0
    private void OnDrag()
    {
        //Wait for end of swap
        if (swiping || swipedItem == null || GameplayController.Gameplay.InputBlocked || MovementAnimationSystem.IsAnimatingSomeObject())
        {
            return;
        }

        mouseCurrentPosition          = Input.mousePosition;
        mouseDistanceBetweenPositions = mouseCurrentPosition - mouseBeginPositon;

        //Mouse move must overcome a certain distance to allow swap
        if (Mathf.Abs(mouseDistanceBetweenPositions.x) < deadZone && Mathf.Abs(mouseDistanceBetweenPositions.y) < deadZone)
        {
            return;
        }

        dragDirection = GetDirtection(mouseDistanceBetweenPositions);
        swipedItem.Move(dragDirection);

        swiping = true;
    }