UGUI检测按钮的按下,抬起,进入,退出
参考网址:https://blog.csdn.net/FransicZhang/article/details/78256753;
该方法需要挂载在button上,特殊情况下,才需要使用.比如,作为视频窗口的连接,鼠标悬浮时播放介绍视频等;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class Test1 : MonoBehaviour,IPointerDownHandler,IPointerUpHandler,IPointerClickHandler,IPointerEnterHandler,IPointerExitHandler
{
private bool isPressBtn = false;//是否按下按钮
public void OnPointerClick(PointerEventData eventData)//跟OnPointUp()效果一样
{
print("click!!!");
}
public void OnPointerEnter(PointerEventData eventData)//鼠标悬浮在按钮上面
{
print("enter!!!");
}
public void OnPointerExit(PointerEventData eventData)//鼠标离开按钮上面
{
print("exit!!!");
}
public void OnPointerUp(PointerEventData eventData)//点击按钮后抬起
{
isPressBtn = false;
print("up!!!");
}
void IPointerDownHandler.OnPointerDown(PointerEventData eventData)//按下按钮
{
isPressBtn = true;
print("down!!!");
}
}