アウトドアとかゲーム開発とか

ロードバイクやキャンプなどアウトドアとUnityでの開発とか

【Unity】Windows Mixed RealityのモーションコントローラをUnityで使う【WinMR】

Windows Mixed Realityのモーションコントローラの開発機が届いたのでセットアップしてUnityで動かしてみました。

f:id:vrcycling:20171008185054p:plain

■セットアップ

https://developer.microsoft.com/en-us/windows/mixed-reality/install_the_tools

【翻訳】Motion controllers - 戯言日記

Windows Insider Progoram の設定で引っかかったので補足。
下記のように設定すると最新のWin10のOSビルドになります。

f:id:vrcycling:20171008185452p:plain

10/10更新 【重要】で下記メールが来たので注意してください

~~
We are reaching out to you regarding an important change to your development environment for Windows Mixed Reality. Please follow the instructions listed below today!


Soon, developers using the Windows Insider Fast Ring will receive early RS4 updates, which may not provide the most stable builds for mixed reality development. To continue your development uninterrupted, please switch your Windows Insider settings.

Instructions for switching:
1. Open Windows Settings
2. Select "Update & Security"
3. Select "Windows Insider Program"
4. In the "What kind of content would you like to receive?" drop-down menu, select "Just fixes, apps, and drivers"
5. In the "What pace do you want to get new builds?" drop-down menu, select "Windows Insider Release Preview"
~~

Windowsのバージョンアップが終わったらコントローラのペアリングをします。
電池を入れるところの下にあるのでカバーを外してペアリングします。

f:id:vrcycling:20171008190030p:plain

Mixed Reality ポータルで確認できれば準備完了です。

■Unityのバージョンの設定

Unity2017.2.0f2 で動作確認できました。

Unity - Unity - Beta Archive
※2017.2.0b6ではUnityが反応しなくなりました

設定は下記を参照してください。

Windows Mixed Reality Headsetで自作コンテンツを動かす with Unity - tks_yoshinagaの日記

■Unityでコントローラを使う

下記を参照

Gestures and motion controllers in Unity

■コントローラ位置の取得

Vector3 leftPosition = InputTracking.GetLocalPosition(XRNode.LeftHand);
Quaternion leftRotation = InputTracking.GetLocalRotation(XRNode.LeftHand);

で位置と回転を取得できます。LeftHandをRightHandに変えれば右手が使えます。
スクリプト冒頭に using UnityEngine.XR; が必要です。

■入力の取得

入力についても上記ページに記載されてるとおり、インプットマネージャーから各Axisを設定して使用します。
ただひとつひとつ設定するのはめんどくさいので、MixedRealityToolkitからインプットマネージャーを引っ張ってきます。

GitHub - Microsoft/MixedRealityToolkit-Unity at Dev_Unity_2017.2.0

InputManagerの設定を再利用する - Unityな日々(Unity Geek)

あとは通常のAxisやButtonの取得と同じです。

Debug.Log( Input.GetAxis("CONTROLLER_RIGHT_STICK_HORIZONTAL") );

こんな感じです。

※Unityのプレビューでうまくコントローラの値が取得できないときは、コントローラのWindowsボタンを押しポータルに行ってから戻ってくる(ウインドウを選択する)と取得できるみたいです。

とりあえずこれでコントローラの位置や入力が取得できたのでViveやRiftのコンテンツが移植できるはず・・・なのでひとまずここまで。