using UnityEngine; using UnityEngine.UI; using System; using System.Collections.Generic; namespace UIWidgets { /// /// ListViewIcons item component. /// [AddComponentMenu("UI/UIWidgets/ListViewIconsItemComponent")] public class ListViewIconsItemComponent : ListViewItem, IResizableItem { /// /// Gets the objects to resize. /// /// The objects to resize. public GameObject[] ObjectsToResize { get { return new GameObject[] {Icon.transform.parent.gameObject, Text.gameObject}; } } /// /// The icon. /// [SerializeField] public Image Icon; /// /// The text. /// [SerializeField] public Text Text; /// /// Set icon native size. /// public bool SetNativeSize = true; ListViewIconsItemDescription item; /// /// Gets the current item. /// /// Current item. public ListViewIconsItemDescription Item { get { return item; } } /// /// Sets component data with specified item. /// /// 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(); } //set transparent color if no icon if (Icon!=null) { Icon.color = (Icon.sprite==null) ? Color.clear : Color.white; } } /// /// Called when item moved to cache, you can use it free used resources. /// public override void MovedToCache() { if (Icon!=null) { Icon.sprite = null; } } } }