【Hololens】Mixed Reality Toolkit 사용 【AirTap】
6227 단어 MixedRealityToolkitHoloLensUnity
환경
2017.2에서 빌드가 잘 되지 않았기 때문에 이번에는 2017.1을 사용하고 있습니다.
준비
다운로드
Unity용 MixedRealityToolKit 다운로드 대상:
htps : // 기주 b. 코 m / mic 로소 ft / mi d
가져오기
Assets > Import Package > Custom Package
다운로드한 패키지 가져오기
Unity 설정
자동 설정
MixedRealityToolkit을 가져오면 Unity 메뉴에 "Mixed Reality Toolkit"이 추가됩니다.

설정하고 싶은 항목을 선택하면 아래와 같은 화면이 나오므로, 필요한 부분에 체크를 넣고 Apply를 클릭.
이번은 초기 상태로 실행.

빌드 설정
Build Settings에서 Universal Windows Platform을 선택하고 Switch Platform을 클릭하십시오.
그런 다음 Player Settings를 열고 Other Sttings(Unity2017.2의 경우 XR Settings)의 Virtual Reality Supported를 선택하고 Windows Holographic을 선택합니다.

커서 관계
커서 추가
참고 : HoloToolKit의 AirTap에 대한 메모 (AirTap 이벤트 얻기)
Holotooolkit > Input > Prefabs
에서 InputManager를 Hierarchy에 추가.
Holotooolkit > Input > Prefabs > Cursor
에서 좋아하는 Cursor의 prefab을 Hierarchy에 추가하십시오.
![20171206-201217.jpg]()
커서를 객체에 씌우면 모양이 바뀝니다.
InputManager내에 있는 EditorHandsInput은 사용하지 않으므로 비활성으로 해 둔다(화면에 양손의 커서가 표시되고 싶기 때문에)
시선 이벤트
시선의 이벤트는 HoloToolkit.Unity.InputModule의 IFocusable를 상속하면
OnFocusEnter()
OnFocusExit()
에서 불린다.
아래 샘플 코드
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Unity.InputModule;
public class CubeGazefocus : MonoBehaviour, IFocusable {
public Material focusOn;
public Material focusOut;
public void OnFocusEnter()
{
GetComponent<Renderer>().material = focusOn;
}
public void OnFocusExit()
{
GetComponent<Renderer>().material = focusOut;
}
}
Hierarchy에 Cube를 추가하고이 코드를 첨부.
Blue와 Green의 Material을 만들고 다음과 같이 설정
![20171207-100607.jpg]()
청색 Cube가 시선을 맞추면 녹색으로 바뀝니다.


AirTap 이벤트 추가
AirTap의 이벤트는 HoloToolkit.Unity.InputModule의 IInputClickHandler를 상속하면
OnInputClicked(InputClickEventData eventData){}
불린다.
아래 샘플 코드
using UnityEngine;
using System.Collections;
using HoloToolkit.Unity.InputModule;
public class CubeCommand : MonoBehaviour, IInputClickHandler
{
public Material first;
public Material second;
public void OnInputClicked(InputClickedEventData eventData)
{
var material = GetComponent<Renderer>().material;
GetComponent<Renderer>().material = (material.color == first.color) ? second : first;
}
}
이 코드를 이전 Cube에 연결하고 다음과 같이 설정합니다.

탭하면 빨간색과 녹색으로 색상이 바뀝니다.


버튼 추가
Unity의 UI Button을 그대로 사용할 수 있다.
Create > UI > Button
더 버튼을 추가.
Canvas의 RendarMode를 "World Space"로 변경.
버튼을 보기 쉬운 위치로 이동합니다.
다음 샘플 코드를 Cube에 연결합니다.
※AirTap 이벤트로 작성한 스크립트는 불필요합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickButton : MonoBehaviour {
public Material click1;
public Material click2;
private bool isTouchOn = false;
public void OnClicked()
{
if (isTouchOn)
{
isTouchOn = false;
GetComponent<Renderer>().material = click1;
}
else
{
isTouchOn = true;
GetComponent<Renderer>().material = click2;
}
}
}

버튼 이벤트에 작성한 OnClicked를 설정합니다.

이제 버튼을 AirTap 할 때마다 Cube의 색상이 바뀝니다.

Reference
이 문제에 관하여(【Hololens】Mixed Reality Toolkit 사용 【AirTap】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/raku-lab/items/a7a46fca7b57160c7f73
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
자동 설정
MixedRealityToolkit을 가져오면 Unity 메뉴에 "Mixed Reality Toolkit"이 추가됩니다.

설정하고 싶은 항목을 선택하면 아래와 같은 화면이 나오므로, 필요한 부분에 체크를 넣고 Apply를 클릭.
이번은 초기 상태로 실행.

빌드 설정
Build Settings에서 Universal Windows Platform을 선택하고 Switch Platform을 클릭하십시오.
그런 다음 Player Settings를 열고 Other Sttings(Unity2017.2의 경우 XR Settings)의 Virtual Reality Supported를 선택하고 Windows Holographic을 선택합니다.

커서 관계
커서 추가
참고 : HoloToolKit의 AirTap에 대한 메모 (AirTap 이벤트 얻기)
Holotooolkit > Input > Prefabs
에서 InputManager를 Hierarchy에 추가.
Holotooolkit > Input > Prefabs > Cursor
에서 좋아하는 Cursor의 prefab을 Hierarchy에 추가하십시오.
![20171206-201217.jpg]()
커서를 객체에 씌우면 모양이 바뀝니다.
InputManager내에 있는 EditorHandsInput은 사용하지 않으므로 비활성으로 해 둔다(화면에 양손의 커서가 표시되고 싶기 때문에)
시선 이벤트
시선의 이벤트는 HoloToolkit.Unity.InputModule의 IFocusable를 상속하면
OnFocusEnter()
OnFocusExit()
에서 불린다.
아래 샘플 코드
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Unity.InputModule;
public class CubeGazefocus : MonoBehaviour, IFocusable {
public Material focusOn;
public Material focusOut;
public void OnFocusEnter()
{
GetComponent<Renderer>().material = focusOn;
}
public void OnFocusExit()
{
GetComponent<Renderer>().material = focusOut;
}
}
Hierarchy에 Cube를 추가하고이 코드를 첨부.
Blue와 Green의 Material을 만들고 다음과 같이 설정
![20171207-100607.jpg]()
청색 Cube가 시선을 맞추면 녹색으로 바뀝니다.


AirTap 이벤트 추가
AirTap의 이벤트는 HoloToolkit.Unity.InputModule의 IInputClickHandler를 상속하면
OnInputClicked(InputClickEventData eventData){}
불린다.
아래 샘플 코드
using UnityEngine;
using System.Collections;
using HoloToolkit.Unity.InputModule;
public class CubeCommand : MonoBehaviour, IInputClickHandler
{
public Material first;
public Material second;
public void OnInputClicked(InputClickedEventData eventData)
{
var material = GetComponent<Renderer>().material;
GetComponent<Renderer>().material = (material.color == first.color) ? second : first;
}
}
이 코드를 이전 Cube에 연결하고 다음과 같이 설정합니다.

탭하면 빨간색과 녹색으로 색상이 바뀝니다.


버튼 추가
Unity의 UI Button을 그대로 사용할 수 있다.
Create > UI > Button
더 버튼을 추가.
Canvas의 RendarMode를 "World Space"로 변경.
버튼을 보기 쉬운 위치로 이동합니다.
다음 샘플 코드를 Cube에 연결합니다.
※AirTap 이벤트로 작성한 스크립트는 불필요합니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickButton : MonoBehaviour {
public Material click1;
public Material click2;
private bool isTouchOn = false;
public void OnClicked()
{
if (isTouchOn)
{
isTouchOn = false;
GetComponent<Renderer>().material = click1;
}
else
{
isTouchOn = true;
GetComponent<Renderer>().material = click2;
}
}
}

버튼 이벤트에 작성한 OnClicked를 설정합니다.

이제 버튼을 AirTap 할 때마다 Cube의 색상이 바뀝니다.

Reference
이 문제에 관하여(【Hololens】Mixed Reality Toolkit 사용 【AirTap】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/raku-lab/items/a7a46fca7b57160c7f73
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
OnFocusEnter()
OnFocusExit()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Unity.InputModule;
public class CubeGazefocus : MonoBehaviour, IFocusable {
public Material focusOn;
public Material focusOut;
public void OnFocusEnter()
{
GetComponent<Renderer>().material = focusOn;
}
public void OnFocusExit()
{
GetComponent<Renderer>().material = focusOut;
}
}
OnInputClicked(InputClickEventData eventData){}
using UnityEngine;
using System.Collections;
using HoloToolkit.Unity.InputModule;
public class CubeCommand : MonoBehaviour, IInputClickHandler
{
public Material first;
public Material second;
public void OnInputClicked(InputClickedEventData eventData)
{
var material = GetComponent<Renderer>().material;
GetComponent<Renderer>().material = (material.color == first.color) ? second : first;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ClickButton : MonoBehaviour {
public Material click1;
public Material click2;
private bool isTouchOn = false;
public void OnClicked()
{
if (isTouchOn)
{
isTouchOn = false;
GetComponent<Renderer>().material = click1;
}
else
{
isTouchOn = true;
GetComponent<Renderer>().material = click2;
}
}
}
Reference
이 문제에 관하여(【Hololens】Mixed Reality Toolkit 사용 【AirTap】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/raku-lab/items/a7a46fca7b57160c7f73텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)