각각 AR Core 패키지에 포함된 동명의 스크립트를 수정한것.
AugmentedImageExampleController.cs
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | namespace GoogleARCore.Examples.AugmentedImage { using System.Collections.Generic; using GoogleARCore; using UnityEngine; public class AugmentedImageExampleController : MonoBehaviour { public GameObject FitToScanOverlay; public TrackedImage[] picturePrefab; private Anchor[] anchorArray; private Dictionary<int, AugmentedImageVisualizer> m_Visualizers = new Dictionary<int, AugmentedImageVisualizer>(); private List<AugmentedImage> m_TempAugmentedImages = new List<AugmentedImage>(); private void Start() { anchorArray = new Anchor[picturePrefab.Length]; } public void Update() { if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } Session.GetTrackables<AugmentedImage>( m_TempAugmentedImages, TrackableQueryFilter.Updated); foreach (var image in m_TempAugmentedImages) { if (image.TrackingState == TrackingState.Tracking) { //if (image.TrackingMethod == AugmentedImageTrackingMethod.LastKnownPose) // 트레킹되고있지만 그건 마지막으로 알려진 위치로 실행중이었다. if (anchorArray[image.DatabaseIndex] == null) { Anchor anchor = image.CreateAnchor(image.CenterPose); anchorArray[image.DatabaseIndex] = anchor; picturePrefab[image.DatabaseIndex].Image = image; picturePrefab[image.DatabaseIndex].gameObject.SetActive(true); picturePrefab[image.DatabaseIndex].transform.SetParent(anchor.transform); picturePrefab[image.DatabaseIndex].transform.localPosition = Vector3.zero; picturePrefab[image.DatabaseIndex].transform.localRotation = Quaternion.identity; picturePrefab[image.DatabaseIndex].transform.localScale = new Vector3(image.ExtentX, image.ExtentX, image.ExtentX); } } else if (image.TrackingState == TrackingState.Stopped) { anchorArray[image.DatabaseIndex] = null; picturePrefab[image.DatabaseIndex].gameObject.SetActive(false); } } foreach (var visualizer in m_Visualizers.Values) { if (visualizer.Image.TrackingState == TrackingState.Tracking) { FitToScanOverlay.SetActive(false); return; } } } } } |
AugmentedImageVisualizer.cs
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 | namespace GoogleARCore.Examples.AugmentedImage { using GoogleARCore; using UnityEngine; public class AugmentedImageVisualizer : MonoBehaviour { public AugmentedImage Image; public GameObject AllObj; public void Update() { if (Image == null || Image.TrackingState != TrackingState.Tracking) { AllObj.SetActive(false); return; } AllObj.transform.localScale = new Vector3(Image.ExtentX, Image.ExtentX, Image.ExtentX); AllObj.SetActive(true); } } } |
'🌍 Unity > VR, AR' 카테고리의 다른 글
AR Core Rotation 값만 받아오기 (0) | 2019.06.05 |
---|---|
AR Core 미리 할당된 오브젝트의 위치이동으로 구현하기 (0) | 2019.05.31 |
Unity 2019.2 에서 ARCore 오류 해결 (0) | 2019.05.27 |
Unity Google ARCore / MR (3) | 2019.01.10 |
OculusGo Mirror Mirroring 오큘러스 고 미러링 (0) | 2018.08.07 |