65 lines
1.3 KiB
C#
65 lines
1.3 KiB
C#
using UIWidgets;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UIWidgetsSamples
|
|
{
|
|
public class TileViewComponentSample : ListViewItem
|
|
{
|
|
[SerializeField]
|
|
public Image Icon;
|
|
|
|
[SerializeField]
|
|
public Text Name;
|
|
|
|
[SerializeField]
|
|
public Text Capital;
|
|
|
|
[SerializeField]
|
|
public Text Area;
|
|
|
|
[SerializeField]
|
|
public Text Population;
|
|
|
|
[SerializeField]
|
|
public Text Density;
|
|
|
|
public bool SetNativeSize = true;
|
|
|
|
public TileViewSample Tiles;
|
|
|
|
public void Remove()
|
|
{
|
|
Tiles.DataSource.RemoveAt(Index);
|
|
}
|
|
|
|
public void SetData(TileViewItemSample item)
|
|
{
|
|
if (item == null)
|
|
{
|
|
Icon.sprite = null;
|
|
Name.text = string.Empty;
|
|
Capital.text = string.Empty;
|
|
Area.text = string.Empty;
|
|
Population.text = string.Empty;
|
|
Density.text = string.Empty;
|
|
}
|
|
else
|
|
{
|
|
Icon.sprite = item.Icon;
|
|
Name.text = item.Name;
|
|
Capital.text = "Capital: " + item.Capital;
|
|
Area.text = "Area: " + item.Area.ToString("N0") + " sq. km";
|
|
Population.text = "Population: " + item.Population.ToString("N0");
|
|
string text = ((item.Area != 0) ? (Mathf.CeilToInt(item.Population / item.Area).ToString("N") + " / sq. km") : "n/a");
|
|
Density.text = "Density: " + text;
|
|
}
|
|
if (SetNativeSize)
|
|
{
|
|
Icon.SetNativeSize();
|
|
}
|
|
Icon.color = ((!(Icon.sprite == null)) ? Color.white : Color.clear);
|
|
}
|
|
}
|
|
}
|