using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class SpUI : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler { public Image my_image; public Sprite wendu_normal; public Sprite wendu_selected; public Sprite shidu_normal; public Sprite shidu_selected; public Sprite yangan_normal; public Sprite yangan_selected; public Image expand_image; public Sprite wendu_expand; public Sprite shidu_expand; public Sprite yangan_expand; public TextMeshProUGUI textMeshPro; public Text text; public Color hightC; public Color hightM; public Transform temperatureAndHumidity; public void OnPointerEnter(PointerEventData eventData) { expand_image.gameObject.SetActive(true); switch (TemperatureAndHumidity.current_state) { case "温度": { my_image.sprite = wendu_selected; expand_image.sprite = wendu_expand; textMeshPro.text = transform.parent.parent.parent.GetComponent().eNVList_W.collectResult; text.text = transform.parent.parent.parent.GetComponent().eNVList_W.collectResult; } break; case "湿度": { my_image.sprite = shidu_selected; expand_image.sprite = shidu_expand; textMeshPro.text = transform.parent.parent.parent.GetComponent().eNVList_S.collectResult; text.text = transform.parent.parent.parent.GetComponent().eNVList_S.collectResult; } break; case "烟感": { my_image.sprite = yangan_selected; expand_image.sprite = yangan_expand; textMeshPro.text = transform.parent.parent.parent.GetComponent().eNVList_Y.collectResult; text.text = transform.parent.parent.parent.GetComponent().eNVList_Y.collectResult; } break; default: break; } my_image.SetNativeSize(); } public void OnPointerExit(PointerEventData eventData) { expand_image.gameObject.SetActive(false); switch (TemperatureAndHumidity.current_state) { case "温度": my_image.sprite = wendu_normal; break; case "湿度": my_image.sprite = shidu_normal; break; case "烟感": my_image.sprite = yangan_normal; break; default: break; } my_image.SetNativeSize(); } public void ChangeWSD(string wsd) { string _a = null; string _max = null; string _min = null; switch (TemperatureAndHumidity.current_state) { case "温度": { _a = temperatureAndHumidity.parent.GetComponent().eNVList_W.collectResult; _max = GameManager.Inst.arguments.heatThresholdValueMax; _min = GameManager.Inst.arguments.heatThresholdValueMin; my_image.sprite = wendu_normal; if (string.IsNullOrEmpty(_a)) transform.parent.parent.gameObject.SetActive(false); } break; case "湿度": { _a = temperatureAndHumidity.parent.GetComponent().eNVList_S.collectResult; _max = GameManager.Inst.arguments.humidityThresholdValueMax; _min = GameManager.Inst.arguments.humidityThresholdValueMin; my_image.sprite = shidu_normal; if (string.IsNullOrEmpty(_a)) transform.parent.parent.gameObject.SetActive(false); } break; case "烟感": { _a = temperatureAndHumidity.parent.GetComponent().eNVList_Y.collectResult; my_image.sprite = yangan_normal; if (string.IsNullOrEmpty(_a)) transform.parent.parent.gameObject.SetActive(false); } break; default: break; } if (string.IsNullOrEmpty(_a)) { if (transform.parent.parent.name == "温湿度") { transform.parent.parent.gameObject.SetActive(false); } return; } if (TemperatureAndHumidity.current_state != "烟感") { var a = string.IsNullOrEmpty(_a) ? "0" : _a; var max = string.IsNullOrEmpty(_max) ? "0" : _max; var min = string.IsNullOrEmpty(_min) ? "0" : _min; if (float.Parse(a) > float.Parse(max)) my_image.color = hightC; if (float.Parse(a) < float.Parse(min)) my_image.color = hightM; else my_image.color = new Color(1, 1, 1, 1); } else { if (_a == "正常") { my_image.color = hightC; } else { my_image.color = new Color(1, 1, 1, 1); } } } void Update() { } }