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); } } }
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(); } }
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)); }
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); } } }
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); } }); }