Inventool Documentation
  • Inventool Documentation
  • đŸ•šī¸Quick Start
    • Installation
    • Start Creating
  • 💡General
    • Running the Demo
    • Menu Options
    • UI Updates
    • UI Customizations
      • uGUI
      • UI Toolkit
    • Custom Item Drops
  • 🎓Tutorials
    • Demo Walkthrough
  • âœī¸Editors
    • Inventool
      • Inventory
      • Equipment
      • Items
      • Currencies
      • Crafting
      • Dismantling
      • Enchanting
      • Stats
        • Stat IDs
        • Attributes
      • Settings
    • Item Type Manager
    • Localization Editor
    • Stats Editor
    • Merchants
      • Shopkeeper
      • Craftsman
      • Enchanter
    • Storage
    • Loot
      • Loot Box
      • Item Pouch
      • Currency Pouch
    • Components
      • Initializer
      • UI
        • uGUI
          • Inventool Window
          • Split UI
            • Inventory Window UGUI
            • Equipment Window UGUI
            • Key Items Window UGUI
            • Crafting Window UGUI
            • Enchanting Window UGUI
            • Storage Window UGUI
            • Shop Window UGUI
            • Selector UGUI
          • Action Menu UGUI
          • Hover Details UGUI
          • Confirm Prompt UGUI
          • Quantity Prompt UGUI
          • Character Viewer Element UGUI
        • UI Toolkit
          • Inventool Window
          • Split UI
            • Inventory Window
            • Equipment Window
            • Key Items Window
            • Crafting Window
            • Enchanting Window
            • Storage Window
            • Shop Window
          • Action Menu
          • Hover Details
          • Confirm Prompt
          • Quantity Prompt
        • Character Viewer
      • Overworld Merchant
      • Storage Keeper
      • Item Drop
      • Item Spawner
      • Input
        • Cross Input Support
        • Cross Input Support UGUI
          • Target Selectable
  • 📄Scripting API
    • Initialization
    • Inventory
    • Equipment
      • Equipment Slot
    • Items
      • Item
      • Item Type
      • Item Stack
      • Item Drop
      • Item Spawner
      • Loot Box
      • Item Pouch
    • Currencies
      • Currency Identity
      • Currency
        • Value
      • Currency Pouch
    • Crafting
      • Craft
      • Crafter
    • Enchanting
      • Enchantment
    • Stats
      • Stat Identity
      • Attribute
      • Stat
        • Stat Value
          • Value
        • Effectiveness
      • Stat Profile
    • Storing
      • Storage
      • Storage Keeper
    • Settings
    • Merchants
      • Shopkeeper
      • Craftsman
      • Enchanter
      • Overworld Merchant
    • UI
      • uGUI
        • Inventool Window UGUI
        • Split UI
          • Draggable Window UGUI
            • Inventory Window UGUI
            • Equipment Window UGUI
            • Key Items Window UGUI
            • Crafting Window UGUI
            • Enchanting Window UGUI
            • Storage Window UGUI
            • Shop Window UGUI
          • Selector UGUI
        • Action Menu UGUI
        • Hover Details UGUI
        • Confirm Prompt UGUI
        • Quantity Prompt UGUI
        • Draggable Element UGUI
          • Equipment Slot Element UGUI
          • Item Slot Element UGUI
          • Item Stack Element UGUI
        • Action Menu Option UGUI
        • Currency Element UGUI
        • Inventory Filter UGUI
        • Inventory Slot UGUI
        • Key Item Element UGUI
        • Shop Item Element UGUI
        • Storage Currency Element UGUI
        • Stat Element UGUI
      • UI Toolkit
        • Inventool Window
        • Split UI
          • Draggable Window
            • Inventory Window
            • Equipment Window
            • Key Items Window
            • Crafting Window
            • Enchanting Window
            • Storage Window
            • Shop Window
        • Action Menu
        • Hover Details
        • Confirm Prompt
        • Quantity Prompt
        • Item Elements
          • Item Stack Element
          • Equipment Slot Element
          • Item Slot Element
          • Shop Item Element
      • Action Menu Option
      • Character Viewer
    • Events
    • Sounds
    • Saving & Loading
      • Inventory & Equipment
      • Storage
    • Input
      • Cross Input Support
      • Cross Input Support UGUI
    • Localization
      • Localization Settings
      • Localizer
  • đŸ› ī¸Support
    • Getting Help
  • 📚Changelogs
    • Latest Releases
    • Future Plans
  • ⭐Rate Me?
Powered by GitBook
On this page
  • Fields & Properties
  • Active Instance
  • Opening
  • Closing
  • Customizations
  • Customize For Inventory Item Stacks
  • Customize For Equipment Slots
  1. Scripting API
  2. UI
  3. UI Toolkit

Action Menu

Scripting with the InventoolActionMenu class.

The InventoolActionMenu class is a pop-up menu for custom actions.

Fields & Properties

Name
Description
Type
Access

document

The UI document.

UIDocument

protected

root

The root of the content.

VisualElement

protected

optionContainer

The visual element that contains all options.

VisualElement

protected

closeButton

The full-screen invisible close button.

Button

protected

IsOpen

If the action menu is currently open.

bool

public

Active Instance

You can get the active InventoolActionMenu instance with InventoolActionMenu.Instance. Ensure there's an instance of it in your scene before using this field.

Opening

Opening the action menu requires a VisualElement target and a list of Action Menu Option.

InventoolActionMenu.Instance.Open(targetElement, myMenuOptions);

Closing

InventoolActionMenu.Instance.Close();

Customizations

The options displayed on the action menu are customizable through scripting.

Customize For Inventory Item Stacks

To customize the action menu options displayed when an item stack in the inventory is clicked, edit the ItemStack.actionMenuOptionsGetter field.

using Esper.Inventool.Items;
using Esper.Inventool.UI;
using System.Collections.Generic;
using UnityEngine;

public class ActionMenuCustomizer : MonoBehaviour
{
    public Sprite myIcon;

    private void Awake()
    {
        // Apply the customization on awake
        ItemStack.actionMenuOptionsGetter = MyActionMenuOptionsGetter;
    }

    /// <summary>
    /// Creates and returns the action menu options.
    /// </summary>
    /// <param name="itemStack">The item stack target to create the options for.</param>
    /// <returns>A list of action menu options.</returns>
    private List<ActionMenuOption> MyActionMenuOptionsGetter(ItemStack itemStack)
    {
        // Create a list that will contain the options
        var options = ItemStack.GetDefaultActionMenuOptions(itemStack);

        // Add an option
        var myOption = new ActionMenuOption()
        {
            // Set the button text (smallcaps is generally used for styling purposes)
            text = $"<smallcaps>My Option</smallcaps>",

            // Set the button color
            backgroundColor = new Color(0.3f, 0.3f, 0.3f),

            // Set its order in the menu (lower numbers appear at the top)
            sortingOrder = 0,

            // Create an on-click action
            action = () => Debug.Log("Do something"),
            
            // Display a small icon beside the text
            icon = myIcon
        };

        options.Add(myOption);

        return options;
    }
}

If you'd like a reference, you can find the original in the ItemStack.actionMenuOptionsGetter field in the ItemStack.cs script.

Customize For Equipment Slots

To customize the action menu options displayed when an equipment slot in the inventory is clicked, edit the EquipmentSlot.actionMenuOptionsGetter field.

using Esper.Inventool;
using Esper.Inventool.UI;
using System.Collections.Generic;
using UnityEngine;

public class ActionMenuCustomizer : MonoBehaviour
{
    private void Awake()
    {
        // Apply the customization on awake
        EquipmentSlot.actionMenuOptionsGetter = MyActionMenuOptionsGetter;
    }

    /// <summary>
    /// Creates and returns the action menu options.
    /// </summary>
    /// <param name="slot">The equipment slot target to create the options for.</param>
    /// <returns>A list of action menu options.</returns>
    private List<ActionMenuOption> MyActionMenuOptionsGetter(EquipmentSlot slot)
    {
        // Create a list that will contain the options
        var options = EquipmentSlot.GetDefaultActionMenuOptions(slot);

        // Add an option
        var myOption = new ActionMenuOption()
        {
            // Set the button text (smallcaps is generally used for styling purposes)
            text = $"<smallcaps>My Option</smallcaps>",

            // Set the button color
            backgroundColor = new Color(0.3f, 0.3f, 0.3f),

            // Set its order in the menu (lower numbers appear at the top)
            sortingOrder = 0,

            // Create an on-click action
            action = () => Debug.Log("Do something")
        };

        options.Add(myOption);

        return options;
    }
}

If you'd like a reference, you can find the original in the EquipmentSlot.actionMenuOptionsGetter field in the EquipmentSlot.cs script.

PreviousShop WindowNextHover Details

Last updated 4 months ago

📄