1、背景:鼠标悬浮在UI上出现提示框
cs
public class SpecialParam_list : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
public void OnPointerEnter(PointerEventData eventData)
{
TipBox.Instance.ShowBox(Input.mousePosition, value);
}
public void OnPointerExit(PointerEventData eventData)
{
TipBox.Instance.HideBox();
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TipBox : UnitySingleton<TipBox>
{
SpecialFyALand_Panel fyALand_Panel;
GameObject tioObj;
public float offset = 1;
[SerializeField]
private float threshold = 1f;
public void ShowBox(Vector2 pos, string ac )
{
if (tioObj == null)
{
tioObj = ResMgr.GetInstance().Load<GameObject>("TipBox", ResourcesType.UIPrefabs);
tioObj.transform.SetParent(GameObject.Find("Canvas").transform);
tioObj.transform.SetAsLastSibling();
}
TipBoxInfo tipBoxInfo = tioObj.GetComponent<TipBoxInfo>();
tipBoxInfo.InitData( ac );
tioObj.SetActive(true);
tioObj.transform.SetAsLastSibling();
tipBoxInfo.transform.position = new Vector2(pos.x, pos.y) + new Vector2(0, 0) * offset;
//tipBoxInfo.transform.position = new Vector3(pos.x, pos.y, 0) + new Vector3(963, 539, 0) * offset;
}
public void HideBox()
{
if (tioObj != null&& tioObj.activeSelf)
tioObj.SetActive(false);
}
}
2、鼠标一旦出现在图片边缘弹框就会不停的闪烁
3、解决方案:将弹框包含所有的物体的RaycastTarget去掉
PS:个人猜测原因是弹窗的移入导致出发了pointenter事件