コード例 #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
    void SelectNextChild(bool right)
    {
        List <CardData> childCards = largeCard.GetCardData().GetChildCards();

        if (childCards.Count == 0)
        {
            return;
        }
        CardData cardData = largeCard.GetCardData();
        int      index    = cardData.ChildCardViewIndex;
        //If right move forward, if left go backward in list of child cards
        int inc = right ? 1 : -1;

        index += inc;
        //negative 1 defaults the image to the default one for the card
        if (index == childCards.Count)
        {
            index = -1;
        }
        else if (index < -1)
        {
            index = childCards.Count - 1;
        }
        cardData.ChildCardViewIndex = index;
        largeCard.UpdateCard();

        //Save card/duplicate card here
        //
    }
コード例 #3
0
    void Setup()
    {
        //Create duplicate cardData to work with and apply to card
        largeCard   = GetComponent <LargeCard>();
        dupCardData = largeCard.GetCardData().Duplicate();
        largeCard.SetCard(dupCardData);

        //Set individual field listeners
        FromField.onEndEdit.AddListener(SetFrom);
        PhoneticField.onEndEdit.AddListener(SetPhonetic);
        BrokenUpToField.onEndEdit.AddListener(SetBrokenUp);
        ToField.onEndEdit.AddListener(SetTo);

        //Set individual field pretext
        FromField.text       = dupCardData.From;
        PhoneticField.text   = dupCardData.PhoneticFrom;
        BrokenUpToField.text = dupCardData.BrokenUpTo;
        ToField.text         = dupCardData.To;


        List <TMP_InputField> fields = new List <TMP_InputField>()
        {
            FromField, PhoneticField, BrokenUpToField, ToField
        };

        UnityAction <string> finalizeAndUpdate = x =>
        {
            dupCardData.DataFinalize();
            largeCard.UpdateCard();
        };

        foreach (TMP_InputField field in fields)
        {
            field.onEndEdit.AddListener(finalizeAndUpdate);
        }
    }