관리 메뉴

그냥한다

유니티VR - CastEventToUI.cs 본문

유니티

유니티VR - CastEventToUI.cs

hololol 2019. 7. 23. 09:27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Valve.VR;
using UnityEngine.EventSystems;
using Valve.VR.Extras;
 
public class CastEventToUI : MonoBehaviour
{
    private SteamVR_LaserPointer laserPointer;
 
 
    private void OnEnable()
    {
            laserPointer = gameObject.GetComponent<SteamVR_LaserPointer>();
 
            //이벤트 할당
            laserPointer.PointerIn += OnPointerEnter;
            laserPointer.PointerOut += OnPointerExit;
            laserPointer.PointerClick += OnPointerClick;
 
    }
 
    private void OnDisable()
    {
        //이벤트 연결 해제
        laserPointer.PointerIn -= OnPointerEnter;
        laserPointer.PointerOut -= OnPointerExit;
        laserPointer.PointerClick -= OnPointerClick;
    }
 
    // 레이저 포인터가 들어갔을 경우
    void OnPointerEnter(object sender, PointerEventArgs e)
    {
        IPointerEnterHandler enterHandler = e.target.GetComponent<IPointerEnterHandler>();
        if (enterHandler == null)
            return;
 
        enterHandler.OnPointerEnter(new PointerEventData(EventSystem.current));
    }   
 
 
    //레이저포인터가 나갔을 경우
    void OnPointerExit(object sender, PointerEventArgs e)
    {
        IPointerExitHandler exitHandler = e.target.GetComponent<IPointerExitHandler>();
        if (exitHandler == nullreturn;
        exitHandler.OnPointerExit(new PointerEventData(EventSystem.current));
    }
 
 
    //트리거 버튼을 클릭했을 경우
 
    void OnPointerClick(object sender, PointerEventArgs e)
    {
        IPointerClickHandler clickHandler = e.target.GetComponent<IPointerClickHandler>();
        if (clickHandler == nullreturn;
 
        clickHandler.OnPointerClick(new PointerEventData(EventSystem.current));
    }
  
}
 
cs

'유니티' 카테고리의 다른 글

유니티VR - PaletteMgr.cs  (0) 2019.07.23
유니티VR - DrawMgr.cs  (0) 2019.07.23
유니티VR-ViveController.cs  (0) 2019.07.23
유니티VR - UI, 레이저 포인터, 텔레포트 기능  (0) 2019.07.22
로그라이크 - Player.cs  (0) 2019.06.25