public class TestInvoke : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
{
public void OnPointerDown(PointerEventData eventData)
{
Debug.LogFormat("[OnPointerDown]pointerPress:{0}", eventData.pointerPress); //这个时候还是空的
Debug.LogFormat("[OnPointerDown]selectedObject:{0}", eventData.selectedObject);
}
public void OnPointerUp(PointerEventData eventData)
{
Debug.LogFormat("[OnPointerUp]pointerPress:{0}", eventData.pointerPress);
Debug.LogFormat("[OnPointerUp]selectedObject:{0}", eventData.selectedObject);
}
public void OnPointerClick(PointerEventData eventData)
{
Debug.LogFormat("[OnPointerClick]pointerPress:{0}", eventData.pointerPress);
Debug.LogFormat("[OnPointerClick]selectedObject:{0}", eventData.selectedObject);
}
public void OnPointerEnter(PointerEventData eventData)
{
Debug.LogFormat("[OnPointerEnter]pointerPress:{0}", eventData.pointerPress);//这个时候还是空的
Debug.LogFormat("[OnPointerEnter]selectedObject:{0}", eventData.selectedObject);//这个时候还是空的
}
public void OnPointerExit(PointerEventData eventData)
{
Debug.LogFormat("[OnPointerExit]pointerPress:{0}", eventData.pointerPress);//这个时候已经空了
Debug.LogFormat("[OnPointerExit]selectedObject:{0}", eventData.selectedObject);
}
}
通过继承几个点击相关的接口,来打日志看看,点击响应对象何时才能访问到
- pointerPress:顾名思义,发生了press才会访问到,所以在OnPointerEnter、OnPointerExit、OnPointerDown的时候是访问不到的。
- selectedObject:没有press这个限制,所以只有OnPointerEnter才访问不到。
感觉这些接口表达的含义是,在事件发生时的前一刻。