- 빈 GameObject에 DynamicDataSetLoader.cs(아래 스크립트)를 추가한다.
- Inspector에 멤버 변수를 채운다
Augmentation Object - 마커 하위 오브젝트로 추가될 오브젝트를 넣는 곳
Data Set Name - DataSet의 이름을 적는 곳
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 71 72 73 74 75 76 77 78 79 80 81 82 | using UnityEngine; using System.Collections; using Vuforia; using System.Collections.Generic; public class DynamicDataSetLoader : MonoBehaviour { // specify these in Unity Inspector public GameObject augmentationObject = null; // you can use teapot or other object public string dataSetName = ""; // Assets/StreamingAssets/QCAR/DataSetName // Use this for initialization void Start() { // Vuforia 6.2+ VuforiaARController vac = VuforiaARController.Instance; vac.RegisterVuforiaStartedCallback(LoadDataSet); } void LoadDataSet() { ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>(); DataSet dataSet = objectTracker.CreateDataSet(); if (dataSet.Load(dataSetName)) { objectTracker.Stop(); // stop tracker so that we can add new dataset if (!objectTracker.ActivateDataSet(dataSet)) { // Note: ImageTracker cannot have more than 100 total targets activated Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>"); } if (!objectTracker.Start()) { Debug.Log("<color=yellow>Tracker Failed to Start.</color>"); } int counter = 0; IEnumerable<TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours(); foreach (TrackableBehaviour tb in tbs) { if (tb.name == "New Game Object") { // change generic name to include trackable name tb.gameObject.name = ++counter + ":DynamicImageTarget-" + tb.TrackableName; // add additional script components for trackable tb.gameObject.AddComponent<DefaultTrackableEventHandler>(); tb.gameObject.AddComponent<TurnOffBehaviour>(); if (augmentationObject != null) { // instantiate augmentation object and parent to trackable GameObject augmentation = (GameObject)GameObject.Instantiate(augmentationObject); augmentation.transform.parent = tb.gameObject.transform; augmentation.transform.localPosition = new Vector3(0f, 0f, 0f); augmentation.transform.localRotation = Quaternion.identity; augmentation.transform.localScale = new Vector3(0.005f, 0.005f, 0.005f); augmentation.gameObject.SetActive(true); } else { Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>"); } } } } else { Debug.LogError("<color=yellow>Failed to load dataset: '" + dataSetName + "'</color>"); } } } | cs |
'프로그래밍 > Unity' 카테고리의 다른 글
(유니티) 뷰포리아 - 마커인식할 때마다 다른 오브젝트 띄우기 (0) | 2018.03.21 |
---|---|
(유니티) 뷰포리아 마커 인식 이벤트 설정 (0) | 2018.03.21 |
(유니티) 뷰포리아 (0) | 2018.03.21 |
(유니티) 립모션(leapmotion) 간단한 충돌 예제 (0) | 2018.03.21 |
(유니티) 씬 전환 시 로딩화면 띄우는 방법 (0) | 2018.03.21 |