// Method for unloading active data sets once user exits the scene. This is to prevent
    // presence of multiple copies of same data sets when re-entering scene.
    public void UnloadActiveDataSets()
    {
        ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

        System.Collections.ObjectModel.ReadOnlyCollection <DataSet> activeDataSets = objectTracker.GetActiveDataSets().ToReadOnlyCollection();

        for (int i = 0; i < activeDataSets.Count; i++)
        {
            DataSet currDataSet = activeDataSets[i];

            StateManager stateManager     = TrackerManager.Instance.GetStateManager();
            List <TrackableBehaviour> tbs = (List <TrackableBehaviour>)TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();

            for (int j = 0; j < tbs.Count; j++)
            {
                if (activeDataSets[i].Contains(tbs[j].Trackable))
                {
                    stateManager.DestroyTrackableBehavioursForTrackable(tbs[j].Trackable, true);
                }
            }

            if (!objectTracker.DeactivateDataSet(currDataSet))
            {
                Debug.Log("Could not deactive data set!");
            }

            if (!objectTracker.DestroyDataSet(currDataSet, false))
            {
                Debug.Log("Could not destroy data set!");
            }
        }
    }
        /// <summary>
        /// 关闭指定识别数据集
        /// </summary>
        /// <param name="datasetName">数据集名称或绝对路径</param>
        public static void DeactivateDateset(string datasetName)
        {
            ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

            IEnumerable <DataSet> activeDataSets = objectTracker.GetActiveDataSets();

            List <DataSet> activeDataSetsToBeRemoved = activeDataSets.ToList();

            List <DataSet> dataSetsToBeActive = new List <DataSet>();

            foreach (DataSet ads in activeDataSetsToBeRemoved)
            {
                objectTracker.DeactivateDataSet(ads);
                if (!ads.Path.Contains(datasetName))
                {
                    dataSetsToBeActive.Add(ads);
                }
                else
                {
                    objectTracker.DestroyDataSet(ads, false);
                    var trackables = ads.GetTrackables();
                    foreach (var item in trackables)
                    {
                        TrackerManager.Instance.GetStateManager().DestroyTrackableBehavioursForTrackable(item, true);
                    }
                }
            }
            objectTracker.Stop();
            foreach (DataSet ds in dataSetsToBeActive)
            {
                objectTracker.ActivateDataSet(ds);
            }
            objectTracker.Start();
        }
Example #3
0
    void UnloadDataSet()
    {
        ObjectTracker tracker = TrackerManager.Instance.GetTracker <ObjectTracker> ();

        if (tracker != null)
        {
            tracker.Stop();
        }
        List <DataSet> activeDataSets = tracker.GetActiveDataSets().ToList();

        if (activeDataSets.Count > 0)
        {
            DataSet ds = activeDataSets.ElementAt(0);
            IEnumerable <Trackable> tbs          = ds.GetTrackables();
            StateManager            stateManager = TrackerManager.Instance.GetStateManager();
            tracker.DeactivateDataSet(ds);
            foreach (Trackable tb in tbs)
            {
                Debug.Log(tb.Name);

                stateManager.DestroyTrackableBehavioursForTrackable(tb, false);
                GameObject ob = GameObject.Find("DynamicImageTarget-" + tb.Name);
                if (ob != null)
                {
                    Debug.Log(tb.Name);
                    ob.SetActive(false);
                    Destroy(ob);
                }
            }
            tracker.DestroyDataSet(ds, false);
            Resources.UnloadUnusedAssets();
        }
        tracker.Start();

        List <DataSet> dataSets = tracker.GetDataSets().ToList();

        if (dataSets.Count > 0)
        {
            foreach (var dataset in dataSets)
            {
                Debug.Log("datasetName------" + GetDataSetName(dataset));
            }
        }
    }