3テラバイト

プログラム関連備忘録サイト。主にゲーム。

Unity

Unity2020でMapboxを使用する

投稿日:

この記事ではエラー回避のため、SDKからAR関連パッケージを除外してインポートを行います。
セットアップ完了まで動作確認済ですが、AR以外にも動作に影響している可能性があります。

確認環境

  • Unity Version 2020.3.12f1.590.2
  • mapbox-unity-sdk_v2.1.1

Mapboxにサインアップする

MapboxのWebサイトのSign upボタン等からアカウントを作成します。
https://www.mapbox.com/

新規Unityプロジェクトの作成

新規の3Dプロジェクトを作成します。

SDKのダウンロードとインポート

以下のページからunitypackageをダウンロードします。
https://www.mapbox.com/install/unity/

Unityエディタ上で、Assets > Import Package > Custom Package…を選択し、ダウンロードしたmapbox-unity-sdk_v2.1.1.unitypackageを選択します。

AR関連のエラー回避のため、名前にARと付くもののチェックを外し、Importボタンを押下します。

Mapboxのセットアップ

パッケージのインポートが完了すると上の画像のようなウィンドウが開きます。
自動で開かない場合は、Unityエディタ上部のメニューにMapboxメニューが追加されているため、そのメニューのSetupを選択するとこのウィンドウが開きます。

Access Tokenのテキストボックスに自身のアクセストークンを入力し、Submitボタンを押下すると認証が行われ、認証が通るとAPIが使用可能な状態になります。

アクセストークンは自身のアカウントページに表示されています。
https://account.mapbox.com/

または、サインアップした状態だと以下のページにも表示されています。
https://www.mapbox.com/install/unity/permission/

AR関連パッケージのエラー

AR関連のパッケージをインポートすると以下のようなエラーが発生します。

Assets\GoogleARCore\SDK\InstantPreview\Scripts\InstantPreviewManager.cs(32,23): error CS0234: The type or namespace name 'SpatialTracking' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
Assets\UnityARInterface\ARRemote\Scripts\ARRemoteEditorInterface.cs(40,17): error CS0246: The type or namespace name 'ARBackgroundRenderer' could not be found (are you missing a using directive or an assembly reference?)
Assets\UnityARInterface\Scripts\ARCoreInterface.cs(51,17): error CS0246: The type or namespace name 'ARBackgroundRenderer' could not be found (are you missing a using directive or an assembly reference?)
Assets\UnityARInterface\Scripts\ARKitInterface.cs(26,17): error CS0246: The type or namespace name 'ARBackgroundRenderer' could not be found (are you missing a using directive or an assembly reference?)
Assets\GoogleARCore\SDK\Scripts\ARCoreBackgroundRenderer.cs(43,17): error CS0246: The type or namespace name 'ARBackgroundRenderer' could not be found (are you missing a using directive or an assembly reference?)

5件中4件のエラー原因になっているARBackgroundRendererが見つからない問題については以下mapbox-unity-sdkのGitHubにissueも挙がっています。
https://github.com/mapbox/mapbox-unity-sdk/issues/1753

ARBackgroundRendererの公式スクリプトリファレンスは以下のページで、Unity2020以降には存在しません。
https://docs.unity3d.com/ja/2019.4/ScriptReference/XR.ARBackgroundRenderer.html

AR Foundationパッケージ内にARBackgroundRendererコンポーネントの存在が確認できますが、[1.0.0-preview.9] – 2018-06-06でARCameraBackgroundにリネームされ、[3.0.0-preview.6] – 2019-11-14でARCameraBackgroundが削除されているようです。
https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@3.1/changelog/CHANGELOG.html

-Unity


comment

メールアドレスが公開されることはありません。

関連記事

no image

Unityエディタ上で使用できるダイアログを表示する方法

EditorUtility.DisplayDialog関数でダイアログの表示が可能です。 bool isOK = EditorUtility.DisplayDialog("Title&quo …

no image

UnityでuGUIのButtonサイズを子のTextのサイズに自動で合わせる

こんにちは、今日はUnityのuGUIでButtonのサイズを、子オブジェクトのTextのサイズに合わせて変更する方法についてまとめていきます。 確認環境 Version 2018.4.15f1 実装 …

no image

Unityでカーソルの表示、ロック、画像の切り替えをする

こんにちは、今日はUnityでカーソルの表示、ロック、画像の切り替えをする方法についてまとめていきます。 確認環境 Unity 2018.4.15f1 カーソルの表示、非表示 表示 Cursor.vi …

no image

Unityで数値を指定範囲に収める

確認環境 Unity 2018.4.15f1 数値を指定範囲に収める Clamp public static int Clamp(int value, int min, int max); publi …

no image

Unityでマウスオーバーしているウィンドウを最大化するショートカットキー

こんにちは、今日はUnityでマウスオーバーしているウィンドウを最大化するショートカットキーについてまとめていきます。 確認環境 Unity 2018.4.15f1 マウスオーバーしているウィンドウを …