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.
The documentation for this may be slightly ahead of the released version. However, the idea is the similar. GetDefaultActionMenuOptions will be available in the next update.
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.
usingEsper.Inventool.Items;usingEsper.Inventool.UI;usingSystem.Collections.Generic;usingUnityEngine;publicclassActionMenuCustomizer:MonoBehaviour{privatevoidAwake() { // Apply the customization on awakeItemStack.actionMenuOptionsGetter= MyActionMenuOptionsGetter; } /// <summary> /// Creates and returns the action menu options. /// </summary> /// <paramname="itemStack">The item stack target to create the options for.</param> /// <returns>A list of action menu options.</returns>privateList<ActionMenuOption> MyActionMenuOptionsGetter(ItemStack itemStack) { // Create a list that will contain the optionsvar options =ItemStack.GetDefaultActionMenuOptions(itemStack); // Add an optionvar myOption =newActionMenuOption() { // Set the button text (smallcaps is generally used for styling purposes) text =$"<smallcaps>My Option</smallcaps>", // Set the button color backgroundColor =newColor(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 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.
usingEsper.Inventool;usingEsper.Inventool.UI;usingSystem.Collections.Generic;usingUnityEngine;publicclassActionMenuCustomizer:MonoBehaviour{privatevoidAwake() { // Apply the customization on awakeEquipmentSlot.actionMenuOptionsGetter= MyActionMenuOptionsGetter; } /// <summary> /// Creates and returns the action menu options. /// </summary> /// <paramname="slot">The equipment slot target to create the options for.</param> /// <returns>A list of action menu options.</returns>privateList<ActionMenuOption> MyActionMenuOptionsGetter(EquipmentSlot slot) { // Create a list that will contain the optionsvar options =EquipmentSlot.GetDefaultActionMenuOptions(slot); // Add an optionvar myOption =newActionMenuOption() { // Set the button text (smallcaps is generally used for styling purposes) text =$"<smallcaps>My Option</smallcaps>", // Set the button color backgroundColor =newColor(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.