예제 #1
0
 /// <summary>
 /// Put new item in this cell
 /// </summary>
 /// <param name="itemObj"> New item's object with DragAndDropItem script </param>
 ///
 public void PlaceItemForCell(DragAndDropCell cell, GameObject itemObj)
 {
     cell.RemoveItem();                                                       // Remove current item from this cell
     if (itemObj != null)
     {
         itemObj.transform.SetParent(cell.transform, false);
         itemObj.transform.localPosition = Vector3.zero;
         DragAndDropItem item = itemObj.GetComponent <DragAndDropItem>();
         if (item != null)
         {
             item.MakeRaycast(true);
         }
         cell.SetBackgroundState(true);
     }
 }
예제 #2
0
    /// <summary>
    /// Swap items between to cells
    /// </summary>
    /// <param name="firstCell"> Cell </param>
    /// <param name="secondCell"> Cell </param>
    public void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
    {
        if ((firstCell != null) && (secondCell != null))
        {
            DragAndDropItem firstItem  = firstCell.GetItem();               // Get item from first cell
            DragAndDropItem secondItem = secondCell.GetItem();              // Get item from second cell

            ItemSlot slot1 = firstCell.GetComponent <ItemSlot>();
            ItemSlot slot2 = secondCell.GetComponent <ItemSlot>();

            Item  item1  = slot1.item;
            Image image1 = slot1.image;
            Text  text1  = slot1.counterText;

            Item  item2  = slot2.item;
            Image image2 = slot2.image;
            Text  text2  = slot2.counterText;

            if (firstItem != null)
            {
                slot1.item        = item2;
                slot1.image       = image2;
                slot1.counterText = text2;
                // Place first item into second cell
                firstItem.transform.SetParent(secondCell.transform, false);
                firstItem.transform.localPosition = Vector3.zero;
                secondCell.SetBackgroundState(true);
            }
            if (secondItem != null)
            {
                slot2.item        = item1;
                slot2.image       = image1;
                slot2.counterText = text1;
                // Place second item into first cell
                secondItem.transform.SetParent(firstCell.transform, false);
                secondItem.transform.localPosition = Vector3.zero;
                firstCell.SetBackgroundState(true);
            }
        }
    }
예제 #3
0
 /// <summary>
 /// Swap items between to cells
 /// </summary>
 /// <param name="firstCell"> Cell </param>
 /// <param name="secondCell"> Cell </param>
 public void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
 {
     if ((firstCell != null) && (secondCell != null))
     {
         DragAndDropItem firstItem  = firstCell.GetItem();               // Get item from first cell
         DragAndDropItem secondItem = secondCell.GetItem();              // Get item from second cell
         if (firstItem != null)
         {
             // Place first item into second cell
             firstItem.transform.SetParent(secondCell.transform, false);
             firstItem.transform.localPosition = Vector3.zero;
             secondCell.SetBackgroundState(true);
         }
         if (secondItem != null)
         {
             // Place second item into first cell
             secondItem.transform.SetParent(firstCell.transform, false);
             secondItem.transform.localPosition = Vector3.zero;
             firstCell.SetBackgroundState(true);
         }
     }
 }
 /// <summary>
 /// Swap items between to cells
 /// </summary>
 /// <param name="firstCell"> Cell </param>
 /// <param name="secondCell"> Cell </param>
 public void SwapItems(DragAndDropCell firstCell, DragAndDropCell secondCell)
 {
     if ((firstCell != null) && (secondCell != null))
     {
         DragAndDropItem firstItem = firstCell.GetItem();                // Get item from first cell
         DragAndDropItem secondItem = secondCell.GetItem();              // Get item from second cell
         if (firstItem != null)
         {
             // Place first item into second cell
             firstItem.transform.SetParent(secondCell.transform, false);
             firstItem.transform.localPosition = Vector3.zero;
             secondCell.SetBackgroundState(true);
         }
         if (secondItem != null)
         {
             // Place second item into first cell
             secondItem.transform.SetParent(firstCell.transform, false);
             secondItem.transform.localPosition = Vector3.zero;
             firstCell.SetBackgroundState(true);
         }
     }
 }