Ejemplo n.º 1
0
    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);
    }
    public void RemoveCardButton()
    {
        if (selectedCard == null)
        {
            cantRemoveCardWarning.SetActive(true);
            return;
        }

        deletingCard.card = selectedCard.card;
        deletingCard.UpdateCardValues();

        isDeletingCard = true;
        confirmRemoveCardWindow.SetActive(true);
    }
Ejemplo n.º 3
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);
        }
    }