コード例 #1
0
        /// <summary>
        /// Handles the inventory related inputs and acts on them.
        /// </summary>
        protected virtual void HandleInventoryInput()
        {
            // if we don't have a current inventory display, we do nothing and exit
            if (_currentInventoryDisplay == null)
            {
                return;
            }

            // if the user presses the 'toggle inventory' key
            if (Input.GetKeyDown(ToggleInvKey) || Input.GetKeyDown(ToggleInvAltKey))
            {
                // if the inventory is not open
                if (!InventoryOpen)
                {
                    OpenInventory();
                }
                // if it's open
                else
                {
                    CloseInventory();
                }
            }

            // if we've only authorized input when open, and if the inventory is currently closed, we do nothing and exit
            if (InputOnlyWhenOpen && !InventoryOpen)
            {
                return;
            }

            // previous inventory panel
            if (Input.GetKeyDown(PrevInvKey) || Input.GetKeyDown(PrevInvAltKey))
            {
                if (_currentInventoryDisplay.GoToInventory(-1) != null)
                {
                    _currentInventoryDisplay = _currentInventoryDisplay.GoToInventory(-1);
                }
            }

            // next inventory panel
            if (Input.GetKeyDown(NextInvKey) || Input.GetKeyDown(NextInvAltKey))
            {
                if (_currentInventoryDisplay.GoToInventory(1) != null)
                {
                    _currentInventoryDisplay = _currentInventoryDisplay.GoToInventory(1);
                }
            }

            // move
            if (Input.GetKeyDown(MoveKey) || Input.GetKeyDown(MoveAltKey))
            {
                if (CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Move();
                }
            }

            // equip or use
            if (Input.GetKeyDown(EquipOrUseKey) || Input.GetKeyDown(EquipOrUseAltKey))
            {
                EquipOrUse();
            }

            // equip
            if (Input.GetKeyDown(EquipKey) || Input.GetKeyDown(EquipAltKey))
            {
                if (CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Equip();
                }
            }

            // use
            if (Input.GetKeyDown(UseKey) || Input.GetKeyDown(UseAltKey))
            {
                if (CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Use();
                }
            }

            // drop
            if (Input.GetKeyDown(DropKey) || Input.GetKeyDown(DropAltKey))
            {
                if (CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Drop();
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Triggers the selected slot's drop method
 /// </summary>
 public virtual void Drop()
 {
     CurrentlySelectedInventorySlot.Drop();
 }
コード例 #3
0
        /// <summary>
        /// Handles the inventory related inputs and acts on them.
        /// </summary>
        protected override void HandleInventoryInput()
        {
            // if the user presses the 'toggle inventory' key
            if (Input.GetKeyDown(ToggleInventoryKey) || Input.GetKeyDown(ToggleInventoryAltKey))
            {
                // if the inventory is not open
                if (!InventoryOpen)
                {
                    _isPressed = false;
                    OpenInventory();
                }
                // if it's open
                else
                {
                    _isPressed = true;
                    CloseInventory();
                    _isPressed = false;
                }
            }

            // if we've only authorized input when open, and if the inventory is currently closed, we do nothing and exit
            if (InputOnlyWhenOpen && !InventoryOpen)
            {
                return;
            }

            // vendor increase quantity
            if (Input.GetKeyDown(IncreaseQuantityKey) || Input.GetKeyDown(IncreaseQuantityAltKey))
            {
                IncreaseQuantity();
            }

            // vendor decrease quantity
            if (Input.GetKeyDown(DecreaseQuantityKey) || Input.GetKeyDown(DecreaseQuantityAltKey))
            {
                DecreaseQuantity();
            }

            // vendor sell
            if (Input.GetKeyDown(SellKey) || Input.GetKeyDown(SellAltKey))
            {
                SellItem();
            }

            // vendor buy
            if (Input.GetKeyDown(BuyKey) || Input.GetKeyDown(BuyAltKey))
            {
                BuyItem();
            }

            // vendor toggle inventory
            if (Input.GetKeyDown(ToggleVendorKey) || Input.GetKeyDown(ToggleVendorAltKey))
            {
                Vendor   openedVendor = null;
                Vendor[] vendors      = FindObjectsOfType <Vendor>();
                foreach (Vendor vendor in vendors)
                {
                    if (vendor.enabled && vendor.isOpen)
                    {
                        openedVendor = vendor;
                    }
                }
                if (openedVendor != null && openedVendor.canRollBackItems)
                {
                    if (openedVendor.isVendorRollBackOpen)
                    {
                        OpenVendorInventory();
                    }
                    else
                    {
                        OpenRollBackVendorInventory();
                    }
                }
            }

            // previous inventory panel
            if (Input.GetKeyDown(PrevInvKey) || Input.GetKeyDown(PrevInvAltKey))
            {
                if (_currentInventoryDisplay.GoToInventory(-1) != null)
                {
                    _currentInventoryDisplay = _currentInventoryDisplay.GoToInventory(-1);
                }
            }

            // next inventory panel
            if (Input.GetKeyDown(NextInvKey) || Input.GetKeyDown(NextInvAltKey))
            {
                if (_currentInventoryDisplay.GoToInventory(1) != null)
                {
                    _currentInventoryDisplay = _currentInventoryDisplay.GoToInventory(1);
                }
            }

            // move
            if (Input.GetKeyDown(MoveKey) || Input.GetKeyDown(MoveAltKey))
            {
                if (!_inVendor && CurrentlySelectedInventorySlot != null)
                {
                    MoveWithKeyboardJoypad();
                }
            }

            // equip or use
            if (Input.GetKeyDown(EquipOrUseKey) || Input.GetKeyDown(EquipOrUseAltKey))
            {
                if (!_inVendor && CurrentlySelectedInventorySlot != null)
                {
                    EquipOrUse();
                }
            }

            // split
            if (Input.GetKeyDown(SplitKey) || Input.GetKeyDown(SplitAltKey))
            {
                if (!_inVendor && CurrentlySelectedInventorySlot != null)
                {
                    SplitItemStack();
                }
            }

            // equip
            if (Input.GetKeyDown(EquipKey) || Input.GetKeyDown(EquipAltKey))
            {
                if (!_inVendor && CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Equip();
                }
            }

            // use
            if (Input.GetKeyDown(UseKey) || Input.GetKeyDown(UseAltKey))
            {
                if (!_inVendor && CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Use();
                }
            }

            // drop
            if (Input.GetKeyDown(DropKey) || Input.GetKeyDown(DropAltKey))
            {
                if (!_inVendor && CurrentlySelectedInventorySlot != null)
                {
                    CurrentlySelectedInventorySlot.Drop();
                }
            }
        }