Example #1
0
 public void onDragHand(HandListItem item, PointerEventData pointer)
 {
     if (item.GetComponentInParent <HandList>() != SelfHandList)//你不能用别人的卡
     {
         return;
     }
     usingHand = item;
     if (!canControl)//不是你的回合
     {
         resetUse(true, true);
         return;
     }
     //拖拽卡片
     item.Card.rectTransform.position = pointer.position;
     if (SelfHandList.rectTransform.rect.Contains(SelfHandList.rectTransform.InverseTransformPoint(pointer.position)))
     {
         //如果移动回手牌区域,恢复正常大小
         item.Card.rectTransform.localScale = Vector3.one;
         //移除随从占位
         hideServantPlaceHolder();
     }
     else
     {
         //移动到手牌区以外的地方视作打算使用
         if (!item.Card.card.isUsable(game, player, out string info))
         {
             //卡牌不可用,停止拖拽并提示
             showTip(info);
             resetUse(true, true);
         }
         else
         {
             //手牌在战场上大小和随从牌一致
             item.Card.rectTransform.localScale = Vector3.one * .4f / rectTransform.localScale.y;
             if (item.Card.card.define is ServantCardDefine)
             {
                 SelfFieldList.defaultItem.rectTransform.SetAsFirstSibling();
                 ServantPlaceHolder.rectTransform.sizeDelta = SelfFieldList.defaultItem.rectTransform.sizeDelta;
                 SelfFieldList.addChild(ServantPlaceHolder.rectTransform);
                 ServantPlaceHolder.display();
                 var servants = SelfFieldList.getItems();
                 int index    = 0;
                 if (servants.Length > 0)
                 {
                     //需要选择空位,计算空位
                     for (int i = 0; i < servants.Length; i++)
                     {
                         if (servants[i].rectTransform.position.x < pointer.position.x)
                         {
                             index = i + 1;
                         }
                     }
                     ServantPlaceHolder.rectTransform.SetSiblingIndex(index + 1);
                 }
             }
         }
     }
 }
Example #2
0
 private void hideServantPlaceHolder()
 {
     addChild(ServantPlaceHolder.rectTransform);
     ServantPlaceHolder.Servant.hide();
     ServantPlaceHolder.hide();
 }