예제 #1
0
    GameObject CreateCardAndContainer()
    {
        Card card = Instantiate(cardPrefab);

        GameObject containerObj = Instantiate(cardContainerPrefab, cardLibraryUI.libraryContainer.transform);

        cardContainerObjects.Add(containerObj);
        CardContainer container = cardContainerObjects.Last().GetComponentInChildren <CardContainer>();

        container.SetSize(CARD_SCALE);
        container.buttonsOnFocus = false;
        container.offsetOnFocus  = false;
        container.scaleOnFocus   = true;
        container.onBeginDrag   += () => OnBeginDrag(container);
        container.onPointerUp   += (dragging) =>
        {
            if (dragging)
            {
                OnEndDrag(container);
            }
            else
            {
                onClickCard?.Invoke(card);
            }
        };
        container.onDrag += () => onDragCard(container.GetCard());

        container.SetCard(card);
        card.OnCardPlaced = Close;

        return(containerObj);
    }
예제 #2
0
    private Card AddCardFromModel(ICardAssignmentModel assignment)
    {
        Card card = Instantiate(cardPrefab);

        card.Populate(assignment);
        card.AddListener((eventCard, eventType, eventData) =>
        {
            switch (eventType)
            {
            case Card.EventType.POINTER_DOWN:
                cardManager.OnPointerDownCard(eventCard);
                break;

            case Card.EventType.POINTER_UP:
                cardManager.OnPointerUpCard(eventCard);
                break;

            case Card.EventType.BEGIN_DRAG:
                cardManager.BeginDrag();
                break;

            default:
                break;
            }
        });

        card.OnClick = () => onCardClicked?.Invoke(card);

        // Create container for the card
        CardContainer newContainer = Instantiate(cardContainerPrefab, transform).GetComponentInChildren <CardContainer>();
        int           index        = this.model.GetIndexOf(card.GetCardAssignment());

        newContainer.rectTransform.transform.SetSiblingIndex(index);
        newContainer.SetSize(CardManager.BASE_CARD_SIZE);
        newContainer.scaleOnFocus = false;
        newContainer.deck         = this;

        newContainer.onPointerDown  += () => cardManager.OnPointerDownCard(newContainer.GetCard());
        newContainer.onPointerUp    += (dragging) => cardManager.OnPointerUpCard(newContainer.GetCard());
        newContainer.onPointerEnter += () => cardManager.OnPointerEnterContainer(newContainer);
        newContainer.onBeginDrag    += cardManager.BeginDrag;

        containers.Add(newContainer);
        newContainer.SetCard(card);
        newContainer.TriggerAddEffect();
        ResortCards();

        return(card);
    }