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
  • Creating a Slot
  • Setting Items
  • Equip An Item
  • Unequip An Item
  • Switching Items
  • Action Menu Options
  1. Scripting API
  2. Equipment

Equipment Slot

Scripting with the EquipmentSlot class.

The EquipmentSlot class serves as the slots used for equipping items by the Equipment.

Fields & Properties

Name
Description
Type
Access

positionIndex

The index of the position to use.

int

public

name

The name of the slot. Used for searching purposes.

string

public

itemStack

The equipped item.

ItemStack

public

backgroundIcon

The background icon of the slot.

Sprite

public

backgroundIconColorTint

The background icon color tint.

Color

public

itemType

The item type that is accepted by the slot.

ItemType

public

HasItem

If this slot has an item.

bool

public

Creating a Slot

While it's recommended to use the Equipment to create slots, it's possible to create them through code at runtime.

var mySlot = new EquipmentSlot()
{
    // Set the position index
    positionIndex = 0,

    // Create searchable name
    name = "My Slot Name",

    // Set the background icon (Sprite)
    backgroundIcon = mySlotSprite,

    // Set the color tint of the background icon
    backgroundColorTint = Color.white,

    // Set the item type restriction (ItemType)
    itemType = myItemType
};

Setting Items

Equipment slots can equip an Item Stack. In the examples below, mySlot is an instance of an EquipmentSlot.

Checking If Equipping Is Possible

You can check if an item can be equipped by an equipment slot. Note that TryEquip already checks for this.

Equip An Item

The TryEquip method attempts to equip an ItemStack. This method returns true if the item stack was successfully equipped. This may fail if the slot restricts the type of the item.

bool result = mySlot.TryEquip(myItemStack);

Unequip An Item

mySlot.Unequip();

Switching Items

The TrySwitch method attempts to switch item stacks with another slot. This method returns true if the switch was successful. This may fail if the slot cannot equip the item of the other slot (restricted type).

bool result = mySlot.TrySwitch(myOtherSlot);

Action Menu Options

By default, equipment slots' UI counterpart logically display item options for the Action Menu. You can override these options by editing the EquipmentSlot.actionMenuOptionsGetter field.

Here's an example of how you can override these options:

EquipmentSlot.actionMenuOptionsGetter = new(x =>
{
    List<ActionMenuOption> options = new();

    options.Add(new ActionMenuOption()
    {
        // Smallcaps is generally used by Inventool for styling purposes but it is not required
        text = $"<smallcaps>Some Action</smallcaps>",
        backgroundColor = new Color(0.3f, 0.3f, 0.3f),
        sortingOrder = 0,
        action = () => { Debug.Log("Do something"); }
    });

    return options;
});

You can call the GetActionMenuOptions method to get the options.

var options = mySlot.GetActionMenuOptions();
PreviousEquipmentNextItems

Last updated 5 months ago

📄