前提・実現したいこと
https://youtu.be/Ml2UakwRxjk
この動画のアプリケーションを実際に自分のスマホで動かそうとしているのですが、Placement Indicatorがうまく動作せず、またその他の機能も全く動きません。
発生している問題・エラーメッセージ
Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179) Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179) Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179) Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179) Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr) (at C:/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:179)
該当のソースコード
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.XR.ARFoundation; 5using UnityEngine.Experimental.XR; 6using System; 7 8public class ARTapToPlaceObject : MonoBehaviour 9{ 10 public GameObject objectToPlace; 11 public GameObject placementIndicator; 12 13 private ARSessionOrigin arOrigin; 14 private Pose placementPose; 15 private bool placementPoseIsValid = false; 16 17 void Start() 18 { 19 arOrigin = FindObjectOfType<ARSessionOrigin>(); 20 } 21 22 void Update() 23 { 24 UpdatePlacementPose(); 25 UpdatePlacementIndicator(); 26 27 if (placementPoseIsValid && Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) 28 { 29 PlaceObject(); 30 } 31 } 32 33 private void PlaceObject() //オブジェクトの生成 34 { 35 Instantiate(objectToPlace, placementPose.position, placementPose.rotation); 36 } 37 38 private void UpdatePlacementIndicator() 39 { 40 if (placementPoseIsValid) 41 { 42 placementIndicator.SetActive(true); //placementIndicatorを表示 43 placementIndicator.transform.SetPositionAndRotation(placementPose.position, placementPose.rotation); 44 } 45 else 46 { 47 placementIndicator.SetActive(false); //placementIndicatorを非表示 48 } 49 } 50 51 private void UpdatePlacementPose() 52 { 53 var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f)); 54 var hits = new List<ARRaycastHit>(); 55 arOrigin.Raycast(screenCenter, hits, TrackableType.Planes); //コライダとぶつかるかを検知 56 57 placementPoseIsValid = hits.Count > 0; 58 if (placementPoseIsValid) 59 { 60 placementPose = hits[0].pose; 61 62 var cameraForward = Camera.current.transform.forward; 63 var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized; 64 placementPose.rotation = Quaternion.LookRotation(cameraBearing); 65 } 66 } 67} 68
試したこと
unityを初めて触ることもあり、色々調べたのですが全くうまくいかないので試したことはないと思ってもらって構いません。
補足情報(FW/ツールのバージョンなど)
Unity 2018.4.36f1
windows10
あなたの回答
tips
プレビュー