using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; public class TipShower : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler { public RectTransform tips; public string data; public void OnPointerEnter(PointerEventData eventData) { currentShower = this; tips.anchoredPosition = this.GetComponent().anchoredPosition; tips.gameObject.SetActive(true); tips.GetComponentInChildren().text = data; LayoutRebuilder.ForceRebuildLayoutImmediate(tips.GetChild(0).GetComponent()); ; // 强制重新计算布局 LayoutRebuilder.ForceRebuildLayoutImmediate(tips.GetComponent()); // 强制重新计算布局 } public static TipShower currentShower = null; public void OnPointerExit(PointerEventData eventData) { if (currentShower == this) { tips.gameObject.SetActive(false); currentShower = null; } } }