Exemple #1
0
    // Use this for initialization
    void Start()
    {
        LargeCard        lCard  = GetComponent <LargeCard>();
        CardSelectPasser passer = GameObject.FindObjectOfType <CardSelectPasser>();

        lCard.SetCard(passer.GetSelectedCard());
    }
Exemple #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);
    }
Exemple #3
0
    //Undo selection change
    void UnselectCard(LargeCard c)
    {
        Image image = c.GetComponent <Image>();

        image.color = previousColor;

        selectedCards.Remove(c);
    }
Exemple #4
0
    //Somehow denote some kind of selection
    void SelectCard(LargeCard c)
    {
        Image image = c.GetComponent <Image>();

        previousColor = image.color;

        image.color = new Color(0, .5f, .5f);

        selectedCards.Add(c);
    }
Exemple #5
0
    IEnumerator FlipBackCards(LargeCard a, LargeCard b)
    {
        yield return(new WaitForSeconds(FlipBackDelay + a.SpinDuration));

        SetFlippingChildren(true);
        ignoreSet.Remove(a.transform);
        ignoreSet.Remove(b.transform);
        a.SpinCard();
        b.SpinCard();
        ForceCardsOver();
    }
Exemple #6
0
 void FindCardsAddTriggers()
 {
     //Get every card in scene and add trigger to them
     LargeCard[] cards = GameObject.FindObjectsOfType <LargeCard>();
     for (int i = 0; i < cards.Length; i++)
     {
         LargeCard          lCard   = cards[i];
         EventTrigger       trigger = lCard.GetComponent <EventTrigger>();
         EventTrigger.Entry entry   = new EventTrigger.Entry();
         entry.eventID = EventTriggerType.PointerClick;
         entry.callback.AddListener((data) => { TappedCard((PointerEventData)data); });
         trigger.triggers.Add(entry);
     }
 }
Exemple #7
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();
         }
     }
 }
Exemple #8
0
    protected override void DoAfterLoad()
    {
        base.DoAfterLoad();
        //Set card in scene to this card data
        LargeCard lCard = GameObject.FindObjectOfType <LargeCard>();

        //If it contains game line trigger
        GameLineTrigger trigger = lCard.GetComponent <GameLineTrigger>();

        if (trigger != null)
        {
            trigger.PathType = PathType;
            trigger.Folder   = Folder;
        }
    }
Exemple #9
0
    void TappedCard(PointerEventData data)
    {
        //Have to double click
        if (data.clickCount < 2)
        {
            return;
        }
        GameObject go       = data.pointerCurrentRaycast.gameObject;
        LargeCard  selected = go.GetComponentInParent <LargeCard>();

        //Quick select and pass to scene as this is the only card that can be selected
        if (MaxSelectedCards == 1)
        {
            selectedCards.Add(selected);
            SendCardsToScene();
            return;
        }

        if (!selectedCards.Contains(selected))
        {
            SelectCard(selected);
            cardQueue.Enqueue(selected);
            while (cardQueue.Count > MaxSelectedCards)
            {
                LargeCard card = cardQueue.Dequeue();
                UnselectCard(card);
            }
        }
        else
        {
            UnselectCard(selected);
            //Remove this card from the queue
            Queue <LargeCard> newQueue = new Queue <LargeCard>();
            while (cardQueue.Count > 0)
            {
                LargeCard card = cardQueue.Dequeue();
                if (card != selected)
                {
                    newQueue.Enqueue(card);
                }
            }
            cardQueue = newQueue;
        }
    }
Exemple #10
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);
        }
    }
Exemple #11
0
    void TappedCard(PointerEventData data)
    {
        //Ignore these flip events
        if (lockedSpin)
        {
            return;
        }
        GameObject go    = data.pointerCurrentRaycast.gameObject;
        LargeCard  lCard = go.GetComponentInParent <LargeCard>();

        if (!lCard.CanSpin || (selectedCard != null && !selectedCard.CanSpin) || ignoreSet.Contains(lCard.transform))
        {
            return;
        }
        if (selectedCard == null)
        {
            selectedCard = lCard;
        }
        else if (selectedCard == lCard)
        {
            selectedCard = null;
        }
        else
        {
            //Selected the correct second card (has to be facing the other way)
            if (lCard.GetCardData() == selectedCard.GetCardData() && (lCard.hideType != selectedCard.hideType))
            {
                //Disable interactivity
                //Can't just set canspin because canspin is constantly reset (can make it only reset cards that aren't in solved hashset if necessary)
                CanvasGroup lCardGroup    = lCard.GetComponent <CanvasGroup>();
                CanvasGroup selectedGroup = selectedCard.GetComponent <CanvasGroup>();
                lCardGroup.interactable      = false;
                selectedGroup.interactable   = false;
                lCardGroup.blocksRaycasts    = false;
                selectedGroup.blocksRaycasts = false;

                //Ignore these cards when forcing all cards to flip over
                ignoreSet.Add(lCard.transform);
                ignoreSet.Add(selectedCard.transform);

                //Show some other way that it was correct
                lCard.GetComponent <Image>().color        = Color.cyan;
                selectedCard.GetComponent <Image>().color = Color.cyan;
                ForceCardsOver();
                selectedCard = null;

                cardsCompleted += 2;
                CheckGameCompleted();
            }
            else
            {
                //Make sure second card is still flipped due to how events are passed
                lCard.SpinCard();
                //Force all other children cards over if they aren't in hashSet of solved cards or selected cards
                ignoreSet.Add(lCard.transform);
                ignoreSet.Add(selectedCard.transform);
                ForceCardsOver();
                //Enforce a delay to see that you made a mistake
                SetFlippingChildren(false);
                StartCoroutine(FlipBackCards(lCard, selectedCard));
                //Wrong second card, lock out spinning of all the cards in order to show mistake
                selectedCard = null;
            }
        }
    }
 // Use this for initialization
 void Start()
 {
     largeCard = GetComponentInParent <LargeCard>();
 }