Input Systems
Inventool's demos are set up with the New Input System, but that doesn't mean it is a requirement. The main component handling input is the Default Inventool Input Handler component, which is created in a way that it works with all UI options. Here is the script for reference:
using Esper.Inventool.Merchants;
using Esper.Inventool.Storing;
using Esper.Inventool.UI;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Events;
using Esper.Inventool.UI.UGUI;
namespace Esper.Inventool.Input
{
/// <summary>
/// A default input handler for Inventool. This can only toggle the Inventool window.
/// </summary>
public class DefaultInventoolInputHandler : MonoBehaviour
{
/// <summary>
/// A callback for when the interact button is pressed.
/// </summary>
public static UnityEvent onInteract = new();
/// <summary>
/// Called when an input named "Inventory" is pressed. This simply toggles the inventool window.
/// </summary>
/// <param name="input">The input value.</param>
private void OnInventory(InputValue input)
{
if (input.isPressed)
{
if (InventoolWindow.Instance)
{
InventoolWindow.Instance.Toggle();
}
else if (InventoryWindow.Instance)
{
InventoryWindow.Instance.Toggle();
}
else if (InventoolWindowUGUI.Instance)
{
InventoolWindowUGUI.Instance.Toggle();
}
else if (InventoryWindowUGUI.Instance)
{
InventoryWindowUGUI.Instance.Toggle();
}
}
}
/// <summary>
/// Called when an input named "Equipment" is pressed. This simply toggles the equipment window.
/// </summary>
/// <param name="input">The input value.</param>
private void OnEquipment(InputValue input)
{
if (input.isPressed)
{
if (EquipmentWindow.Instance)
{
EquipmentWindow.Instance.Toggle();
}
else if (EquipmentWindowUGUI.Instance)
{
EquipmentWindowUGUI.Instance.Toggle();
}
}
}
/// <summary>
/// Called when an input named "KeyItems" is pressed. This simply toggles the key items window.
/// </summary>
/// <param name="input">The input value.</param>
private void OnKeyItems(InputValue input)
{
if (input.isPressed && Inventool.Inventory.enableKeyItems)
{
if (KeyItemsWindow.Instance)
{
KeyItemsWindow.Instance.Toggle();
}
else if (KeyItemsWindowUGUI.Instance)
{
KeyItemsWindowUGUI.Instance.Toggle();
}
}
}
/// <summary>
/// Called when an input named "Interact" is pressed. This will interact with a merchant if possible.
/// </summary>
/// <param name="input">The input value.</param>
private void OnInteract(InputValue input)
{
Inventool.Inventory.PickUpAllItemsInRange();
if (input.isPressed)
{
if (OverworldMerchant.activeMerchant)
{
OverworldMerchant.activeMerchant.Interact();
}
else if (StorageKeeper.activeStorageKeeper)
{
StorageKeeper.activeStorageKeeper.Interact();
}
}
onInteract.Invoke();
}
/// <summary>
/// Called when an input named "Exit" is pressed. This will close the inventool window when opened for a merchant.
/// </summary>
/// <param name="input">The input value.</param>
private void OnExit(InputValue input)
{
if (input.isPressed)
{
if (InventoolActionMenu.Instance && InventoolActionMenu.Instance.IsOpen)
{
InventoolActionMenu.Instance.Close();
return;
}
else if (InventoolActionMenuUGUI.Instance && InventoolActionMenuUGUI.Instance.IsOpen)
{
InventoolActionMenuUGUI.Instance.Close();
return;
}
if (InventoolWindow.Instance)
{
InventoolWindow.Instance.Exit();
}
else if (InventoolWindowUGUI.Instance)
{
InventoolWindowUGUI.Instance.Exit();
}
else if (DraggableWindow.active)
{
DraggableWindow.active.Close();
}
else if (DraggableWindowUGUI.active)
{
DraggableWindowUGUI.active.Close();
}
}
}
}
}
It's set to work with all UI options. It's recommended to create your own input handler script.
Old Input System
If you'd like to use Inventool with the old input system, you need to write your own input script. The example below works with the old input system, but only the full-screen uGUI option. To make it work with other input options, simply use the correct class names (check the script above for reference).
using Esper.Inventool;
using Esper.Inventool.Merchants;
using Esper.Inventool.Storing;
using Esper.Inventool.UI.UGUI;
using UnityEngine;
public class MyInventoolInputHandler : MonoBehaviour
{
private void Update()
{
// Toggle inventory
if (Input.GetKeyDown(KeyCode.Tab))
{
InventoolWindowUGUI.Instance.Toggle();
}
// Interact
else if (Input.GetKeyDown(KeyCode.E))
{
Inventool.Inventory.PickUpAllItemsInRange();
if (OverworldMerchant.activeMerchant)
{
OverworldMerchant.activeMerchant.Interact();
}
else if (StorageKeeper.activeStorageKeeper)
{
StorageKeeper.activeStorageKeeper.Interact();
}
}
// Exit merchant window or action menu if open
else if (Input.GetKeyDown(KeyCode.Escape))
{
if (InventoolActionMenuUGUI.Instance && InventoolActionMenuUGUI.Instance.IsOpen)
{
InventoolActionMenuUGUI.Instance.Close();
return;
}
if (InventoolWindowUGUI.Instance)
{
InventoolWindowUGUI.Instance.Exit();
}
}
}
}
Last updated