Example #1
0
        public void RotateCard(CardRotation cardRotation)
        {
            CardEdge[] currentCardEdges = new CardEdge[] { EdgeNorth, EdgeEast, EdgeSouth, EdgeWest };
            CardEdge[] newCardEdges     = new CardEdge[4];

            int currentRotation = (int)RotationState;
            int newRotation     = (int)cardRotation;

            int diffRotation = newRotation - currentRotation;

            diffRotation = (diffRotation < 0) ? 4 + diffRotation : diffRotation;

            if (diffRotation == 0)
            {
                return;
            }

            //Console.WriteLine("Diffrot = {0}", diffRotation);
            for (int i = 0; i < 4; i++)
            {
                int currentIndex = (i + diffRotation) % 4;
                newCardEdges[currentIndex] = currentCardEdges[i];
                //Console.WriteLine("{0} -> {1}", i, currentIndex);
            }
            EdgeNorth = newCardEdges[0];
            EdgeEast  = newCardEdges[1];
            EdgeSouth = newCardEdges[2];
            EdgeWest  = newCardEdges[3];

            RotateMask(diffRotation);
        }
    public void Bent(List<GameObject> cards, Transform parent)
    {
        if (cards == null || cards.Count < 1)
            return;

        var fullAngle = -bentAngle;
        var anglePerCard = fullAngle / cards.Count;
        var firstAngle = Utilities.CalcFirstAngle(fullAngle);
        //var handWidth = CalcHandWidth(cards.Count);
        var handWidth = Utilities.CalcAreaWidth(cards.Count, cardWidth, spacing);

        var offsetX = pivot.position.x - handWidth / 2;

        for (var i = 0; i < cards.Count; i++ )
        {
            var card = cards[i];

           

            var angleTwist = firstAngle + i * anglePerCard;
            var xPos = offsetX + cardWidth / 2;
            var yDistance = Mathf.Abs(angleTwist) * height;
            var yPos = pivot.position.y - yDistance;
            var rotation = new Vector3(0, 0, angleTwist);
            var position = new Vector3(xPos, yPos, card.transform.position.z);
            //card.transform.position = position;
            card.transform.rotation = Quaternion.Euler(rotation.x, rotation.y, rotation.z);
            CardRotation cardRotation = card.transform.GetComponent<CardRotation>();
            if (cardRotation.cardState == Enums.CardState.FaceDown)
            {
                cardRotation.cardState = Enums.CardState.FaceUp;
                if (cardRotation.CardStateChangeDone)
                    cardRotation.CardStateChangeDone = false;
                cardRotation.Flip();
            }
            cardRotation.cardFront.transform.rotation = Quaternion.Euler(
                       rotation.x,
                       0,
                       rotation.z
                   );

            //if (cardRotation.cardFront.transform.rotation.eulerAngles.y == 180 || card.transform.rotation.eulerAngles.y == -180)
            //{
            //    cardRotation.cardFront.transform.rotation = Quaternion.Euler(
            //            rotation.x,
            //            0,
            //            rotation.z
            //        );
            //}

            card.transform.DOMove(position, 0.5f).SetEase(Ease.OutQuint).OnComplete(() => {
                VisualsEvents.current.UpdateDraggableOriginalPosition(card, -1f, -1f);
            });
            card.transform.SetParent(parent, false);
            card.SetCardLocation(Enums.CardLocation.HandArea);
            offsetX += cardWidth + spacing;

        }
    }
        private static string GetDescription(CardRotation rotation)
        {
            Type type = rotation.GetType();

            MemberInfo[] memInfo = type.GetMember(type.ToString());

            if (memInfo != null && memInfo.Length > 0)
            {
                object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (attrs != null && attrs.Length > 0)
                {
                    return(((DescriptionAttribute)attrs[0]).Description);
                }
            }

            return(rotation.ToString());
        }
    public static void StartRotation(this GameObject gameObject, Enums.CardState cardState)
    {
        CardRotation cardRotation = gameObject.transform.GetComponent <CardRotation>();

        if (cardRotation != null)
        {
            if (cardRotation.cardState == Enums.CardState.FaceDown && cardState == Enums.CardState.FaceUp && gameObject.GetCardAsset().LocationOfCard == Enums.CardLocation.Deck)
            {
                cardRotation.FromDeckStartFaceUp();
            }
            if (cardRotation.cardState == Enums.CardState.FaceUp && cardState == Enums.CardState.FaceDown)
            {
                cardRotation.StartFaceDown();
            }
            if (cardRotation.cardState == Enums.CardState.FaceDown && cardState == Enums.CardState.FaceUp)
            {
                cardRotation.StartFaceUp();
            }
        }
    }
Example #5
0
    public GameObject GetCard(int cardId)
    {
        Card findCard = GetCardsFromResource().Where(w => w.CardId == cardId).FirstOrDefault();

        card = GetTypeOfCard(findCard);
        var cardDisplay        = card.GetComponent <CardDisplay>();
        var cardPreview        = card.transform.Find("CardPreview");
        var cardPreviewDisplay = cardPreview.GetComponent <CardPreviewDisplay>();
        var canvas             = card.transform.Find("Canvas");
        var cardArt            = canvas.transform.Find("ArtCard");
        ArtCardPreviewDisplay cardArtPreviewDisplay = null;

        if (cardArt != null)
        {
            cardArtPreviewDisplay = cardArt.GetComponent <ArtCardPreviewDisplay>();
        }


        if (findCard != null)
        {
            cardDisplay.card        = findCard;
            cardPreviewDisplay.card = findCard;
            if (cardArtPreviewDisplay != null)
            {
                cardArtPreviewDisplay.card = findCard;
            }
            GameObject singleCard = Instantiate(card, new Vector3(0, 0, -0.01f), Quaternion.identity);

            CardRotation cardRotation = singleCard.transform.GetComponent <CardRotation>();
            cardRotation.cardState = Enums.CardState.FaceDown;
            cardRotation.Flip();


            return(singleCard);
        }
        return(null);
    }