Exemple #1
0
    public IEnumerator loadDatasetCoroutine()
    {
        Landmark landmark = exp.getLandmark();

        while (!isSetup || !landmark.getDat().isLoaded() || !landmark.getXML().isLoaded())
        {
            yield return(null);
        }

        t = TrackerManager.Instance.GetTracker <ObjectTracker>();

        if (dataSets.ContainsKey(landmark))
        {
            ds = dataSets[landmark];
        }
        else
        {
            ds = t.CreateDataSet();

            IFileManager iFileManager = ServiceLocator.getIFileManager();
            iFileManager.pushDirectory(iFileManager.getBaseDirectory());

            // TODO: FIX ISSUE w/ LOADING FROM RESOURCES
            if (ds.Load(CachedLoader.convertWebToLocalPath(landmark.getXML().getPath(), PathType.RELATIVE), VuforiaUnity.StorageType.STORAGE_ABSOLUTE))
            {
                dataSets[landmark] = ds;
            }
            else
            {
                IFileManager fm = ServiceLocator.getIFileManager();

                string             paXML = "tmp.xml", paDat = "tmp.dat";
                Reference <string> fileXML = landmark.getXML();
                Reference <byte[]> fileDat = landmark.getDat();

                fm.writeToFile(paXML, fileXML.getResource());
                fm.writeToFile(paDat, fileDat.getResource());

                if (ds.Load(paXML, VuforiaUnity.StorageType.STORAGE_ABSOLUTE))
                {
                    dataSets[landmark] = ds;
                }
                else
                {
                    ds = null;
                }

                fm.deleteFile(paXML);
                fm.deleteFile(paDat);
            }

            iFileManager.popDirectory();
        }

        if (ds != null)
        {
            t.Stop();
            t.ActivateDataSet(ds);
            t.Start();

            IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
            foreach (TrackableBehaviour tb in tbs)
            {
                // change general name to include trackable name
                GameObject tbg = tb.gameObject;

                DefaultTrackableEventThing dtet = GameObjectUtility.GetComponent <DefaultTrackableEventThing>(tbg);
                TurnOffThing tot = GameObjectUtility.GetComponent <TurnOffThing>(tbg);

                if (tb.TrackableName == exp.getId())
                {
                    defaultTracker = dtet;
                    dtet.enabled   = true;

                    if (tb.name != tb.TrackableName)
                    {
                        tb.name = tb.TrackableName;

                        planeGroup = new GameObject("planeGroup");
                        planeGroup.transform.parent        = tbg.transform;
                        planeGroup.transform.localPosition = new Vector3(0f, 0f, 0f);
                        planeGroup.transform.localRotation = Quaternion.identity;

                        overlayPlane = GameObject.CreatePrimitive(PrimitiveType.Plane);
                        overlayPlane.transform.parent = planeGroup.gameObject.transform;
                    }
                    else
                    {
                        planeGroup   = GameObjectUtility.GetChild(tbg, "planeGroup");
                        overlayPlane = GameObjectUtility.GetChild(tbg, "Plane");
                    }

                    planeGroup.SetActive(true);
                }
                else
                {
                    dtet.enabled = false;
                    GameObject planeGroup = GameObjectUtility.GetChild(tbg, "planeGroup");
                    if (planeGroup != null)
                    {
                        planeGroup.SetActive(false);
                    }
                }
            }
        }
        else
        {
            debugMessage = "Failed to load Vuforia!";
        }
    }