namespace UIWidgets.Examples { using UIWidgets; using UnityEngine; using UnityEngine.UI; /// /// TableRow component. /// public class TableRowComponent : ListViewItem, IViewData { /// /// Cell01Text. /// [SerializeField] [HideInInspector] [System.Obsolete("Replaced with Cell01TextAdapter.")] public Text Cell01Text; /// /// Cell02Text. /// [SerializeField] [HideInInspector] [System.Obsolete("Replaced with Cell02TextAdapter.")] public Text Cell02Text; /// /// Cell03Image. /// [SerializeField] public Image Cell03Image; /// /// Cell04Text. /// [SerializeField] [HideInInspector] [System.Obsolete("Replaced with Cell04TextAdapter.")] public Text Cell04Text; /// /// Cell01Text. /// [SerializeField] public TextAdapter Cell01TextAdapter; /// /// Cell02Text. /// [SerializeField] public TextAdapter Cell02TextAdapter; /// /// Cell04Text. /// [SerializeField] public TextAdapter Cell04TextAdapter; TableRow Item; /// /// Init graphics foreground. /// protected override void GraphicsForegroundInit() { if (GraphicsForegroundVersion == 0) { Foreground = new Graphic[] { UtilitiesUI.GetGraphic(Cell01TextAdapter), UtilitiesUI.GetGraphic(Cell02TextAdapter), UtilitiesUI.GetGraphic(Cell04TextAdapter), }; GraphicsForegroundVersion = 1; } } /// /// Init graphics background. /// protected override void GraphicsBackgroundInit() { if (GraphicsBackgroundVersion == 0) { graphicsBackground = Compatibility.EmptyArray(); GraphicsBackgroundVersion = 1; } } /// /// Gets the objects to resize. /// /// The objects to resize. public GameObject[] ObjectsToResize { get { return new GameObject[] { Cell01TextAdapter.transform.parent.gameObject, Cell02TextAdapter.transform.parent.gameObject, Cell03Image.transform.parent.gameObject, Cell04TextAdapter.transform.parent.gameObject, }; } } /// /// Set data. /// /// Item. public void SetData(TableRow item) { Item = item; Cell01TextAdapter.text = Item.Cell01; Cell02TextAdapter.text = Item.Cell02.ToString(); Cell03Image.sprite = Item.Cell03; Cell04TextAdapter.text = Item.Cell04.ToString(); // set transparent color if no icon Cell03Image.color = (Cell03Image.sprite == null) ? Color.clear : Color.white; } /// /// Handle cell clicked event. /// /// Cell name. public void CellClicked(string cellName) { Debug.Log(string.Format("clicked row {0}, cell {1}", Index.ToString(), cellName)); switch (cellName) { case "Cell01": Debug.Log(string.Format("cell value: {0}", Item.Cell01)); break; case "Cell02": Debug.Log(string.Format("cell value: {0}", Item.Cell02.ToString())); break; case "Cell03": Debug.Log(string.Format("cell value: {0}", Item.Cell03)); break; case "Cell04": Debug.Log(string.Format("cell value: {0}", Item.Cell04.ToString())); break; default: Debug.Log("cell value: "); break; } } /// /// Upgrade this instance. /// public override void Upgrade() { #pragma warning disable 0612, 0618 Utilities.GetOrAddComponent(Cell01Text, ref Cell01TextAdapter); Utilities.GetOrAddComponent(Cell02Text, ref Cell02TextAdapter); Utilities.GetOrAddComponent(Cell04Text, ref Cell04TextAdapter); #pragma warning restore 0612, 0618 } } }