Input Systems
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();
}
}
}
}
}Old Input System
Last updated