'프로그래밍/Unity 공부'에 해당되는 글 2건

  1. 2018.12.21 유니티 뷰포리아 AR 이미지인식
  2. 2018.12.13 유니티 마우스,터치 이벤트 작성(IPointer)

유니티 최신버전에서는 뷰포리아가 지원되기 되는 것 같더라구요


이번장은 유니티를 이용해 마커를 인식하는 것을 작성하겠습니다.



0. Vuforia 이미지 등록

먼저 뷰포리아(https://developer.vuforia.com)를 가입하시고 DevPortal 에서

  1. License 생성(Type이 Developer 이면 비용이 들지 않습니다.)
  2. DataBase 생성
  3. Add Taget(이미지 타겟)을 통해 이미지를 추가하고
  4. Download Database를 통해 UnityPackage를 뽑을 수 있습니다.
  5. 생성한 License의 키를 복사하여 Unity의 License Key에 붙여넣으시면 됩니다.

(Resource->VuforiaConfiguration -> App License Key )

다음의 뷰포리아 셋팅을 추가하시면 License키를 등록할 수 있습니다.


1. Unity Vuforia Setting

Edit->ProjectSettings->Player



XR Settings-> Vuforia Augemented Reality Supptorted Check




2. 기존의 카메라 삭제 후 ARCamera 등록

GameObject->Vuforia->ARCamera



3. 이미지 마커 객체 생성

GameObject->Vuforia->Image 



이미지 마커 위에 객체 생성시에 휴대폰 혹은 웹캠을 통해 이미지 인식 위에 생성되는 걸 확인할 수 있습니다.


Posted by Dongkey
,

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
,