3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ARFoundation version2.0以降での注意点

Posted at

経緯

下のテラシュールブログさんの記事を参考にAR Foundationを使用しARアプリを作ろうとした時に記事のバージョンより上の
AR Foundation Version 2.0.2を使用したところいくつか変更点があり、記事の通りにやってもうまくいかなかったため。
テラシュールブログさんの記事

内容

AR Foundation Version 2.0.2を使用しての簡単なARアプリの作り方
なおアプリの仕様に関しては前述のテラシュールブログさんの内容に同じです。

環境

Unity 2019.2.5f1
AR Foundation 2.0.2
AR Core XR Plugin
AR Kit XR Plugin
ビルド先
Android端末

開発の流れ

  1. Package Managerから上部3つをインストールします。
  2. Main Cameraを削除しシーン上にAR Session, AR Session Origin,AR Default Planeを設置します。
  3. AR Default PlaneをPrefabにしてシーンから削除します。
  4. AR Session OriginにAR Plane Manager, AR Raycast Managerの二つのコンポーネントを追加します。Version 1.0.0では
    AR Session OriginにRaycastの定義が含まれていましたが2.0.0以降では新しくAR Raycast Managerというコンポーネントで
    AR CameraからのRaycastを管理するようになりました。
  5. AR Plane ManagerにPrefabにしたPlaneを登録します。
  6. 以下のスクリプトを参考にしてAR Session Originにアタッチしてください。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;

public class SpawnScript : MonoBehaviour
{
    private List<ARRaycastHit> hitResults = new List<ARRaycastHit>();
    private ARRaycastManager rayManage;

    [SerializeField] GameObject prefab;

    private void Awake() {
        rayManage = this.GetComponent<ARRaycastManager>();
    }
    private void Update() {
        if (Input.GetMouseButtonDown(0)) {
            if (rayManage.Raycast(Input.GetTouch(0).position, hitResults)) {
                Instantiate(prefab, hitResults[0].pose.position, Quaternion.identity);
            }
        }
    }
}

7.Prefabに出現させたいオブジェクトを登録してください
8.Build Settingで各種設定をしてもらいます。この時にAR Core Supportにチェックを入れるとAR Core XR Pluginと競合するのでチェックを入れないようにしてください。Settingの仕方に関してはAndroidの場合以下を参考にしてください(iosに関してはすみませんが調べてください)
Android AR Setting
Buildするとうまくいくと思います。
初めての執筆だったのでわかりづらい点があるかもしれませんが参考になればうれしいです。

解決策になったUnity Forum

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?