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();

Last updated