/// <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);
            }
Exemplo n.º 2
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);
            }