Storage

Scripting with the Storage class.

Fields & Properties

Name
Description
Type
Access

id

The storage ID.

string

public

navigation

The navigation type.

Vault.Navigation

public

isInfinite

If the storage is infinite.

bool

public

currentPage

The current page number.

int

public

maxPages

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

int

public

minPageSize

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

Vector2Int

public

pageSize

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

Vector2Int

public

itemStacks

A list of all items stacks in the storage.

List<ItemStack>

public

currencies

A list of stored currencies.

List<Currency>

public

itemSlots

A list of all item slots.

ItemSlot[]

public

orderMode

The order mode of the items.

Vault.OrderMode

public

activeItemTypeFilter

The active item type filter.

ItemType

public

PageSlotCount

The number of total slots per page.

int

public

TotalSlotCount

The number of total slots, combining all slots in all pages.

int

public

AllowItemDropping

If item dropping should be allowed. Taken from the inventory.

bool

public

ShowSubtypes

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

bool

public

DeleteItemsOnDrop

If the item should be deleted on drop. Taken from the inventory.

bool

public

NoFilterIcon

The icon of the no filter button. Taken from the inventory.

Sprite

public

NoFilterIconColorTint

The color tint of the no filter icon. Taken from the inventory.

Color

public

Items

Setting Items

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

myStorage.SetItems(myItemStackList);

Depositing Items

With the Deposit method, you can add a single or a list of item stacks to the storage. This will remove the item(s) from the inventory.

myStorage.Deposit(myItemStack);

Remove Items

With the Withdraw method, you can remove a single or a list of item stacks from the storage. This will add the item(s) to the inventory.

myStorage.Withdraw(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 = myStorage.GetAllItemsInPage(0);

Get All Items in the Current Page

var itemStacks = myStorage.GetAllItemsInCurrentPage();

Checking If An Item Can Fit

You can check if an item will fit in the storage 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 storage. 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 = myStorage.Contains("Door Key");

Drop Items

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

myStorage.DropItem(itemStackToDrop);

Currencies

In the examples below, amount is a Currency. You can access the full list of currencies with the myStorage.currencies field.

Depositing a Currency

A currency can be deposited with the Deposit method.

myStorage.Deposit(myCurrency);

Withdrawing a Currency

A currency can be withdrawn from the storage with the Withdraw method.

myStorage.Withdraw(myCurrency);

Resetting

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

myStorage.ResetCurrencies();

Pages & Organization

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

Reorganization

You can reorganize the storage with the Reorganize method.

myStorage.Reorganize();

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

myStorage.Regroup();

Filters

Storage 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

myStorage.SetItemFilter(ItemType);

Remove Item Filter

myStorage.RemoveItemFilter();

Page Sizes

Setting the Size

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

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

Recalculating the Size

Page sizes may need to be recalculated when the storage is infinite, navigation is set to scrolling, and new items are added. Call the RecalculatePageSize method for this purpose. This will update the pageSize field automatically.

myStorage.RecalculatePageSize();

Pagination

Current Page

The current page number is stored in the currentPage field.

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

myStorage.NextPage();

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

myStorage.PreviousPage();

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

myStorage.SetPage(0);

Recalculate Required Pages

The maxPages field is an integer that stores the max number of pages that the storage has. The pages can be limited or unlimited (this can be set from the Storage). In the case they are unlimited, the maxPages field may need to be recalculated at times. You can call RecalculateRequiredPages for this purpose.

myStorage.RecalculateRequiredPages();

Minimum Required Pages

You can get the minimum required pages to fit all items with the MinimumRequiredPages method.

int min = myStorage.MinimumRequiredPages();

Last updated