Exemplo n.º 1
0
        private void Update()
        {
            // Check if ACTION key is held for more than 0.5 seconds
            if (Input.GetKeyUp(GetActionKeyCode()))
            {
                interactionKeyHeldTime = 0f;
                heldInteractionKey     = false;
            }
            else if (!heldInteractionKey && Input.GetKey(GetActionKeyCode()))
            {
                interactionKeyHeldTime += Time.deltaTime;
                if (interactionKeyHeldTime >= 0.25f)
                {
                    heldInteractionKey = true;
                }
            }

            // If ACTION key is pressed while hovering a food in inventory, eat it
            Inventory3DManager inventory = Inventory3DManager.Get();

            if (inventory && inventory.IsActive() &&                                                                                                     // Make sure inventory is currently open
                inventory.m_FocusedItem && !inventory.m_FocusedItem.m_OnCraftingTable &&                                                                 // Make sure the highlighted item isn't on crafting table
                !inventory.m_CarriedItem &&                                                                                                              // Make sure we aren't drag & dropping any items at the moment
                TriggerController.Get().GetBestTrigger() && TriggerController.Get().GetBestTrigger().gameObject == inventory.m_FocusedItem.gameObject && // Make sure the highlighted item is the item that the cursor is on
                !HUDItem.Get().m_Active&&                                                                                                                // Make sure RMB menu isn't open for any item right now
                !InputsManager.Get().m_TextInputActive&&                                                                                                 // Make sure chat isn't active
                (inventory.m_FocusedItem.m_Info.m_Eatable || inventory.m_FocusedItem.m_Info.m_Drinkable) &&                                              // Make sure the highlighted item is eatable or drinkable
                Input.GetKeyDown(GetActionKeyCode()))                                                                                                    // Make sure hotkey is pressed
            {
                if (!inventory.m_FocusedItem.ReplIsOwner())
                {
                    inventory.m_FocusedItem.ReplRequestOwnership();
                }

                inventory.m_FocusedItem.ReplSetDirty();

                if (inventory.m_FocusedItem.m_Info.m_Eatable)
                {
                    inventory.m_FocusedItem.Eat();
                }
                else
                {
                    inventory.m_FocusedItem.Drink();
                }
            }
        }
Exemplo n.º 2
0
        private void Update()
        {
            // If the configurable hotkey is pressed while hovering an item in inventory, move the item to crafting table
            Inventory3DManager inventory     = Inventory3DManager.Get();
            CraftingManager    craftingTable = CraftingManager.Get();

            if (inventory && craftingTable &&
                !HUDItem.Get().m_Active&&                   // Make sure RMB menu isn't open for any item right now
                TriggerController.Get().GetBestTrigger() && // Make sure there is a highlighted item
                !InputsManager.Get().m_TextInputActive&&    // Make sure chat isn't active
                GetButtonDown(hotkey))                      // Make sure hotkey is pressed
            {
                bool forceOpenedInventory = false;
                if (!inventory.IsActive() && openInventoryIfNotOpen)
                {
                    // Force open inventory
                    Item triggerItem = TriggerController.Get().GetBestTrigger().GetComponent <Item>();
                    if (triggerItem)
                    {
                        inventory.Activate();
                        if (inventory.IsActive())
                        {
                            forceOpenedInventory = true;

                            inventory.m_FocusedItem = triggerItem;
                            if (!triggerItem.GetWasTriggered())
                            {
                                triggerItem.SetWasTriggered(true);
                            }
                        }
                    }
                }

                if (inventory.IsActive() &&                                                                    // Make sure inventory is currently open
                    inventory.m_FocusedItem && !inventory.m_FocusedItem.m_OnCraftingTable &&                   // Make sure the highlighted item isn't already on crafting table
                    !inventory.m_CarriedItem && inventory.CanSetCarriedItem(true) &&                           // Make sure we aren't drag & dropping any items at the moment
                    TriggerController.Get().GetBestTrigger().gameObject == inventory.m_FocusedItem.gameObject) // Make sure the highlighted item is the item that the cursor is on
                {
                    craftingTable.Activate();

                    inventory.StartCarryItem(inventory.m_FocusedItem, false);
                    craftingTable.AddItem(inventory.m_CarriedItem, true);

                    if (inventory.m_StackItems != null)
                    {
                        for (int i = 0; i < inventory.m_StackItems.Count; i++)
                        {
                            craftingTable.AddItem(inventory.m_StackItems[i], true);
                        }
                    }

                    inventory.SetCarriedItem(null, true);

                    if (dropItemToTableClip)
                    {
                        inventory.GetComponent <AudioSource>().PlayOneShot(dropItemToTableClip);
                    }
                }
                else if (forceOpenedInventory)
                {
                    inventory.Deactivate();
                }
            }
        }