Exemplo n.º 1
0
    private void UpdateCurrentCards(Card[] cards)
    {
        var screenWidth      = Screen.width;
        var totalSpaceNeeded = screenWidth * (cardSpacingScreenPercent * cards.Length);
        var startX           = (screenWidth - totalSpaceNeeded) / 2f;

        var highlightedCardIndex = -1;

        for (var i = 0; i < cards.Length; i++)
        {
            var effectivePosition = _isFocused ? _defaultPosition : _unfocusedPosition;
            var cardIndex         = i;
            var card = cards[cardIndex];
            var(presenterIndex, presenter) = _cardPool.GetCardPresenter(cardIndex, card);
            var c             = presenter;
            var isHighlighted = c.IsHighlighted;
            if (isHighlighted)
            {
                highlightedCardIndex = presenterIndex;
            }

            if (!c.HasCard)
            {
                c.MoveTo(new Vector3(screenWidth * 1.5f, effectivePosition.y, effectivePosition.z));
            }

            var targetX        = startX + cardSpacingScreenPercent * (cardIndex + 0.5f) * screenWidth;
            var targetPosition = new Vector3(targetX, effectivePosition.y, effectivePosition.z);

            c.Set(card, () => SelectCard(cardIndex), true);
            c.SetCanPlay(allowInteractions && (!onlyAllowInteractingWithPlayables || card.IsPlayableByHero(state)));
            c.SetDisabled(!_isFocused);
            if (!card.Owner.IsConscious() || card.Owner.IsStunnedForCurrentTurn())
            {
                c.SetDisabled(true);
            }
            _cardPool.SwapItems(cardIndex, presenterIndex);
            c.SetHighlight(isHighlighted);
            c.SetTargetPosition(targetPosition);
            c.transform.SetAsLastSibling();
        }

        if (highlightedCardIndex > -1)
        {
            _cardPool.ShownCards[highlightedCardIndex].transform.SetAsLastSibling();
        }
    }