Hover Details

Scripting with the InventoolHoverDetails class.

The InventoolHoverDetails class is a mini pop-up window that displays item details.

Fields & Properties

Name
Description
Type
Access

document

The UI document.

UIDocument

protected

root

The root of the content.

VisualElement

protected

topBackgroundElement

The element used to display the top background.

VisualElement

protected

imageElement

The element used to display the item image.

VisualElement

protected

itemNameLabel

The label that displays the item name.

Label

protected

itemTypeLabel

The label that displays the item type.

Label

protected

descriptionScrollView

The scroll view that contains the description.

ScrollView

protected

descriptionLabel

The label that displays the description.

Label

protected

statsScrollView

The scroll view that displays all stats.

ScrollView

protected

weightArea

The element that contains weight content.

VisualElement

protected

weightLabel

The label that displays the item's weight.

Label

protected

currencyIconElement

The element that displays the currency icon.

VisualElement

protected

currencyLabel

The label that displays the currency amount.

Label

protected

appearanceDelay

The length of time the user must hover an item for the details to display.

float

public

autoScrollDelay

The automatic scrolling delay when the scroll view reaches the beginning or end.

float

protected

descriptionAutoScrollSpeed

The automatic scrolling speed of the description scroll view.

float

protected

statsAutoScrollSpeed

The automatic scrolling speed of the stats scroll view.

float

protected

autoScrollDescriptionToEnd

If the description auto scroll is currently scrolling to the end.

bool

protected

autoScrollStatsToEnd

If the stats auto scroll is currently scrolling to the end.

bool

protected

openAction

The open action.

Action

protected

transitionState

The current transition state.

TransitionState

protected

TargetElement

The element currently being targetted.

VisualElement

public

IsOpen

If the hover details is currently open.

bool

public

Active Instance

You can get the active InventoolHoverDetails instance with InventoolHoverDetails.Instance. Ensure there's an instance of it in your scene before using this field.

Open

Opening the hover details essentially requires a VisualElement target. By default, Inventool has special UI elements that hold a reference to an item, which is used by the InventoolHoverDetails class to both open at the location of the UI element and also display the item details. So, it's not as easy as just calling an Open method.

// This may only open the hover details without setting the item
InventoolHoverDetails.Instance.Open(myVisualElement);

Close

InventoolHoverDetails.Instance.Close();

Customizations

If you're okay with when the InventoolHoverDetails is opened, but not okay with the information displayed, you can customize it.

Step 1: Create a New Class

Create a new class that inherits from InventoolHoverDetails. In your scene, replace the Hover Details component with the new one you created.

using Esper.Inventool.UI;

public class MyHoverDetails : InventoolHoverDetails
{
    
}

Step 2: Override Methods

Override the four Open methods as shown below. Each one opens the hover details for a different UI item element (each UI element has a reference to an item).

using Esper.Inventool.UI;

public class MyHoverDetails : InventoolHoverDetails
{
    // For inventory slots
    public override void Open(ItemStackElement target)
    {
        base.Open(target);
    }
    
    // For equipment slots
    public override void Open(EquipmentSlotElement target)
    {
        base.Open(target);
    }

    // For other purposes (enchanting, crafting)
    public override void Open(ItemSlotElement target)
    {
        base.Open(target);
    }
    
    // For shop items
    public override void Open(ShopItemElement target)
    {
        base.Open(target);
    }
}

Step 3: Implement Your Customizations

In the code example below, we're going to customize the description displayed when an inventory item is hovered with a custom scriptable object.

using Esper.Inventool.UI;

public class MyHoverDetails : InventoolHoverDetails
{
    public override void Open(ItemStackElement target)
    {
        base.Open(target);

        var myCustomClass = (MyCustomClass)target.itemStack.item.customObject;
        descriptionLabel.text = myCustomClass.myCustomDescription;
    }

    public override void Open(EquipmentSlotElement target)
    {
        base.Open(target);
    }

    public override void Open(ItemSlotElement target)
    {
        base.Open(target);
    }

    public override void Open(ShopItemElement target)
    {
        base.Open(target);
    }
}

Last updated