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 // }
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); } }
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; } } }