UGUI事件系統點選響應物件的獲取時機
阿新 • • 發佈:2019-02-13
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才訪問不到。
感覺這些介面表達的含義是,在事件發生時的前一刻。