Example #1
0
    void MoveCard()
    {
        if (gamepad.GetStick_L().X == 1)
        {
            //Get card indexes
            int cardIndex      = cardOrder.IndexOf(selectedCard);
            int otherCardIndex = cardIndex + 1;

            if (otherCardIndex == cardOrder.Count)
            {
                otherCardIndex = 0;
            }

            //Get other card
            CardBehaviour otherCard  = cardOrder[otherCardIndex];
            CardBehaviour middleCard = null;
            if (otherCardIndex == 0)
            {
                middleCard = cardOrder[1];
            }

            //Swap card positions
            selectedCard.Move(new Vector3(otherCard.transform.localPosition.x, selectedCard.offsetY, otherCard.transform.localPosition.z));

            if (middleCard != null)
            {
                otherCard.Move(new Vector3(middleCard.transform.localPosition.x, middleCard.originY, middleCard.transform.localPosition.z));
                middleCard.Move(new Vector3(selectedCard.transform.localPosition.x, selectedCard.originY, selectedCard.transform.localPosition.z));

                //Update card order
                cardOrder[1] = otherCard;
                cardOrder[otherCardIndex] = selectedCard;
                cardOrder[cardIndex]      = middleCard;
            }

            else
            {
                otherCard.Move(new Vector3(selectedCard.transform.localPosition.x, selectedCard.originY, selectedCard.transform.localPosition.z));

                //Update card order
                cardOrder[cardIndex]                = otherCard;
                cardOrder[otherCardIndex]           = selectedCard;
                cardOrder[cardIndex].cardIndex      = cardIndex;
                cardOrder[otherCardIndex].cardIndex = otherCardIndex;
            }

            //Input cooldown
            canChangeCards = false;
            StartCoroutine(HorizontalCooldown(selectedCard.moveTime));
        }

        if (gamepad.GetStick_L().X == -1)
        {
            //Get card indexes
            int cardIndex      = cardOrder.IndexOf(selectedCard);
            int otherCardIndex = cardIndex - 1;

            if (otherCardIndex < 0)
            {
                otherCardIndex = cardOrder.Count - 1;
            }

            //Get other card
            CardBehaviour otherCard  = cardOrder[otherCardIndex];
            CardBehaviour middleCard = null;
            if (otherCardIndex == cardOrder.Count - 1)
            {
                middleCard = cardOrder[1];
            }

            //Swap card positions
            selectedCard.Move(new Vector3(otherCard.transform.localPosition.x, selectedCard.offsetY, otherCard.transform.localPosition.z));

            if (middleCard != null)
            {
                otherCard.Move(new Vector3(middleCard.transform.localPosition.x, middleCard.originY, middleCard.transform.localPosition.z));
                middleCard.Move(new Vector3(selectedCard.transform.localPosition.x, selectedCard.originY, selectedCard.transform.localPosition.z));

                //Update card order
                cardOrder[1] = otherCard;
                cardOrder[otherCardIndex] = selectedCard;
                cardOrder[cardIndex]      = middleCard;
            }

            else
            {
                otherCard.Move(new Vector3(selectedCard.transform.localPosition.x, selectedCard.originY, selectedCard.transform.localPosition.z));

                //Update card order
                cardOrder[cardIndex]                = otherCard;
                cardOrder[otherCardIndex]           = selectedCard;
                cardOrder[cardIndex].cardIndex      = cardIndex;
                cardOrder[otherCardIndex].cardIndex = otherCardIndex;
            }

            //Input cooldown
            canChangeCards = false;
            StartCoroutine(HorizontalCooldown(selectedCard.moveTime));
        }
    }