https://www.youtube.com/watch?v=o_z_Eb8Yh2g&list=PL6VJLOFcTt7awvyIGIbLLPOBrW6-Y1R-J&index=3&ab_channel=DineshPunni
AR Session Origin -> Add AR Tracked Image Manager
Assets -> Create -> XR -> Reference Image Library
拖一张图到Assets里
Reference Library -> Add Image 把图拖进去,填Physical Size
AR Session Origin -> 把Reference Library拖到AR Tracked Image Manager中
Assets -> Create -> C# Script -> 重命名ImageRecognitionExample
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.XR.ARFoundation;
public class NewBehaviourScript : MonoBehaviour {
private ARTrackedImageManager _arTrackedImageManager; private void Awake() { _arTrackedImageManager = FindObjectOfType<ARTrackedImageManager>(); } public void OnEnable() { _arTrackedImageManager.trackedImagesChanged += OnImageChanged; } public void onDisable() { _arTrackedImageManager.trackedImagesChanged -= OnImageChanged; } public void OnImageChanged(ARTrackedImagesChangedEventArgs args) { foreach (var trackedImage in args.added) { Debug.Log(trackedImage.name); } }
}
|
Create 3D Object Cube,调整位置、大小
拖进Assets(变成prefab),在SampleScene中删除
把prefab拖进AR Tracked Image Manager
Build
成功~