Ejemplo n.º 1
0
        /// <summary>
        /// Swap items between two 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
                // Swap items
                if (firstItem != null)
                {
                    firstItem.transform.SetParent(secondCell.transform, false);
                    firstItem.transform.localPosition = Vector3.zero;
                    firstItem.MakeRaycast(true);
                }

                if (secondItem != null)
                {
                    secondItem.transform.SetParent(firstCell.transform, false);
                    secondItem.transform.localPosition = Vector3.zero;
                    secondItem.MakeRaycast(true);
                }

                // Update states
                firstCell.UpdateMyItem();
                secondCell.UpdateMyItem();
                firstCell.UpdateBackgroundState();
                secondCell.UpdateBackgroundState();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Put item into this cell.
        /// </summary>
        /// <param name="item">Item.</param>
        private void PlaceItem(DragAndDropItem item)
        {
            if (item != null)
            {
                DestroyItem();                 // Remove current item from this cell
                myDadItem = null;
                DragAndDropCell cell = item.GetComponentInParent <DragAndDropCell>();
                if (cell != null)
                {
                    if (cell.unlimitedSource == true)
                    {
                        string itemName = item.name;
                        item      = Instantiate(item);                    // Clone item from source cell
                        item.name = itemName;
                    }
                }

                item.transform.SetParent(transform, false);
                item.transform.localPosition = Vector3.zero;
                item.MakeRaycast(true);
                myDadItem = item;
            }

            UpdateBackgroundState();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// On any item drag start need to disable all items raycast for correct drop operation
 /// </summary>
 /// <param name="item"> dragged item </param>
 private void OnAnyItemDragStart(DragAndDropItem item)
 {
     UpdateMyItem();
     if (myDadItem != null)
     {
         myDadItem.MakeRaycast(false);          // Disable item's raycast for correct drop handling
         if (myDadItem == item)                 // If item dragged from this cell
         {
             // Check cell's type
             switch (cellType)
             {
             case CellType.DropOnly:
                 DragAndDropItem.icon.SetActive(false);                                 // Item can not be dragged. Hide icon
                 break;
             }
         }
     }
 }