skinwalker
Member
Hi,
I have a list of icons depending on if the item is broken or not. I want to have my own scripts to do that, but there are problems
1) IconItemView
This doesnt really do anything but if I place the same code in the main Setvalue method it works.
2) ItemShapeItemView - it works but when I drag my item is invisible
What is the right way to do this? I also replaced the original components on the prefabs with my own. If I edit your scripts with the code I posted it works but I want to inherit from then and override to keep my changes when I update the inventory.
I have a list of icons depending on if the item is broken or not. I want to have my own scripts to do that, but there are problems
1) IconItemView
public class IconItemViewWithIndex : IconItemView
{
public override void SetValue(ItemInfo info)
{
if (info.Item == null || info.Item.IsInitialized == false) {
Clear();
return;
}
m_Icon.enabled = true;
var iconToSet = m_MissingIcon;
if (info.Item.TryGetAttributeValue<List<Sprite>>("Icons", out var icons))
{
if (icons == null || icons.Count == 0)
{
iconToSet = m_MissingIcon;
}
else
{
if (info.Item.TryGetAttributeValue<int>("Index", out var index))
{
iconToSet = icons[index];
}
}
}
m_Icon.sprite = iconToSet;
}
}
This doesnt really do anything but if I place the same code in the main Setvalue method it works.
2) ItemShapeItemView - it works but when I drag my item is invisible
public class ItemShapeItemViewIndex : ItemShapeItemView
{
public override void SetValue(ItemInfo info)
{
if (info.Item == null || info.Item.IsInitialized == false) {
Clear();
return;
}
SetAsItemSelectable(true);
SetIcon(info);
}
/// <summary>
/// Set the icon for the item info.
/// </summary>
/// <param name="info">The item info.</param>
public void SetIcon(ItemInfo info)
{
if (info.Item == null) {
ClearIcon();
return;
}
m_Icon.enabled = true;
Sprite iconToSet = null;
if (info.Item.TryGetAttributeValue<List<Sprite>>(m_ShapeIconAttributeName, out var shapeIcons))
{
if (info.Item.TryGetAttributeValue<int>("Index", out var index))
{
iconToSet = shapeIcons[index];
}
}
if (m_UseBackupIcon && iconToSet == null) {
if (info.Item.TryGetAttributeValue<Sprite>("Icon", out var icon)) {
iconToSet = icon;
}
}
if (iconToSet == null) {
iconToSet = m_MissingIcon;
}
m_Icon.sprite = iconToSet;
ResizeToItemShape(info);
}
}
What is the right way to do this? I also replaced the original components on the prefabs with my own. If I edit your scripts with the code I posted it works but I want to inherit from then and override to keep my changes when I update the inventory.
Last edited: