티스토리 뷰

반응형





안녕하세요. Base Of Coding입니다.

요즘 찾고 있는 정보가 있는데.. 이것저것 뒤져보다가 저는 쓸 일이 없지만

에셋번들 없이 사용하시는 분들께서는 도움이 될 것 같은 것들을 가져왔습니다.


imagetarget 동적할당 하는 부분인데요. 


코드는 아래와 같습니다.


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
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 5.0 to 6.1
        VuforiaBehaviour vb = GameObject.FindObjectOfType<VuforiaBehaviour>();
        vb.RegisterVuforiaStartedCallback(LoadDataSet);
 
        // Vuforia 6.2+
        VuforiaARController.Instance.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>");
        }
    }
}


한번 천천히 분석해가시면서 사용해보시면 좋을 것 같습니다.


출처는 Vuforia 포럼에서 가져왔습니다.


출처 : https://developer.vuforia.com/forum/faq/unity-load-dataset-setup-trackables-runtime


지금까지 Base Of Coding이였습니다.



- 이 글에 도움이 되셨다면, 공감(♡) 버튼과 댓글 부탁드리겠습니다. - 


반응형
댓글
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
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
글 보관함