76 lines
1.2 KiB
C#
76 lines
1.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UIWidgets
|
|
{
|
|
public class ListViewIconsItemComponent : ListViewItem, IResizableItem
|
|
{
|
|
[SerializeField]
|
|
public Image Icon;
|
|
|
|
[SerializeField]
|
|
public Text Text;
|
|
|
|
public bool SetNativeSize = true;
|
|
|
|
private ListViewIconsItemDescription item;
|
|
|
|
public GameObject[] ObjectsToResize
|
|
{
|
|
get
|
|
{
|
|
return new GameObject[2]
|
|
{
|
|
Icon.transform.parent.gameObject,
|
|
Text.gameObject
|
|
};
|
|
}
|
|
}
|
|
|
|
public ListViewIconsItemDescription Item
|
|
{
|
|
get
|
|
{
|
|
return item;
|
|
}
|
|
}
|
|
|
|
public virtual void SetData(ListViewIconsItemDescription newItem)
|
|
{
|
|
item = newItem;
|
|
if (item == null)
|
|
{
|
|
if (Icon != null)
|
|
{
|
|
Icon.sprite = null;
|
|
}
|
|
Text.text = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
if (Icon != null)
|
|
{
|
|
Icon.sprite = item.Icon;
|
|
}
|
|
Text.text = item.LocalizedName ?? item.Name;
|
|
}
|
|
if (SetNativeSize && Icon != null)
|
|
{
|
|
Icon.SetNativeSize();
|
|
}
|
|
if (Icon != null)
|
|
{
|
|
Icon.color = ((!(Icon.sprite == null)) ? Color.white : Color.clear);
|
|
}
|
|
}
|
|
|
|
public override void MovedToCache()
|
|
{
|
|
if (Icon != null)
|
|
{
|
|
Icon.sprite = null;
|
|
}
|
|
}
|
|
}
|
|
}
|