Unity.EventSystems 네임스페이스에서 Unity는 IPointer 인터페이스를 제공합니다.


인터페이스가 적용되기 위해서는 UI의 경우에는 그래픽레이캐스터가 존재해야하며 Raycast Target이 On이어야 실행되며 3D혹은 2D의 경우에는 Collider가 존재해야 합니다.


IPointer 인터페이스의 종류는 다음과 같습니다.


1. IPointerClickHandler

 - 마우스의 클릭 혹은 터치시에 들어오는 이벤트


1
2
3
4
5
6
7
8
9
10
11
12
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
 
public class TestIPointer : MonoBehaviour , IPointerClickHandler{
 
    public void OnPointerClick(PointerEventData eventData)
    {
        //Click Event
    }    
}
cs


2. IPointerDownHandler

 - 마우스의 다운 혹은 터치다운 시에 들어오는 이벤트


1
2
3
4
5
6
7
8
9
10
11
12
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
 
public class TestIPointer : MonoBehaviour , IPointerDownHandler{
 
    public void OnPointerDown(PointerEventData eventData)
    {
        //Down Event
    }
}
cs


3. IPointerEnterHandler

 - 마우스의 포인터가 충돌범위안에 들어 올때 들어오는 이벤트


1
2
3
4
5
6
7
8
9
10
11
12
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
 
public class TestIPointer : MonoBehaviour , IPointerEnterHandler{
 
    public void OnPointerEnter(PointerEventData eventData)
    {
        //Up Event
    }
}
cs



4. IPointerExitHandler

 - 마우스의 포인터가 충돌범위밖으로 나갈 때 들어오는 이벤트


1
2
3
4
5
6
7
8
9
10
11
12
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
 
public class TestIPointer : MonoBehaviour , IPointerExitHandler{
 
    public void OnPointerExit(PointerEventData eventData)
    {
        //Exit Event
    }
}
cs


5. IPointerUpHandler

 - 마우스의 업 혹은 터치업 시에 들어오는 이벤트


1
2
3
4
5
6
7
8
9
10
11
12
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
 
public class TestIPointer : MonoBehaviour , IPointerUpHandler{
 
    public void OnPointerUp(PointerEventData eventData)
    {
        //Up Event
    }
}
cs



'프로그래밍 > Unity 공부' 카테고리의 다른 글

유니티 뷰포리아 AR 이미지인식  (0) 2018.12.21
Posted by Dongkey
,