Example #1
0
    bool TryPickupCard(Collider2D c)
    {
        if (holding == null && buttonFixedPressed)
        {
            CardPickup card = c.GetComponent <CardPickup>();
            if (card == null)
            {
                return(false);
            }

            //Put card into "hand" transform and disable its collider
            c.transform.SetParent(CardHolder);
            c.transform.localPosition = Vector3.zero;
            holding = c.transform;
            //Collider can stay on if it is used for dropping
            c.GetComponent <BoxCollider2D>().enabled = false;
            didActionThisFrame = true;

            //Set large card to match this one
            largeCard.SetCard(card.GetCardIndexer().Card, false);
            largeCard.SetDirection(lineManager.Direction);

            return(true);
        }
        else
        {
            return(false);
        }
    }
Example #2
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);
    }
Example #3
0
    // Use this for initialization
    void Start()
    {
        LargeCard        lCard  = GetComponent <LargeCard>();
        CardSelectPasser passer = GameObject.FindObjectOfType <CardSelectPasser>();

        lCard.SetCard(passer.GetSelectedCard());
    }
Example #4
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);
        }
    }