Unityアプリ + Holographic Remotingでクライアント(HoloLens2)からサーバ(PC)に向けて接続する(OpenXR)
今回は、以前できなかったUnityアプリでHolographic Remotingの接続待ち(Listen)ができるようになったので、方法をメモします。
xr-physics-work-etc.hatenablog.com
Holographic RemotingがOpenXR対応されることで、Unityで使用できるAPIが増えました。
これを使って、PC側のHolographic RemotingアプリをListen状態で起動し、Hololens2側のHolographic Remoting PlayerからPCに繋ぎに行きます。
前提
Unity 2020.3.16f1
MRTK 2.7.3 (導入、OpenXR設定済み)
準備
まずはOpenXRを用いたHolographic RemotingのUnityアプリを作成します。
今回はMRTKのHandInteractionExamples
シーンをベースに使用します。
PackageManagerからDemos - HandTracking
をImportし、Assets/Samples/Mixed Reality Toolkit Examples/2.7.3/Demos - HandTracking/Scenes/HandInteractionExamples.unity
にあるHandInteractionExamples
シーンをダブルクリックし、表示します。
下記URLからHolographic Remotingアプリ作成のためのサンプルを取得し、Unityプロジェクトに導入します。
Assets/MRTK.Tutorials.PCHolographicRemoting/Scripts/HolographicRemoteConnect.cs
を参考に下記スクリプトを作成します。
アプリ起動とともに、Holographic RemotingをListen状態で接続待ちにします。
- HandTrackingSharing.cs
クリックで展開
using UnityEngine; public class HolographicRemoteListen : MonoBehaviour { private Microsoft.MixedReality.OpenXR.Remoting.RemotingListenConfiguration remotingListenConfiguration = new Microsoft.MixedReality.OpenXR.Remoting.RemotingListenConfiguration { ListenInterface = "0.0.0.0", HandshakeListenPort = 8265, TransportListenPort = 8266, MaxBitrateKbps = 20000 }; // Start is called before the first frame update void Start() { Listen(); } public void Listen() { StartCoroutine(Microsoft.MixedReality.OpenXR.Remoting.AppRemoting.Listen(remotingListenConfiguration)); } }
空のGameObjectにHolographic Remoting
と名付け、先ほど作成したHolographicRemotingListen.cs
をアタッチします。
これで、Sceneのセッティングができました。
次に、Projectの設定をします。
ProjectSettings
-> XR Plug-in Management
からHolographic Remoting remote app feature gorup
にチェックを入れます。
OPenXR
右側に赤いビックリマークが表示されたら、マークをダブルクリックし、表示されるウィンドウのFix All
をIssuesがなくなるまで押下します。
次にOpenXR
の項目のHolographic Remoting remote app
にチェックがついていることを確認します。
Player Settings
のCapabilities
でInternetClient
, InternetClientServer
, PrivateNetworkClientServer
にチェックを入れます。
これで準備ができたので、Build Settings
からUWPビルドをし、Visual Studioでx64でビルドします。
動作確認
下記URLを参考にHoloLens2からURIを使用してHolographic Remoting PlayerをConnectモードで起動すると、Listen状態のUnityアプリに接続できました。
PC側でアプリを起動しておくだけで、何も操作せずにHoloLens2とHolographic Remotingの接続を行うことができました。
xr-physics-work-etc.hatenablog.com