Item View Drawer - Different Empty Item View for Grid by Item View Slot

pleska

New member
I was wondering if there is any creative way of changing the Empty Item View for each Item View Slot in a panel. What I want is a ghosted image of the type of armor in the slot when no armor is present. I guess I could do that by merging my images on top of copies of all of my Item View Slot backgrounds but I was kind of hoping to do it some way by Item Category of armor. Right now they all get the same Empty Item View. It seems like I can override the prefab by Category for the Category Item Views but that doesn't impact the slot when its empty.

I tried putting a fixed Item View Slot for Grid under each of the Item View Slots but those components are removed when the slot is filled including when it is empty.

I guess what I am looking for is something like maybe an ItemViewModule that is displays an specific image when the slot is empty based on an image held in the item category definition?
 
I got it working by creating an ItemViewModule, not sure if this is the best method but at least it worked.


C#:
using Opsive.UltimateInventorySystem.Core.DataStructures;
using Opsive.UltimateInventorySystem.UI.Item.ItemViewModules;
using Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotRestrictions;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// A Item View UI component that lets you bind an icon to the CategoryBackgroundIcon attribute.
/// </summary>
public class CategoryBackgroundIconItemView : ItemViewModule
{
    [Tooltip("The icon image.")]
    [SerializeField] protected Image m_Icon;

    public override void SetValue(ItemInfo info)
    {
        if (info.Item == null || info.Item.IsInitialized == false)
        {
            var parentCategoryRestriction = this.GetComponentInParent<ItemViewSlotCategoryRestriction>();
            if (parentCategoryRestriction != null)
            {
                if (parentCategoryRestriction.ItemCategory.TryGetCategoryAttributeValue<Sprite>("CategoryBackgroundIcon", out var icon))
                {
                    m_Icon.enabled = true;
                    m_Icon.sprite = icon;
                }
                else
                {
                    m_Icon.enabled = false;
                }
                
            }
        }
        else
        {
            m_Icon.enabled = false;
        }
    }

    public override void Clear()
    {
        m_Icon.enabled = false;
    }
}
 
I'm glad you got it working.

Your solution is correct if your Item Views need to be assigned at runtime. (I like your solution I might add something very similar.)

If your Item Views can stay the same for all items that are assigned then you can simply tick the option to not draw Item Views dynamically for your Item View Slot Container.
1611565046593.png
 
Top