UGUI实现提示工具UITooltip(1)
适用情况:1、按钮的功能提示
2、 文本、表格的展示不完里面的文字时,展示其完整信息。
如何设计:
Panel(UITooltip):提示工具窗口,设计提示工具的样式、背景图片
Text(UITooltip.text):显示文本
Text(TooltipEnableButton ):需要显示提示信息的控件
1、按钮功能提示:当鼠标移动到按钮区域,在其下方显示功能提示;鼠标移出后自动关闭功能提示。
2、完整文本提示:当鼠标移动到按钮区域,在其下方显示功能提示;鼠标移出后自动关闭功能提示。
代码实现:
需要提示的按钮(文本):TooltipEnableButton 继承自Button,因为要通过OnPointerEnter和OnPointerExit来判断鼠标是否进入控件
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class TooltipEnableButton :Button{
public string tipStr="";
private RectTransform rTrsf;
protected override void Awake()
{
base.Awake ();
rTrsf = gameObject.GetComponent<RectTransform> ();
}
public override void OnPointerEnter (UnityEngine.EventSystems.PointerEventData eventData)
{
//屏幕坐标转换为UI坐标
RectTransformUtility.ScreenPointToLocalPointInRectangle (DataExecute.instance.uiParent.GetComponent<RectTransform> (), eventData.position, null,out vec);