赞
踩
鼠标停在按钮上,会显示详情介绍提示框,代码如下;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.EventSystems;
-
- /// <summary>
- /// 鼠标悬停于按钮上显示介绍的基类
- /// </summary>
- public class BtnHoverBase : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
- {
- /// <summary>
- /// 鼠标移动到按钮上显示的东西
- /// </summary>
- public GameObject tipsBg { get; set; }
- public Text textTips { get; set; }
-
- private void Awake()
- {
- tipsBg = transform.GetChild(0).gameObject;
- textTips = tipsBg.transform.GetChild(0).GetComponent<Text>();
- }
-
- public void SetValue(string text)
- {
- textTips.text = text;
- }
-
- public void OnPointerEnter(PointerEventData eventData)
- {
- tipsBg.SetActive(true);
- }
-
- public void OnPointerExit(PointerEventData eventData)
- {
- tipsBg.SetActive(false);
- }
- }
这是基类,可以写一个子类代码继承这个基类,设置具体信息,把基类中的Awake()方法删掉,在子类中编写,代码拖给需要显示信息的按钮上,代码如下:
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.EventSystems;
-
- /// <summary>
- /// 鼠标移动到按钮上显示介绍
- /// </summary>
- public class TestButton : BtnHoverBase
- {
-
-
- private void Awake()
- {
- tipsBg = transform.GetChild(0).gameObject;
- textTips = tipsBg.transform.GetChild(0).GetComponent<Text>();
-
-
- textTips.text = "仙剑奇侠传";
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。