Files
Simulation/Assets/UILogicListItem.cs

37 lines
1.3 KiB
C#

using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class UILogicListItem : MonoBehaviour
{
private Image Image_Count;
private TextMeshProUGUI Text_LabelCount;
private TextMeshProUGUI Text_Label;
private TextMeshProUGUI Text_Count;
private RectTransform rect;
public RectTransform Rect { get { return rect; } }
private void Awake()
{
var images = transform.GetComponentsInChildren<Image>();
Image_Count= images.FirstOrDefault(x=>x.name.Equals(nameof(Image_Count)));
var textpros = transform.GetComponentsInChildren<TextMeshProUGUI>();
Text_LabelCount = textpros.FirstOrDefault(x => x.name.Equals(nameof(Text_LabelCount)));
Text_Label = textpros.FirstOrDefault(x => x.name.Equals(nameof(Text_Label)));
Text_Count = textpros.FirstOrDefault(x => x.name.Equals(nameof(Text_Count)));
rect = GetComponent<RectTransform>();
}
public void SetItem(string labelCount, string label, string count)
{
if (Text_LabelCount == null)
return;
Text_LabelCount.SetText(labelCount);
Text_Label.SetText(label);
Text_Count.SetText(count);
rect.transform.localPosition = new Vector2(rect.localPosition.x, -60f * int.Parse(labelCount));
}
}