본문 바로가기

Study/Unity3D

NGUI 버튼 클릭 이벤트

UIbutton Message는 외부 스크립트를 찾아서 실행것이고 
아래 내용은 버튼에서 직접 실행하는 것.

버튼으로 사용할 것에 콜라이더(Collider)가 붙어 있어야  작동함. 
  • void OnHover (bool isOver) – Sent out when the mouse hovers over the collider or moves away from it.Not sent on touch-based devices.
  • 마우스 오버일 경우에 작동, 터치에서는 안먹음
  • void OnPress (bool isDown) – Sent when a mouse button (or touch event) gets pressed over the collider (with ‘true’) and when it gets released (with ‘false’, sent to the same collider even if it’s released elsewhere).
  • 버튼을 누르고 있는 경우

  • void OnClick() — Sent to a mouse button or touch event gets released on the same collider as OnPress. UICamera.currentTouchID tells you which button was clicked.
  • 버튼 클릭

  • void OnDoubleClick () — Sent when the click happens twice within a fourth of a second. UICamera.currentTouchID tells you which button was clicked.
  • 더블클릭

  • void OnSelect (bool selected) – Same as OnClick, but once a collider is selected it will not receive any further OnSelect events until you select some other collider.
  • OnClick()과 같지만 다른 콜라이더를 선택할때 까지는 OnSelect()를 다시 호출 하지 않는다.
  • 버튼 눌러서 다른 작업해야할때 유용함.

  • void OnDrag (Vector2 delta) – Sent when the mouse or touch is moving in between of OnPress(true) and OnPress(false).
  • OnPress(true) 에서 OnPress(false) 순간까지의 델타 벡터값 반환, 드레그 중인지 알아야 할때.
  • void OnDrop (GameObject drag) – Sent out to the collider under the mouse or touch when OnPress(false) is called over a different collider than triggered the OnPress(true) event. The passed parameter is the game object of the collider that received the OnPress(true) event.
  • 드레그종료(OnPress(false))할때 오버된 다른 오브젝트 콜라이더의 OnPress(true)를 실행 시킴.
  • void OnInput (string text) – Sent to the same collider that received OnSelect(true) message after typing something. You likely won’t need this, but it’s used by UIInput
  • 문자열 보내주는건데 잘 쓰지는 않을듯

  • void OnTooltip (bool show) – Sent after the mouse hovers over a collider without moving for longer thantooltipDelay, and when the tooltip should be hidden. Not sent on touch-based devices.
  •  툴팁 보여줄때 사용하라는 것, 툴팁 UI까지 만들어 주지는 않음. 터치에서는 안먹음
  • void OnTooltip(bool show){
  • Debug.Log("tooltip open");
  • }

  • void OnScroll (float delta) is sent out when the mouse scroll wheel is moved.
  •  마우스 스크롤 델타값 출력, 휠스크롤 순간에만 값을 출력함.  0.1,  -0.1 같이, 마우스마다 다른지는 모름
  • void OnScroll(float delta){
  • Debug.Log(delta);
  • }

  • void OnKey (KeyCode key) is sent when keyboard or controller input is used.
  •  키값 받아서 작동하는 거,  
  • 사용은 
  • void OnKey(KeyCode a){
  • Debug.Log("a click?");

출처 : http://quest3dkorea.com/m/11050815