예제 #1
0
        private void Update()
        {
            DeckCountText.text = BuildDeckList.getItems().Select(i => i.count).Sum() + "/30";

            if (DragCard.isDisplaying)
            {
                var input = EventSystem.current.currentInputModule.input;
                DragCard.transform.position = input.mousePosition;
                Vector2 position = input.mousePosition;
                if (DeckViewScroll.GetComponent <RectTransform>().rect.Contains(DeckViewScroll.GetComponent <RectTransform>().InverseTransformPoint(position)))
                {
                    if (!DragCard.BuildDeckListItem.isDisplaying)
                    {
                        DragCard.BuildDeckListItem.display();
                        DragCard.BuildDeckListItem.update(DragCard.BuildDeckListItem.card, parent.game.cards.GetCardSkin(DragCard.BuildDeckListItem.card.id), 1);
                    }
                    DragCard.Card.hide();
                }
                else
                {
                    if (!DragCard.Card.isDisplaying)
                    {
                        DragCard.Card.display();
                        DragCard.Card.update(DragCard.BuildDeckListItem.card, parent.game.cards.GetCardSkin(DragCard.BuildDeckListItem.card.id));
                    }
                    DragCard.BuildDeckListItem.hide();
                }
                if (input.GetMouseButtonUp(0))
                {
                    //停止拖拽
                    stopDrag(position);
                }
            }
        }
예제 #2
0
        public void onReleaseCardItem(BuildCardListItem item, PointerEventData pointer)
        {
            DragCard.hide();
            Vector3 localPosition = DeckViewScroll.GetComponent <RectTransform>().InverseTransformPoint(pointer.position);

            if (DeckViewScroll.GetComponent <RectTransform>().rect.Contains(localPosition))
            {
                onReleaseItem();
            }
        }
예제 #3
0
 void onDragItem(CardDefine card, Vector2 position)
 {
     DragCard.display();
     DragCard.rectTransform.position = position;
     if (DeckViewScroll.GetComponent <RectTransform>().rect.Contains(DeckViewScroll.GetComponent <RectTransform>().InverseTransformPoint(position)))
     {
         DragCard.BuildDeckListItem.display();
         DragCard.Card.hide();
     }
     else
     {
         DragCard.Card.display();
         DragCard.BuildDeckListItem.hide();
     }
     DragCard.BuildDeckListItem.update(card, parent.game.cards.GetCardSkin(card.id), 1);
     DragCard.Card.update(card, parent.game.cards.GetCardSkin(card.id));
 }
예제 #4
0
        public void onReleaseDeckItem(BuildDeckListItem item, PointerEventData pointer)
        {
            DragCard.hide();
            Vector3 localPosition = DeckViewScroll.GetComponent <RectTransform>().InverseTransformPoint(pointer.position);

            if (DeckViewScroll.GetComponent <RectTransform>().rect.Contains(localPosition))
            {
                onReleaseItem();
            }
            else
            {
                if (item.count < 1)
                {
                    BuildDeckList.removeItem(item);
                }
            }
        }
예제 #5
0
        public void stopDrag(Vector2 position)
        {
            DragCard.hide();
            Vector3 localPosition = DeckViewScroll.GetComponent <RectTransform>().InverseTransformPoint(position);

            if (!DeckViewScroll.GetComponent <RectTransform>().rect.Contains(localPosition))
            {
                return;
            }
            if (BuildDeckList.Select(i => i.count).Sum() >= 30)
            {
                //你不能带更多的卡牌
                return;
            }
            var item = BuildDeckList.getItems().FirstOrDefault(i => i.card == DragCard.BuildDeckListItem.card);

            if (item != null)
            {
                item.count++;
            }
            else
            {
                var newItem = BuildDeckList.addItem();
                newItem.update(DragCard.BuildDeckListItem.card, parent.game.cards.GetCardSkin(DragCard.BuildDeckListItem.card.id), 1);
            }
            BuildDeckList.sortItems((a, b) =>
            {
                if (a.card.getCost() != b.card.getCost())
                {
                    return(a.card.getCost() - b.card.getCost());
                }
                else
                {
                    return(a.card.id - b.card.id);
                }
            });
        }