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
  • Accessing the Inventory
  • Fields & Properties
  • Dismantling
  • Items
  • Setting Items
  • Adding Items
  • Remove Items
  • Getting Items
  • Checking Items
  • Using Items
  • Pick Up Items
  • Drop Items
  • Currencies
  • Spending
  • Earning
  • Sufficient Funds Checking
  • Resetting
  • Weights
  • Max Weight
  • Total Item Weight
  • Checking If An Item Will Exceed the Weight
  • Pages & Organization
  • Reorganization
  • Filters
  • Page Sizes
  • Pagination
  • Customize Accepted Items
  1. Scripting API

Inventory

Scripting with the Inventory class.

The Inventory class serves as the settings and functionality for the player's inventory. All fields listed in the Inventory tab of the Inventool editor window are public and can be changed at runtime.

NOTE: Runtime edits of the inventory are not saved automatically. This would need to be done manually.

When making edits to the inventory, relevant parts of the Inventool Window may need to be refreshed.

Accessing the Inventory

You can access the player's inventory with Inventool.Inventory.

Fields & Properties

Name
Description
Type
Access

navigation

The navigation type.

Navigation

public

isInfinite

If the vault is infinite.

bool

public

pages

A list of grid pages.

List<Grid>

private

currentPage

The current page number.

int

public

pageSize

The size of each page. This is only relevant if navigation is not set to scrolling and the vault is not infinite.

Vector2Int

public

minPageSize

The minimum size of the page. This is only relevant if navigation is set to scrolling and the vault is infinite.

Vector2Int

public

pageSizeRuntime

The number of pages calculated at runtime.

Vector2Int

public

maxPages

The max number of pages. This is only relevant if the navigation type is set to pagination and the vault is not infinite.

int

public

itemStacks

A list of all items stacks in the vault. For the inventory, use SetItems, AddItems, or RemoveItems to change the list instead of editing the list itself.

List<ItemStack>

public

filteredItemStacks

The item stacks with the active item type filter applied.

List<ItemStack>

public

keyItems

A list of key items separated from the main item stack list. This is only relevant if enableKeyItems is set to true.

List<ItemStack>

public

currencies

A list of stored currencies.

List<Currency>

public

activeItemTypeFilter

The active item type filter.

ItemType

public

canAcceptItem

A function that can be used to limit the items that the inventory can accept.

Func<ItemStack, bool>

public

PageCount

The number of pages calculated at runtime.

int

public

PageSlotCount

The total number of slots on a single page.

int

public

SlotCount

The total number of slots.

int

public

enableEquipment

If the inventory's character equipment section should be enabled.

bool

public

enableFreeCrafting

If free crafting should be enabled.

bool

public

enableFreeEnchanting

If free enchanting should be enabled.

bool

public

enableKeyItems

If the key items should be enabled. If this is enabled, key items will have their own section in the UI and will not contribute to weight.

bool

public

useWeights

If the inventory should use weights.

bool

public

enableDismantling

If item dismantling should be enabled.

bool

public

totalItemWeight

The current weight of all items. This is the cached value since the last time RecalculateTotalWeight was used.

float

public

maxWeight

The max number of item weight the inventory can hold.

float

public

disallowNewItemsIfMaxWeight

If the player should not be able to obtain new items if the weight has reached the max value.

bool

public

showSubtypeInKeyItemsTab

If the details in the key items tab should display subtype names.

bool

public

allowItemDropping

If item dropping should be allowed.

bool

public

showSubtypes

If item subtypes should be displayed in the inventory filter list.

bool

public

deleteItemsOnDrop

If the item should be deleted on drop.

bool

public

enchantingSlotLeftIcon

The icon of the left enchanting slot.

Sprite

public

enchantingSlotRightIcon

The icon of the right enchanting slot.

Sprite

public

enchantingSlotLeftIconTint

The color tint of the left enchanting slot.

Color

public

enchantingSlotRightIconTint

The color tint of the right enchanting slot.

Color

public

noFilterIcon

The icon of the no filter button.

Sprite

public

noFilterIconColorTint

The color tint of the no filter icon.

Color

public

preventAddedItemEvents

Prevents events invoked when adding items.

bool

private

MaxWeightExceeded

If the total item weight is greater than the max weight.

bool

public

Dismantling

You can use the Dismantle method to dismantle an item. This will remove an item stack from the inventory and add it's dismantle result items to the inventory.

Inventool.Inventory.Dismantle(myItemStack);

It's important to note that dismantling may not always work, which is why the method returns true or false.

if (Inventool.Inventory.Dismantle(myItemStack))
{
    Debug.Log("Dismantled");
}

Items

Setting Items

You can set items with the SetItems method. This will remove all previous items in the inventory.

Inventool.Inventory.SetItems(myItemStackList);

Adding Items

With the AddItems method, you can add a single or a list of item stacks to the inventory.

Inventool.Inventory.AddItems(myItemStack);

Remove Items

With the RemoveItems method, you can remove a single or a list of item stacks from the inventory.

Inventool.Inventory.RemoveItems(myItemStack);

Getting Items

You can get the full list of items with the itemStacks and keyItems fields.

Get All Items in a Specific Page

// Get item stacks in the first page (page numbers start at 0)
var itemStacks = Inventool.Inventory.GetAllItemsInPage(0);

Get All Items in the Current Page

var itemStacks = Inventool.Inventory.GetAllItemsInCurrentPage();

Checking If An Item Can Fit

You can check if an item will fit in the inventory with the HasSpaceForItem method.

bool result = Inventool.Inventory.HasSpaceForItem(myItem);

Checking Items

You can use the Contains method to check and see if the player has an instance of an item in their inventory. You can use an Item object, the item ID, or the item name to perform this check.

// Check if the player has an item called 'Door Key'
bool result = Inventool.Inventory.Contains("Door Key");

Using Items

Items in the inventory can be used with the UseItem method. Used items are removed from the inventory.

Inventool.Inventory.UseItem(itemToUse);

Pick Up Items

Pick up methods simply remove an Item Drop from the game world and add an instance of an Item Stack to the player's inventory.

PickUpAllItemsInRange method picks up all items that the player is in range of in the game world.

Inventool.Inventory.PickUpAllItemsInRange();

To pick up a single item, use PickUpItem.

Inventool.Inventory.PickUpItem(itemToPickUp);

Drop Items

To drop a specific item (remove it from the inventory), use the DropItem method. This may create an instance of an Item Drop in the game world.

Inventool.Inventory.DropItem(itemStackToDrop);

Currencies

In the examples below, cost is a Currency. You can access the full list of currencies with the Inventool.Inventory.currencies field.

Spending

A currency can be spent with the TrySpend method. This method returns a bool. False will be returned if the player doesn't have enough of the specific currency. Otherwise, it will return true.

bool result = Inventool.Inventory.TrySpend(cost);

Earning

You can add an amount to a player's currency with the TryEarn method. While this method returns a bool, it should always return true unless the specific currency type does not exist in the inventory.

bool result = Inventool.Inventory.TryEarn(cost);

Sufficient Funds Checking

You can check if the player has enough of a particular currency with the HasEnoughCurrency method and providing a cost parameter.

bool sufficientFunds = Inventool.Inventory.HasEnoughCurrency(cost);

Resetting

You can reset all currencies to their starting values with the ResetCurrencies method.

Inventool.Inventory.ResetCurrencies();

Weights

Weights are only relevant if the useWeights field is set to true.

Max Weight

You can get and set the max weight with the maxWeight field.

Inventool.Inventory.maxWeight = 100;

Total Item Weight

To get the total weight of all items in the inventory, use RecalculateTotalWeight.

float totalWeight = Inventool.Inventory.RecalculateTotalWeight();

Checking If An Item Will Exceed the Weight

Sometimes it may be necessary to check if an item will cause the max weight to be exceeded. You can use the ItemWillExceedWeightLimit method for this purpose.

bool result = Inventool.Inventory.ItemWillExceedWeightLimit(myItem);

Pages & Organization

Inventory items are organized in grid-based pages. Whether your inventory 1 page or 100, the logic is the same.

Reorganization

You can reorganize the inventory with the Reorganize method. This will also recreate all pages.

Inventool.Inventory.Reorganize();

If you'd only like to regroup item stacks, use the Regroup method.

Inventool.Inventory.Regroup();

Filters

Inventory items can be filtered with Item Type. Items that don't match the filter will not be returned when using the GetAllItemsInPage or GetAllItemsInCurrentPage methods. If the ItemType is a parent, items with the parent type or any of it's child types will not be filtered out.

Set the Item Filter

Inventool.Inventory.SetItemFilter(ItemType);

Remove Item Filter

Inventool.Inventory.RemoveItemFilter();

Page Sizes

Setting the Size

You can set the page size by editing the minPageSize or pageSize fields. When these are changed, the inventory may need to be reorganized.

// 6x6 inventory grid
Inventool.Inventory.pageSize = new Vector2Int(6, 6);
Inventool.Inventory.Reorganize();

Pagination

Current Page

The current page number is stored in the currentPage field.

You can flip to the next page with the NextPage method.

Inventool.Inventory.NextPage();

Similarly, you can flip to the previous page with PreviousPage method.

Inventool.Inventory.PreviousPage();

Alternatively, you can set the current page (page numbers start at 0).

Inventool.Inventory.SetPage(0);

Customize Accepted Items

You can customize the items accepted with the canAcceptItem function.

Example

// Only accept key items
Inventool.Inventory.canAcceptItem = itemStack =>
{
    if (itemStack.IsKeyItem)
    {
        return true;
    }

    return false;
};
PreviousInitializationNextEquipment

Last updated 19 days ago

📄