Unity に Mixed Reality OpenXR プラグインを使用するUsing the Mixed Reality OpenXR Plugin for Unity
Unity バージョン2020.2 以降、Microsoft の Mixed Reality OpenXR プラグインパッケージは、Unity パッケージマネージャー (UPM) を使用して利用できます。Starting with Unity version 2020.2, Microsoft’s Mixed Reality OpenXR Plugin package is available using the Unity Package Manager (UPM).
前提条件Prerequisites
- Unity 2020.2 以降Unity 2020.2 or later
- Unity OpenXR plugin 0.1.2 以降Unity OpenXR plugin 0.1.2 or later
- Visual Studio 2019 以降Visual Studio 2019 or later
- HoloLens 2 アプリの UWP プラットフォームサポートを Unity でインストールするInstall UWP platform support in Unity for HoloLens 2 apps
注意
Windows PC で VR アプリケーションを構築している場合、Mixed Reality OpenXR プラグインは必ずしも必要ではありません。If you're building VR applications on Windows PC, the Mixed Reality OpenXR plugin is not necessarily required. ただし、HP リバーブ G2 コントローラーのコントローラーマッピングをカスタマイズしている場合、または HoloLens 2 と VR ヘッドセットの両方で動作するアプリを作成する場合は、プラグインをインストールする必要があります。However, you'll want to install the plugin if you're customizing controller mapping for HP Reverb G2 controllers or building apps that work on both HoloLens 2 and VR headsets.
Mixed Reality OpenXR プラグインのインストールInstalling the Mixed Reality OpenXR plugin
混合 Reality OpenXR プラグインを使用する前に、プロジェクトで OpenXR plugin と XR plugin 管理 パッケージをインストールする必要があります。Your project needs to install the OpenXR Plugin and XR Plugin Management packages before using the Mixed Reality OpenXR Plugin. 既にインストールされている場合は、If you've already installed them, great! それ以外の場合、Mixed Reality OpenXR プラグインをインストールすると、依存関係として自動的にインストールされます。If not, installing the Mixed Reality OpenXR plugin will automatically install them as dependencies:
Unity エディターで、[ > プロジェクトの設定の編集] > [パッケージマネージャー ] の順に移動します。In the Unity Editor, navigate to Edit > Project Settings > Package Manager
[スコープされた レジストリ ] セクションを展開し、次の情報を入力して、[ 保存] を選択します。Expand the Scoped Registries section, enter the following information, and select Save:
- 名前 を Microsoft Mixed Reality に設定するSet Name to Microsoft Mixed Reality
- URL をに設定 https://pkgs.dev.azure.com/aipmr/MixedReality-Unity-Packages/_packaging/Unity-packages/npm/registry/Set URL to https://pkgs.dev.azure.com/aipmr/MixedReality-Unity-Packages/_packaging/Unity-packages/npm/registry/
- スコープ を mixedreality に設定し ます。Set Scope(s) to com.microsoft.mixedreality
[詳細設定] で、[プレビューパッケージを有効にする] を選択します。Under Advanced Settings, select Enable Preview Packages
Unity パッケージマネージャーでは、 manifest.js という名前のマニフェストファイルを使用して、インストールするパッケージとインストール可能なレジストリを決定します。The Unity Package Manager uses a manifest file named manifest.json to determine which packages to install and the registries they can be installed from.
重要
OpenXR は引き続き Unity で試験段階であり、開発者エクスペリエンスを最適化するために作業するため、このプロセスは時間の経過と共に変わる可能性があります。OpenXR is still experimental in Unity and this process may change over time as we work to optimize the developer experience.
Mixed Reality 依存関係を登録していますRegistering the Mixed Reality dependency
Microsoft Mixed Reality スコープのレジストリがマニフェストに追加されたら、OpenXR パッケージを指定できます。Once the Microsoft Mixed Reality scoped registry has been added to the manifest, the OpenXR package can be specified.
OpenXR パッケージを追加するには、次のようにします。To add the OpenXR package:
次のようなテキストエディターで [Projectroot]/パッケージ/manifest.jsを 開き Visual Studio CodeOpen [projectRoot]/Packages/manifest.json in a text editor like Visual Studio Code
- このページを表示するには、プロジェクトウィンドウの左側のパネルにある [ パッケージ ] を右クリックします。To get here, right click on Packages in the left panel of the Project window. 次に、[ エクスプローラーで表示] をクリックします。Then, click Show in Explorer.
- このページを表示するには、プロジェクトウィンドウの左側のパネルにある [ パッケージ ] を右クリックします。To get here, right click on Packages in the left panel of the Project window. 次に、[ エクスプローラーで表示] をクリックします。Then, click Show in Explorer.
次のように、ファイルの Packages/manifest.js の dependencies セクションを変更します。Modify the dependencies section of the Packages/manifest.json file as follows:
重要
マニフェストファイルには、ここに示されている以上の依存関係がある場合があります。There may be more dependencies in your manifest file than shown here. これらのいずれも削除しないでください。リストに OpenXR 依存関係を追加するだけです。Don't delete any of them, just add the OpenXR dependency to the list.
"dependencies": { "com.microsoft.mixedreality.openxr": "0.1.2", }
ファイルを保存し、Unity エディターに戻り、 パッケージマネージャー を開いて、プラグインがインストールされていることを確認します。Save the file, switch back to the Unity Editor, and open the Package Manager to confirm the plugin is installed:
注意
Unity パッケージマネージャーを使用して OpenXR パッケージを削除した場合は、前に説明した手順を使用して、パッケージを再度追加する必要があります。If the OpenXR package is removed using the Unity Package Manager, you'll have to re-add it using the previously described steps.
OpenXR の XR Plugin Management の構成Configuring XR Plugin Management for OpenXR
Unity のランタイムとして OpenXR を設定するには、次のようにします。To set OpenXR as the the runtime in Unity:
- Unity エディターで、[ Edit > プロジェクトの設定] に移動します。In the Unity Editor, navigate to Edit > Project Settings
- 設定の一覧で、[ XR Plugin Management ] を選択します。In the list of Settings, select XR Plugin Management
- [XR On Startup and OpenXR (プレビュー) ] ボックスをオンにします。Check the Initialize XR on Startup and OpenXR (Preview) boxes
- HoloLens 2 を対象とする場合は、UWP プラットフォームを使用していることを確認し、[ Microsoft HoloLens] 機能セット を選択します。If targeting HoloLens 2, make sure you're on the UWP platform and select Microsoft HoloLens Feature Set
重要
OpenXR Plugin (Preview) の横に赤い警告アイコンが表示された場合は、アイコンをクリックし、[すべて修正] を選択してから続行します。If you see a red warning icon next to OpenXR Plugin (Preview), click the icon and select Fix all before continuing. 変更を有効にするには、Unity エディター自体を再起動することが必要になる場合があります。The Unity Editor may need to restart itself for the changes to take effect.
Unity で OpenXR を使用して開発を始める準備ができました。You're now ready to begin developing with OpenXR in Unity! OpenXR サンプルの使用方法については、次のセクションに進んでください。Continue on to the next section to learn how to use the OpenXR samples.
OptimizationOptimization
HoloLens 2 用に開発している場合は、 Mixed Reality> > OpenXR に移動し、hololens 2 に推奨されるプロジェクト設定を適用して 、アプリのパフォーマンスを向上させます。If you're developing for HoloLens 2, navigate to Mixed Reality> OpenXR > Apply recommended project settings for HoloLens 2 to get better app performance.
Unity のサンプルシーンを試すTry out the Unity sample scenes
1つ以上の例を使用するには、パッケージマネージャー から arfoundation 4.0 +をインストールします。To utilize one or more of the examples, install ARFoundation 4.0+ from the Package Manager:
HoloLens 2 のサンプルHoloLens 2 samples
- Unity エディターで、[ ] ウィンドウ > [パッケージマネージャー] の順に移動します。In the Unity Editor, navigate to Window > Package Manager
- パッケージの一覧で [ Mixed Reality OpenXR Plugin ] を選択します。In the list of packages, select Mixed Reality OpenXR Plugin
- サンプル一覧で サンプルを探し、[インポート] を選択します。Locate the sample in the Samples list and select Import
注意
パッケージが更新されると、Unity にはインポートされたサンプルを更新するオプションが用意されています。When a package is updated, Unity provides the option to update imported samples. インポートしたサンプルを更新すると、サンプルおよび関連付けられている資産に加えられた変更が上書きされます。Updating an imported sample will overwrite any changes that have been made to the sample and associated assets.
OpenXR サポートでの MRTK の使用Using MRTK with OpenXR support
MRTK Unity では、2.5.3 リリース以降の Mixed Reality OpenXR プラグインがサポートされています。MRTK Unity supports the Mixed Reality OpenXR plugin starting with the 2.5.3 release. Mixed Reality OpenXR プラグインをインストールするときに設定したものと同じスコープを持つレジストリから、MRTK プラグインをインストールできます。MRTK plugins can be installed from the same scoped registries as you set up when installing the Mixed Reality OpenXR plugin. 詳細については、 Mrtk のドキュメントを参照してください。You can find more detailed information in the MRTK documentation.
- ファイル の [Projectroot]/パッケージ/manifest.js に次のパッケージを追加します。Add following packages in your [projectRoot]/Packages/manifest.json file:
"dependencies": {
"com.microsoft.mixedreality.toolkit.foundation": "2.5.3",
"com.microsoft.mixedreality.toolkit.tools": "2.5.3",
"com.microsoft.mixedreality.toolkit.examples": "2.5.3",
…
}
- インスペクターの MixedReality Toolkit コンポーネントスクリプトに移動し、 DefaultOpenXRConfigurationProfile プロファイルに切り替えます。Go to the MixedReality Toolkit component script in the Inspector and switch to the DefaultOpenXRConfigurationProfile profile:
既知の問題Known issues
ハンドトラッキング機能を使用する場合は、 Assets/MixedRealityToolkit/link.xml ファイルに次の行を追加します。When using the Hand Tracking feature, add following line in the Assets/MixedRealityToolkit.Generated/link.xml file:
<assembly fullname = "Microsoft.MixedReality.Toolkit.Providers.OpenXR" preserve="all"/>
次のステップNext steps
プロジェクトが OpenXR 用に構成され、サンプルにアクセスできるようになったので、OpenXR プラグインで現在サポートされている 機能 を確認してください。Now that you have your project configured for OpenXR and have access to samples, check out what features are currently supported in our OpenXR plugin.
フィードバックがありますか?Have Feedback?
OpenXR は依然として試験的であるため、お客様からのフィードバックをお寄せください。OpenXR is still experimental, so we’d appreciate any feedback you can give us to help make it better. Microsoft + OpenXR と HoloLens 2 または Windows Mixed Reality でフォーラム投稿にタグを付けて、Unity フォーラムをご覧ください。You'll find us on the Unity Forums by tagging your forum post with Microsoft + OpenXR and either HoloLens 2 or Windows Mixed Reality.