Item View

Item Views are used to display an Item in the UI.

Item Views can easily be setup using UI Designer Item View tab

Item Views are often paired with an Item View Slot to detect selection, clicks and more. Find more about Item View Slots here

 

Item View Modules

Creating a custom Item View Module is possible, simply Inherit the Item View Module base class

Example:

 

/// <summary>
/// An item box component to display an amount.
/// </summary>
public class AmountItemView : ItemViewModule
{
    [Tooltip("The amount text.")]
    [SerializeField] protected Text m_AmountText;
    [Tooltip("Do not show amount if it is 1 or lower.")]
    [SerializeField] protected bool m_HideAmountIfSingle;

    /// <summary>
    /// Set the value.
    /// </summary>
    /// <param name="info">The item info.</param>
    public override void SetValue(ItemInfo info)
    {
        if (m_HideAmountIfSingle && info.Amount <= 1) {
            m_AmountText.text = "";
        } else {
            m_AmountText.text = $"x {info.Amount}";
        }
    }

    /// <summary>
    /// Clear the value.
    /// </summary>
    public override void Clear()
    {
        m_AmountText.text = "";
    }
}

There are some special Item View Modules abstract classes and Interfaces which are very useful when creating custom Item View modules

  • IInventoryDependent: This ensures that the Item View Module can have an external Inventory referenced. Example: “Amount Comparison Item View”
  • IViewModuleSelectable: receive Select events from the Item View. Example: “Equipped Select Item View”
  • IItemViewSlotDropHoverSelectable: receive Hover events from the Item View Drophandler. Example: “Drop Hover Icon Preview Item View”

 

Some of the most popular Item View Modules include (Use UI Designer to see all of the options):

Select Image View

Generic box component which changes the sprite of an image depending on the selection state of the box.

Name Item View

Displays the name of the item.

Icon Item View

Displays the item’s “Icon” attribute value.

Amount Item View

Displays the number of items that the inventory contains.

Equipped Select Item View

Changes the image depending on the Item Collection that the item belongs to. This can be used to show if an item is equipped.

Int Attribute Item View

Displays the value of the integer attribute.

Item Slots Item View

Enables or disables GameObjects depending on the Item Collection that the item belongs to. This can be used to show if an item is equipped.

Item Shape Item View

A special Item View Modules required when using an Item Shape Grid.

Cooldown Item View

Show the cooldown of an Item used by the Use Item Action Set Attribute item action.