using Assets.Scripts; using Assets.Scripts.Apis.Models; using Assets.Scripts.UI.UIEffect; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class Item : PFUIPanel //, IPointerClickHandler { private Text text; private string Text { get { return text.text; } set { text.text = value; } } private Text km; private string Distance { get { return km.text; } set { km.text = value; } } private Text count; private string Count { get { return count.text; } set { count.text = value; } } public Action onClick; private Transform hot; protected override void Awake() { text = this.transform.Find("name").GetComponent(); km = this.transform.Find("km").GetComponent(); count = this.transform.Find("count").GetComponent(); Material material = null; if (material == null) { material = Instantiate(Resources.Load("UI/Material/RoundedCornersTextureMaterial")); } var rect = ((RectTransform)transform).rect; material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height * 0.5f, 0)); this.GetComponent().material = material; hot = this.transform.Find("Hot"); SetRounded(hot, 17); UIManager.AddEvent(this.gameObject, EventTriggerType.PointerClick, OnPointerClick); } public void Selected(bool value) { if (value) { this.GetComponent().enabled = true; this.GetComponent().color1 = Utils.HexToColor("FF7485"); this.GetComponent().color2 = Utils.HexToColor("F93086"); this.GetComponent().color = Color.white; km.color = Color.white; count.color = Color.white; this.transform.Find("DistanceIcon").GetComponent().color = Color.white; this.transform.Find("BikeIcon").GetComponent().color = Color.white; hot.GetComponent().color1 = Color.white; hot.GetComponent().color2 = Color.white; hot.Find("PFUIText").GetComponent().color = Utils.HexToColor("F93086"); } else { this.GetComponent().enabled = false; this.GetComponent().color = Utils.HexToColor("353543"); km.color = Utils.HexToColor("5C5C6E"); count.color = Utils.HexToColor("F93086"); this.transform.Find("DistanceIcon").GetComponent().color = Utils.HexToColor("5C5C6E"); this.transform.Find("BikeIcon").GetComponent().color = Utils.HexToColor("F93086"); hot.GetComponent().color1 = Utils.HexToColor("FF7485"); hot.GetComponent().color2 = Utils.HexToColor("F93086"); hot.Find("PFUIText").GetComponent().color = Color.white; } } public void SetModel(NearRouteModel model) { this.Text = model.Name; this.Distance = model.Distance.ToString("0.0") + "KM"; this.Count = model.TheHeat.ToString(); hot.gameObject.SetActive(model.IsFire); } // Start is called before the first frame update protected override void Start() { } // Update is called once per frame void Update() { } public void OnPointerClick(BaseEventData eventData) { if(onClick != null) { onClick(); } } }