Ejemplo n.º 1
0
 public void OnEndDrag(PointerEventData eventData)
 {
     if (!dragBegins)
     {
         return;
     }
     dragBegins = false;
     if (!infoCard.GetComponent <CardInfo>().IsStandard())
     {
         cardImage.GetComponent <Image>().sprite = null;
         CardInfo   newCard = infoCard.GetComponent <CardInfo>();
         GameObject find    = GameObject.Find(FindLoc(Input.mousePosition).ToString());
         if (find != null)
         {
             Transform oldObject    = find.transform;
             Image     oldCardImage = oldObject.Find("CardImage").GetComponent <Image>();
             if (oldCardImage.sprite != null)
             {
                 // switch
                 PieceAttributes attributes = boardInfo.attributesDict[oldObject.name];
                 if (attributes.type == newCard.GetCardType())
                 {
                     boardInfo.SetCard(attributes, new Location(parent.name));
                     cardImage.GetComponent <Image>().sprite = attributes.image;
                     parent = oldObject;
                     boardInfo.SetCard(newCard.piece, new Location(parent.name));
                     oldCardImage.sprite = newCard.piece.image;
                 }
                 else
                 {
                     // Show Animation: Can't Switch
                     StartCoroutine(ShowCantSwitch());
                     cardImage.GetComponent <Image>().sprite = infoCard.GetComponent <CardInfo>().piece.image;
                 }
             }
             else
             {
                 // Drag to an empty spot and resume.
                 cardImage.GetComponent <Image>().sprite = infoCard.GetComponent <CardInfo>().piece.image;
             }
         }
         else
         {
             // Drag outside the board.
             string cardType = newCard.GetCardType();
             collectionManager.AddCollection(new Collection(newCard.piece));
             boardInfo.SetStandardCard(cardType, new Location(parent.name));
             collectionManager.RemoveCollection(Collection.StandardCollection(cardType));
             collectionManager.ShowCurrentPage();
             cardImage.sprite = Database.standardAttributes["Standard " + cardType].image;
         }
     }
     EnableImage(cardImage);
     infoCard.SetActive(false);
 }