NGUI: Events(Event Functions)
Unity3D/NGUI / 2012. 12. 7. 13:42
NGUI의 이벤트 함수를 SendMessage로 호출하려고 함수 원형을 찾아보고 올려놓음.
UICamera sends out the following events to colliders:
- OnHover (isOver) is sent when the mouse hovers over a collider or moves away.
- OnPress (isDown) is sent when a mouse button gets pressed on the collider.
- OnSelect (selected) is sent when a mouse button is first pressed on a game object. Repeated presses on the same object won't result in a new OnSelect.
- OnClick () is sent with the same conditions as OnSelect, with the added check to see if the mouse has not moved much. UICamera.currentTouchID tells you which button was clicked.
- OnDoubleClick () is sent when the click happens twice within a fourth of a second. UICamera.currentTouchID tells you which button was clicked.
- OnDragStart () is sent to a game object under the touch just before the OnDrag() notifications begin.
- OnDrag (delta) is sent to an object that's being dragged.
- OnDragOver (draggedObject) is sent to a game object when another object is dragged over its area.
- OnDragOut (draggedObject) is sent to a game object when another object is dragged out of its area.
- OnDragEnd () is sent to a dragged object when the drag event finishes.
- OnInput (text) is sent when typing (after selecting a collider by clicking on it).
- OnTooltip (show) is sent when the mouse hovers over a collider for some time without moving.
- OnScroll (float delta) is sent out when the mouse scroll wheel is moved.
- OnKey (KeyCode key) is sent when keyboard or controller input is used.
To tap into them in your own custom scripts, simply create a script with the appropriate function, such as:
- void OnPress (bool isPressed)
- {
- if (isPressed) Debug.Log("I was pressed on!");
- else Debug.Log("I was unpressed");
- }
Pro-Tip #2
You can subscribe to events from any script using delegates: UICamera.onClick, UICamera.onHover, etc. These delegates will be called just before the actual notification gets sent to the proper object. You can use this functionality to listen in for events on a script regardless of whether they would be going to that script's game object or not.
Class Documentation
http://tasharen.com/ngui/docs/class_u_i_camera.html
If you have a question regarding this component or would like me to clarify something, just post a reply here.
- void OnPress (bool isPressed)
- {
- if (isPressed) Debug.Log("I was pressed on!");
- else Debug.Log("I was unpressed");
- }
반응형
'Unity3D > NGUI' 카테고리의 다른 글
해상도에 맞게 UI 위치 조절 (0) | 2013.01.04 |
---|---|
해상도에 맞게 UI Scale (0) | 2013.01.04 |
NGUI Virtual Joystick (1) | 2012.12.05 |
스크롤/드래그 이벤트를 받는 방법 (0) | 2012.11.13 |
유니티 NGUI 에서 라벨에 한글(폰트) 적용하기 (2) | 2012.11.05 |