예제 #1
0
    void PopulateLayout()
    {
        List <CardData> baseCards = cardFocused.GetChildCardsOfType(CardType);

        //Create card pairs
        foreach (CardData card in baseCards)
        {
            GameObject goFront = GameObject.Instantiate(CardPrefab, transform);
            GameObject goBack  = GameObject.Instantiate(CardPrefab, transform);

            LargeCard lCardFront = goFront.GetComponent <LargeCard>();
            LargeCard lCardBack  = goBack.GetComponent <LargeCard>();

            lCardFront.SetCard(card, false);
            lCardBack.SetCard(card, false);

            //Remember the card showing the front will hide the back and vice versa
            lCardFront.hideType = LargeCard.HideType.HideBack;
            lCardBack.hideType  = LargeCard.HideType.HideFront;

            //Flip cards that are on the back
            lCardFront.FlipDirection(false);

            lCardFront.UpdateCard();
            lCardBack.UpdateCard();
        }

        //Take all cards out of transform, temporarily add to parent transform and then sort back in randomly
        List <Transform> childTransforms = new List <Transform>();

        foreach (Transform child in transform)
        {
            //So cards can be tapped and still dragged
            GameObject go = child.gameObject;
            go.AddComponent <DragPassthrough>();

            //Add click events
            EventTrigger       trigger = go.GetComponent <EventTrigger>();
            EventTrigger.Entry entry   = new EventTrigger.Entry();
            entry.eventID = EventTriggerType.PointerClick;
            entry.callback.AddListener((data) => { TappedCard((PointerEventData)data); });
            trigger.triggers.Add(entry);

            //Add to list of transforms to perform shuffle
            childTransforms.Add(child);
        }
        //Remove children to be added later
        transform.DetachChildren();

        //Shuffle list
        childTransforms.ShuffleInPlace();

        //Add list back into transform
        foreach (Transform child in childTransforms)
        {
            child.SetParent(transform);
        }

        SetFlippingChildren(true);
    }
예제 #2
0
 /// <summary>
 /// Forces cards to spin to hidden if not in the ignoreSet
 /// </summary>
 void ForceCardsOver()
 {
     foreach (Transform child in transform)
     {
         if (ignoreSet.Contains(child))
         {
             continue;
         }
         LargeCard lCard = child.GetComponent <LargeCard>();
         if (!lCard.IsHidden())
         {
             lCard.FlipDirection();
         }
     }
 }