本日は ARFoundation の小ネタ枠です。
ARFoundationで現在のデバイスが深度情報を取得可能かチェックする手順についてです。
前提条件
前提条件として以下の記事の通り、ARFoundation のインポートと AROcclusionManager コンポーネントの設定を行います。
bluebirdofoz.hatenablog.com
environmentDepthImageSupported
environmentDepthImageSupported 変数はデバイスが環境深度画像をサポートしているかどうかを返します。
サポートされているかどうかの判断には時間がかかる場合があります。サポートがまだ決定していない場合、値は Unknown になります。
docs.unity3d.com
以下の3つの種別が取得できます。
・Supported:環境深度画像がサポートされている。
・Unknown:サポートされているか不明。
・Unsupported:環境深度画像はサポートされていません。
docs.unity3d.com
サンプルコード
以下のサンプルコードを作成しました。
AROcclusionManager コンポーネントから environmentDepthImageSupported 変数を参照してデバイスのサポート情報を取得します。
・DepthTest.cs
using System; using UnityEngine; using UnityEngine.XR.ARFoundation; using UnityEngine.XR.ARSubsystems; public class DepthTest : MonoBehaviour { [SerializeField] private AROcclusionManager arOcclusionManager; void Start() { var supportedInfo = arOcclusionManager.descriptor?.environmentDepthImageSupported ?? Supported.Unknown; switch (supportedInfo) { case Supported.Unknown: Debug.Log("Unknown"); break; case Supported.Unsupported: Debug.Log("UnSupported"); break; case Supported.Supported: Debug.Log("Supported"); break; default: throw new ArgumentOutOfRangeException(); } } }
参照DLL
AROcclusionManager の参照先は UnityEngine.XR.ARFoundation、XROcclusionSubsystemDescriptor の参照先は UnityEngine.XR.ARSubsystems になります。
このため、Assembly Definition を切っている場合は、以下の両方の DLL への参照が必要となる点に注意が必要です。
・UnityEngine.XR.ARFoundation
・UnityEngine.XR.ARSubsystems