void Update()
    {
        if (!isDeletingCard && Input.GetMouseButtonDown(0))
        {
            Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, Mathf.Infinity);

            CardUpdater newSelectedCard = null;
            foreach (CardUpdater card in cards)
            {
                card.isSelected = false;

                if (hit.collider != null)
                {
                    if (hit.transform == card.transform)
                    {
                        newSelectedCard            = hit.transform.GetComponent <CardUpdater>();
                        newSelectedCard.isSelected = true;
                        selectedCard = newSelectedCard;
                        //Debug.Log(selectedCard.transform.name);
                    }
                }

                card.UpdateSelected();
            }

            if (newSelectedCard == null && selectedCard != null)
            {
                selectedCard.isSelected = true;
                selectedCard.UpdateSelected();
            }

            cantRemoveCardWarning.SetActive(false);
        }
    }
    void Start()
    {
        cards        = new List <CardUpdater>();
        selectedCard = null;

        LoadAndDisplayAllCards();

        cantRemoveCardWarning.SetActive(false);
        confirmRemoveCardWindow.SetActive(false);
        isDeletingCard = false;
    }
    public void ShowHandCards()
    {
        foreach (Transform child in handCardArea.transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        RectTransform rt         = (RectTransform)handCardArea.transform;
        float         areaHeight = rt.rect.height;
        float         areaWidth  = rt.rect.width;

        GameObject instantiatedCard = Instantiate(cardPrefab, handCardArea.transform);

        rt = (RectTransform)instantiatedCard.transform;
        float cardHeight = rt.rect.height;
        float cardWidth  = rt.rect.width;

        float   scaleFactor = areaHeight / cardHeight;
        Vector3 scaleVec    = new Vector3(scaleFactor, scaleFactor, scaleFactor);

        instantiatedCard.transform.localScale = scaleVec;
        cardWidth *= scaleFactor;


        float totalCardWidth = cardsInHand.Count * cardWidth;
        float cardPadding    = maxPadding;

        if (totalCardWidth > areaWidth)
        {
            cardPadding = (areaWidth - totalCardWidth) / cardsInHand.Count * 1.1f;
        }
        else if (totalCardWidth + (cardPadding * cardsInHand.Count) > areaWidth)
        {
            cardPadding = (areaWidth - totalCardWidth) / cardsInHand.Count;
        }

        for (int i = 1; i < cardsInHand.Count + 1; i++)
        {
            GameObject cardInGame   = Instantiate(instantiatedCard, handCardArea.transform);
            float      displacement = GetCardPositionInHand(i, cardsInHand.Count, cardWidth, cardPadding);
            cardInGame.transform.localPosition = new Vector3(displacement, 0.1f, 0);

            CardUpdater newCard = cardInGame.GetComponent <CardUpdater>();
            newCard.card = cardsInHand[i - 1];
            newCard.UpdateCardValues();

            DragAndDrop cardDrop = cardInGame.GetComponent <DragAndDrop>();
        }

        GameObject.Destroy(instantiatedCard.gameObject);
    }
Beispiel #4
0
    private void SetScaleAndStyleToPlayedCard(GameObject prefab, bool hiddenValues)
    {
        RectTransform rt         = (RectTransform)enemyPlayZone.transform;
        float         areaHeight = rt.rect.height;
        float         areaWidth  = rt.rect.width;

        GameObject instantiatedCard = Instantiate(prefab, enemyPlayZone.transform);

        rt = (RectTransform)instantiatedCard.transform;
        float cardHeight = rt.rect.height;
        float cardWidth  = rt.rect.width;

        if (cardHeight > areaHeight)
        {
            float   scaleFactor = areaHeight / cardHeight;
            Vector3 scaleVec    = new Vector3(scaleFactor, scaleFactor, scaleFactor);
            instantiatedCard.transform.localScale = scaleVec;
            cardWidth *= scaleFactor;
        }

        float totalCardWidth = cardsPlayed.Count * cardWidth;
        float cardPadding    = 5.0f;

        if (totalCardWidth > areaWidth)
        {
            cardPadding = (areaWidth - totalCardWidth) / cardsPlayed.Count * 1.1f;
        }
        else if (totalCardWidth + (cardPadding * cardsPlayed.Count) > areaWidth)
        {
            cardPadding = (areaWidth - totalCardWidth) / cardsPlayed.Count;
        }

        for (int i = 1; i < cardsPlayed.Count + 1; i++)
        {
            GameObject cardInGame   = Instantiate(instantiatedCard, enemyPlayZone.transform);
            float      displacement = enemyHand.GetCardPositionInHand(i, cardsPlayed.Count, cardWidth, cardPadding);
            cardInGame.transform.localPosition = new Vector3(displacement, 0.1f, 0);

            if (!hiddenValues)
            {
                CardUpdater newCard = cardInGame.GetComponent <CardUpdater>();
                newCard.card = cardsPlayed[i - 1];
                newCard.UpdateCardValues();
            }
        }

        GameObject.Destroy(instantiatedCard.gameObject);
    }
    private void ShowPlayedCards()
    {
        foreach (Transform child in cardPlayZone.transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        foreach (Card card in cardsPlayed)
        {
            GameObject  cardPlayed = Instantiate(cardPrefab, cardPlayZone.transform);
            CardUpdater newCard    = cardPlayed.GetComponent <CardUpdater>();
            newCard.card = card;
            newCard.UpdateCardValues();

            cardPlayed.transform.localScale = new Vector3(1, 1, 1);
        }
    }
    private void LoadAndDisplayAllCards()
    {
        cardManager.LoadCards();
        cardManager.SortCardsByCost();

        foreach (Transform child in cardArea.transform)
        {
            GameObject.Destroy(child.gameObject);
        }

        cards.Clear();
        foreach (Card card in cardManager.cardList)
        {
            GameObject  cardInGame = Instantiate(cardPrefab, cardArea.transform);
            CardUpdater newCard    = cardInGame.GetComponent <CardUpdater>();
            newCard.card = card;
            newCard.UpdateCardValues();

            cards.Add(newCard);
        }
    }