using UnityEngine; using UnityEngine.UI; using static OrderPanel; public class OrderObj : MonoBehaviour { //已完成背景图 public Sprite imgBk1; //已取消背景图 public Sprite imgBk2; //已完成字体颜色 private string colorZong = "574436"; //已取消字体颜色 private string colorFen = "B67687"; //支付中字体颜色 private string colorLv = "63B900"; //背景 public Image imgBk; //商品Id public Text txtId; //支付状态 public Text txtFinish; public void UpdatePanel(OrderList order) { txtId.text = order.productId + "\n" + order.createTime; switch (order.payStatus) { case 0: txtFinish.text = "支付中"; txtFinish.color = HexToColor(colorLv); imgBk.sprite = imgBk1; break; case 1: txtFinish.text = "已完成"; txtFinish.color = HexToColor(colorZong); imgBk.sprite = imgBk1; break; case 2: txtFinish.text = "已取消"; txtFinish.color = HexToColor(colorFen); imgBk.sprite = imgBk2; break; } } // 将十六进制颜色转换为 Color private Color HexToColor(string hex) { byte r = byte.Parse(hex.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); byte g = byte.Parse(hex.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); byte b = byte.Parse(hex.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); return new Color32(r, g, b, 255); } }