public void OnDrop(PointerEventData eventData) { ItemCard card = eventData.pointerDrag.GetComponent <ItemCard>(); if (card != null) { bool IsCorrect = IsEmpty && (card.Category == ChestItemCategory || ChestItemCategory == ItemCardCategory.Empty); if (IsCorrect) { currentCard = card; ChestItemCategory = card.Category; eventData.pointerDrag.transform.SetParent(ImageSlot.transform); RectTransform rect = eventData.pointerDrag.GetComponent <RectTransform>(); rect.anchoredPosition = new Vector2(0, 0); rect.anchorMin = new Vector2(0, 0); rect.anchorMax = new Vector2(1, 1); rect.offsetMin = new Vector2(0, 0); rect.offsetMax = new Vector2(0, 0); card.DisableDrag(); } if (OnCardDrop != null) { OnCardDrop.Invoke(card, IsCorrect); } } }
private void MakeItemCard(ItemCardCategory category) { Sprite sprite = GetAvailableSprite(category); ItemCard itemCard = Instantiate(ItemCardPrefab, CardPosition); itemCard.Construct(category, sprite); }
private void OnCardDroped(ItemCard card, bool IsCorrect) { if (IsWin) { WellDoneDialog winDialog = Instantiate(wellDoneDialogPrefab, Canvas); winDialog.OkButton.button.onClick.AddListener(MakeRetryDialog); AudioManager.instance.PlayCorrectly(); } else { if (IsCorrect) { CheckFirstCardDropped(RightChests, card); CheckFirstCardDropped(LeftChests, card); var leftCategories = GetAvailableChestsCategories(LeftChests).ToList(); var rightCategories = GetAvailableChestsCategories(RightChests).ToList(); List <ItemCardCategory> AvailableCategories = leftCategories.Union(rightCategories).Where(c => !leftCategories.Intersect(rightCategories).Contains(c)).ToList(); ItemCardCategory cardCategory = AvailableCategories[UnityEngine.Random.Range(0, AvailableCategories.Count)]; MakeItemCard(cardCategory); AudioManager.instance.PlayCorrectly(); } else { card.dragHandler.ResetPosition(); AudioManager.instance.PlayWrong(); } } }
private Sprite GetAvailableSprite(ItemCardCategory category) { ItemCardAndPictures cardsPictures = CardPictures.Find(l => l.category == category); var sprites = cardsPictures.Sprites.Where(i => !i.IsUsed).ToList(); if (sprites.Any()) { int index = UnityEngine.Random.Range(0, sprites.Count); sprites[index].IsUsed = true; return(sprites[index].sprite); } return(null); }
public void Construct(ItemCardCategory category, Sprite sprite) { Category = category; Picture.sprite = sprite; }
public void Clear() { Destroy(currentCard.gameObject); ChestItemCategory = ItemCardCategory.Empty; }
private void StartGame() { ItemCardCategory category = (ItemCardCategory)UnityEngine.Random.Range(1, 9); MakeItemCard(category); }
private void SetChestsCategory(List <ChestSlot> chests, ItemCardCategory category) { chests.ForEach(c => c.ChestItemCategory = category); }