게임/Unity3D

[Unity3D][EZ GUI] UIButton Event 처리 방식

Binceline 2012. 11. 5. 18:17

참고 : http://www.devkorea.co.kr/bbs/board.php?bo_table=m03_qna&wr_id=17183

----------------


EZ GUI에서 버튼의 터치 이벤트를 처리할 때, UIButton의 inspector창의 설정으로 터치 입력 설정을 하는 것 보다는 델리게이트 함수로 이벤트 처리를 하는 것이 더 정확하고 빠르다고 한다. 다음은 소스 코드이다.


using UnityEngine;

using System.Collections;


public class CUIButton : MonoBehaviour 

{

// Use this for initialization

void Start () 

{

buttons.AddInputDelegate(ButtonDelegate);

}

// Update is called once per frame

void Update () {

}

void ButtonDelegate(ref POINTER_INFO ptr)

{

if (ptr.evt == POINTER_INFO.INPUT_EVENT.PRESS ) 

{

Debug.Log("PRESSED"); 

}


if ((ptr.evt == POINTER_INFO.INPUT_EVENT.RELEASE) || 

(ptr.evt == POINTER_INFO.INPUT_EVENT.TAP) || 

(ptr.evt == POINTER_INFO.INPUT_EVENT.RELEASE_OFF))

{

Debug.Log(ptr.evt);

}

}

public UIButton buttons;

}


반응형