/// <summary>
        /// Drop this item at the given position
        /// </summary>
        public DropMode Drop(Vector2 pos)
        {
            DropMode mode;

            if (currentController != null)
            {
                var grid = currentController.ScreenToGrid(pos + _offset + GetDraggedItemOffset(currentController.inventoryRenderer, item));

                // Try to add new item
                if (currentController.inventory.CanAddAt(item, grid))
                {
                    currentController.inventory.TryAddAt(item, grid); // Place the item in a new location
                    mode = DropMode.Added;
                }
                // Adding did not work, try to swap
                else if (CanSwap())
                {
                    var otherItem = currentController.inventory.allItems[0];
                    currentController.inventory.TryRemove(otherItem);
                    originalController.inventory.TryAdd(otherItem);
                    currentController.inventory.TryAdd(item);
                    mode = DropMode.Swapped;
                }
                // Could not add or swap, return the item
                else
                {
                    originalController.inventory.TryAddAt(item, originPoint); // Return the item to its previous location
                    mode = DropMode.Returned;
                }

                currentController.inventoryRenderer.ClearSelection();
            }
            else
            {
                mode = DropMode.Dropped;
                if (!originalController.inventory.TryForceDrop(item)) // Drop the item on the ground
                {
                    originalController.inventory.TryAddAt(item, originPoint);
                }
            }

            // Destroy the image representing the item
            Object.Destroy(_image.gameObject);

            return(mode);
        }
            /// <summary>
            /// Drop this item at the given position
            /// </summary>
            /// <param name="position">The position at which to drop the item</param>
            public void Drop(Vector2 position)
            {
                if (CurrentController != null)
                {
                    var grid = CurrentController.ScreenToGrid(position + _offset + CurrentController.GetDraggedItemOffset(Item));
                    if (CurrentController._inventory.CanAddAt(Item, grid))
                    {
                        // Checks if the inventory allows only one equipped item (like a weapon equip slot) AND it has an item equipped
                        if (CurrentController.equipSingleItemOnly && CurrentController._inventory.AllItems.ToArray().Length > 0)
                        {
                            OriginalController._inventory.AddAt(Item, OriginPoint);     // Return the item to its previous location
                        }
                        // For generic inventories that can hold any items
                        else if (CurrentController.inventoryType.Equals("Generic"))
                        {
                            CurrentController._inventory.AddAt(Item, grid);     // Place the item in a new location
                        }
                        // For specific inventories that can only hold a specific type of item (like weapon equip slots)
                        else if (CurrentController.inventoryType != null && CurrentController.inventoryType.Equals(Item.ItemType))
                        {
                            CurrentController._inventory.AddAt(Item, grid);     // Place the item in a new location
                        }
                        // Moves the item back to the original position if it can't fit in the selected inventory slot
                        else
                        {
                            OriginalController._inventory.AddAt(Item, OriginPoint);     // Return the item to its previous location
                        }
                    }
                    else
                    {
                        OriginalController._inventory.AddAt(Item, OriginPoint);     // Return the item to its previous location
                    }

                    CurrentController._renderer.ClearSelection();
                }
                else
                {
                    OriginalController._inventory.Drop(_draggedItem.Item);     // Drop the item
                }

                // Destroy the image representing the item
                GameObject.Destroy(_image.gameObject);
            }
Example #3
0
            /// <summary>
            /// Drop this item at the given position
            /// </summary>
            /// <param name="position">The position at which to drop the item</param>
            public void Drop(Vector2 position)
            {
                if (CurrentController != null)
                {
                    var grid = CurrentController.ScreenToGrid(position + _offset + CurrentController.GetDraggedItemOffset(Item));
                    if (CurrentController._inventory.CanAddAt(Item, grid))
                    {
                        CurrentController._inventory.AddAt(Item, grid);     // Place the item in a new location
                    }
                    else
                    {
                        OriginalController._inventory.AddAt(Item, OriginPoint);     // Return the item to its previous location
                    }
                    CurrentController._renderer.ClearSelection();
                }
                else
                {
                    OriginalController._inventory.Drop(_draggedItem.Item);     // Drop the item
                }

                // Destroy the image representing the item
                GameObject.Destroy(_image.gameObject);
            }