Пример #1
0
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        m_TargetCounter++;

        // Deactivates the dataset first
        m_ObjectTracker.DeactivateDataSet(m_UDT_DataSet);

        // Destroy the oldest target if the dataset is full or the dataset
        // already contains five user-defined targets.
        if (m_UDT_DataSet.HasReachedTrackableLimit() || m_UDT_DataSet.GetTrackables().Count() >= MAX_TARGETS)
        {
            IEnumerable <Trackable> trackables = m_UDT_DataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                m_UDT_DataSet.Destroy(oldest, true);
            }
        }

        // Get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = Instantiate(ImageTargetTemplate);

        imageTargetCopy.gameObject.name = "UserDefinedTarget-" + m_TargetCounter;

        // Add the duplicated trackable to the data set and activate it
        m_UDT_DataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        // Activate the dataset again
        m_ObjectTracker.ActivateDataSet(m_UDT_DataSet);

        // Extended Tracking with user defined targets only works with the most recently defined target.
        // If tracking is enabled on previous target, it will not work on newly defined target.
        // Don't need to call this if you don't care about extended tracking.
        // StopExtendedTracking();
        m_ObjectTracker.Stop();
        // m_ObjectTracker.ResetExtendedTracking();
        m_ObjectTracker.Start();

        // Make sure TargetBuildingBehaviour keeps scanning...
        m_TargetBuildingBehaviour.StartScanning();

        MainManager.GetInstance.BuildDefinedTargetCallback();
    }
Пример #2
0
    private void CreateMissingDataSetTrackableBehaviours(DataSet dataSet)
    {
        foreach (Trackable trackable in dataSet.GetTrackables())
        {
            if (!mTrackableBehaviours.ContainsKey(trackable.ID))
            {
                if (trackable is ImageTarget)
                {
                    ImageTargetBehaviour itb = CreateImageTargetBehaviour((ImageTarget)trackable);

                    // Create Virtual Buttons for this Image Target.
                    ((IEditorImageTargetBehaviour)itb).CreateMissingVirtualButtonBehaviours();

                    // Add newly created Image Target to dictionary.
                    mTrackableBehaviours[trackable.ID] = itb;
                }
                else if (trackable is MultiTarget)
                {
                    MultiTargetBehaviour mtb = CreateMultiTargetBehaviour((MultiTarget)trackable);

                    // Add newly created Multi Target to dictionary.
                    mTrackableBehaviours[trackable.ID] = mtb;
                }
            }
        }
    }
Пример #3
0
    // Deactivates the given dataset.
    // This can only be done when the tracker is not running.
    public override bool DeactivateDataSet(DataSet dataSet)
    {
        if (dataSet == null)
        {
            Debug.LogError("Dataset is null.");
            return(false);
        }

        DataSetImpl dataSetImpl = (DataSetImpl)dataSet;

        if (QCARWrapper.Instance.ImageTrackerDeactivateDataSet(dataSetImpl.DataSetPtr) == 0)
        {
            Debug.LogError("Could not deactivate dataset.");
            return(false);
        }

        StateManagerImpl stateManager = (StateManagerImpl)TrackerManager.Instance.GetStateManager();

        // Deactivate all Trackables.
        foreach (Trackable trackable in dataSet.GetTrackables())
        {
            stateManager.EnableTrackableBehavioursForTrackable(trackable, false);
        }

        mActiveDataSets.Remove(dataSetImpl);
        return(true);
    }
Пример #4
0
 private void CreateMissingDataSetTrackableBehaviours(DataSet dataSet)
 {
     foreach (Trackable trackable in dataSet.GetTrackables())
     {
         if (!this.mTrackableBehaviours.ContainsKey(trackable.ID))
         {
             if (trackable is ImageTarget)
             {
                 ImageTargetAbstractBehaviour behaviour = this.CreateImageTargetBehaviour((ImageTarget)trackable);
                 ((IEditorImageTargetBehaviour)behaviour).CreateMissingVirtualButtonBehaviours();
                 this.mTrackableBehaviours[trackable.ID] = behaviour;
                 this.mAutomaticallyCreatedBehaviours.Add(trackable.ID);
             }
             else if (trackable is MultiTarget)
             {
                 MultiTargetAbstractBehaviour behaviour2 = this.CreateMultiTargetBehaviour((MultiTarget)trackable);
                 this.mTrackableBehaviours[trackable.ID] = behaviour2;
                 this.mAutomaticallyCreatedBehaviours.Add(trackable.ID);
             }
             else if (trackable is CylinderTarget)
             {
                 CylinderTargetAbstractBehaviour behaviour3 = this.CreateCylinderTargetBehaviour((CylinderTarget)trackable);
                 this.mTrackableBehaviours[trackable.ID] = behaviour3;
                 this.mAutomaticallyCreatedBehaviours.Add(trackable.ID);
             }
         }
     }
 }
Пример #5
0
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {                                                                     //将新的目标添加到数据集
        count++;
        objectTracker.DeactivateDataSet(dataSet);                         //禁用数据集
        if (dataSet.HasReachedTrackableLimit())                           //数据集上限
        {
            IEnumerable <Trackable> trackables = dataSet.GetTrackables(); //拿到数据集
            Trackable oldTrackable             = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldTrackable.ID > trackable.ID || oldTrackable == null)
                {
                    oldTrackable = trackable;
                }
            }
            if (oldTrackable != null)
            {
                dataSet.Destroy(oldTrackable, true);//删除最早的数据
            }
        }
        ImageTargetBehaviour imageTargetCopy = Instantiate(ImageTarget);

        imageTargetCopy.gameObject.name = "UseTarget_" + count;               //修改名字
        dataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject); //创建到数据集
        objectTracker.ActivateDataSet(dataSet);                               //激活数据库
    }
Пример #6
0
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        // deactivates the dataset first
        mObjectTracker.DeactivateDataSet(mBuiltDataSet);

        // Destroy the oldest target if the dataset is full
        if (mBuiltDataSet.HasReachedTrackableLimit())
        {
            IEnumerable <Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }
            if (oldest != null)
            {
                mBuiltDataSet.Destroy(oldest, true);
            }
        }

        // get predefined trackable (template) and instantiate it
        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);

        // add the trackable to the data set and activate it
        mBuiltDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        // Re-activate the dataset
        mObjectTracker.ActivateDataSet(mBuiltDataSet);
    }
Пример #7
0
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        mTargetCounter++;

        // deactivates the dataset first
        mImageTracker.DeactivateDataSet(mBuiltDataSet);

        // Destroy the oldest target if the dataset is full or the dataset
        // already contains five user-defined targets.
        if (mBuiltDataSet.HasReachedTrackableLimit() || mBuiltDataSet.GetTrackables().Count() >= 5)
        {
            IEnumerable <Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                mBuiltDataSet.Destroy(oldest, true);
            }
        }

        // get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);

        imageTargetCopy.gameObject.name = "UserDefinedTarget-" + mTargetCounter;

        // add the duplicated trackable to the data set and activate it
        mBuiltDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);


        // activate the dataset again
        mImageTracker.ActivateDataSet(mBuiltDataSet);

        //Extended Tracking with user defined targets only works with the most recently defined target.
        //If tracking is enabled on previous target, it will not work on newly defined target.
        //Don't need to call this if you don't care about extended tracking.
        StopExtendedTracking();
    }
Пример #8
0
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        mTargetCounter++;

        // Deactivates the dataset first
        mObjectTracker.DeactivateDataSet(mBuiltDataSet);

        // Destroy the oldest target if the dataset is full or the dataset
        // already contains five user-defined targets.
        if (mBuiltDataSet.HasReachedTrackableLimit() || mBuiltDataSet.GetTrackables().Count() >= MAX_TARGETS)
        {
            IEnumerable <Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                mBuiltDataSet.Destroy(oldest, true);
            }
        }

        // Get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);

        imageTargetCopy.gameObject.name = "UserDefinedTarget-" + mTargetCounter;

        // Add the duplicated trackable to the data set and activate it
        mBuiltDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        // Activate the dataset again
        mObjectTracker.ActivateDataSet(mBuiltDataSet);

        mObjectTracker.Stop();
        mObjectTracker.ResetExtendedTracking();
        mObjectTracker.Start();
    }
Пример #9
0
        /// <summary>
        /// Takes a new trackable source and adds it to the dataset
        /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
        /// </summary>
        public void OnNewTrackableSource(TrackableSource trackableSource)
        {
            _targetCounter++;

            // Deactivates the dataset first
            _objectTracker.DeactivateDataSet(_udtDataSet);

            // Destroy the oldest target if the dataset is full or the dataset
            // already contains five user-defined targets.
            if (_udtDataSet.HasReachedTrackableLimit() || _udtDataSet.GetTrackables().Count() >= MaxTargets)
            {
                var       trackables = _udtDataSet.GetTrackables();
                Trackable oldest     = null;
                foreach (var trackable in trackables)
                {
                    if (oldest == null || trackable.ID < oldest.ID)
                    {
                        oldest = trackable;
                    }
                }

                if (oldest != null)
                {
                    Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                    _udtDataSet.Destroy(oldest, true);
                }
            }

            // Get predefined trackable and instantiate it
            var imageTargetCopy = Instantiate(ImageTargetTemplate);

            imageTargetCopy.gameObject.name = "UserDefinedTarget-" + _targetCounter;

            // Add the duplicated trackable to the data set and activate it
            _udtDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

            // Activate the dataset again
            _objectTracker.ActivateDataSet(_udtDataSet);

            // Make sure TargetBuildingBehaviour keeps scanning...
            _targetBuildingBehaviour.StartScanning();
        }
Пример #10
0
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        mTargetCounter++;

        // Deactivates the dataset first
        mObjectTracker.DeactivateDataSet(mBuiltDataSet);

        // Destroy the oldest target if the dataset is full or the dataset
        // already contains five user-defined targets.
        if (mBuiltDataSet.HasReachedTrackableLimit() || mBuiltDataSet.GetTrackables().Count() >= MAX_TARGETS)
        {
            IEnumerable <Trackable> trackables = mBuiltDataSet.GetTrackables();
            foreach (Trackable trackable in trackables)
            {
                mBuiltDataSet.Destroy(trackable, true);
            }
        }


        // Get predefined trackable and instantiate it       -----  Add more targets

        /*ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);
         * imageTargetCopy.gameObject.name = "UserDefinedTarget-" + mTargetCounter;*/

        // Add the duplicated trackable to the data set and activate it
        mBuiltDataSet.CreateTrackable(trackableSource, ImageTargetTemplate.gameObject);

        // Activate the dataset again
        mObjectTracker.ActivateDataSet(mBuiltDataSet);

        // Extended Tracking with user defined targets only works with the most recently defined target.
        // If tracking is enabled on previous target, it will not work on newly defined target.
        // Don't need to call this if you don't care about extended tracking.
        StopExtendedTracking();
        mObjectTracker.Stop();
        mObjectTracker.ResetExtendedTracking();
        mObjectTracker.Start();
    }
Пример #11
0
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        m_objectTracker.Stop();   //停止追踪才能激活数据集  
                m_TargetCounter++;

        m_objectTracker.DeactivateDataSet(m_BuildDataSet); //创建一个新的数据集  
                                                           //如果trackable满了或者已经定义了5个识别对象,那么删除旧的DataSet  
                if (m_BuildDataSet.HasReachedTrackableLimit() || m_BuildDataSet.GetTrackables().Count() > 5)
        {
            IEnumerable <Trackable> trackables = m_BuildDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                m_BuildDataSet.Destroy(oldest, true);
            }
        }


        //定义Trackable并实例化  
        ImageTargetBehaviour imageTargetCopy = Instantiate(ImageTargetTemplate);

        //Instantiate<ImageTargetBehaviour>()(ImageTargetTemplate);  
        imageTargetCopy.gameObject.name = "UserDefinedTarget-" + m_TargetCounter;
        //复制一个Trckable到imageTargetCopy上并让它激活  
        m_BuildDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);
        m_objectTracker.ActivateDataSet(m_BuildDataSet);
        m_objectTracker.Start();
    }
Пример #12
0
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        m_TargetCount++;                              //每新增一次识别图,m_TargetCount自增一次

        m_ObjectTracker.DeactivateDataSet(m_DataSet); //关闭数据集
                                                      //当数据饱和或者大于设定数字5的时候,删除最初保存的那个数据,以此类推

        if (m_DataSet.HasReachedTrackableLimit() || m_DataSet.GetTrackables().Count() >= 5)
        {
            IEnumerable <Trackable> trackables = m_DataSet.GetTrackables();

            Trackable oldest = null;

            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }
            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);

                m_DataSet.Destroy(oldest, true);
            }
        }
        //创建一个新的ImageTarget,并为其命名
        ImageTargetBehaviour ImageTBCopy = (ImageTargetBehaviour)Instantiate(m_ImageTarget);

        ImageTBCopy.gameObject.name = "CustomImageTarget-" + m_TargetCount;
        //将创建过的ImageTarget添加到数据集中
        m_DataSet.CreateTrackable(trackableSource, ImageTBCopy.gameObject);
        //激活数据集
        m_ObjectTracker.ActivateDataSet(m_DataSet);
    }
Пример #13
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));
            }
        }
    }
Пример #14
0
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        // Deactivates the dataset first
        m_ObjectTracker.DeactivateDataSet(m_UDT_DataSet);

        // Destroy the oldest target in the dataset if a new target is created
        IEnumerable <Trackable> trackables = m_UDT_DataSet.GetTrackables();
        Trackable oldest = null;

        //fetch for the last target to destroy it
        foreach (Trackable trackable in trackables)
        {
            if (oldest == null || trackable.ID < oldest.ID)
            {
                oldest = trackable;
            }
        }
        if (oldest != null)
        {
            Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
            m_UDT_DataSet.Destroy(oldest, true);
        }


        // Get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = Instantiate(ImageTargetTemplate);

        imageTargetCopy.gameObject.name = "USERTARGET";
        // Add the duplicated trackable to the data set and activate it
        m_UDT_DataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        // Activate the dataset again
        m_ObjectTracker.ActivateDataSet(m_UDT_DataSet);

        m_ObjectTracker.Stop();
        m_ObjectTracker.ResetExtendedTracking();
        m_ObjectTracker.Start();

        // Make sure TargetBuildingBehaviour keeps scanning...
        m_TargetBuildingBehaviour.StartScanning();
    }
    private void ActivateGloveTargetTracking(int guideViewIndex = 0)
    {
        foreach (TrackableBehaviour trackableBehaviour in mAllTargets)
        {
            print(trackableBehaviour.TrackableName);
        }
        //get the object tracker instance
        ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker>();

        if (objectTracker == null)
        {
            return;
        }
        objectTracker.Stop();

        //load dataset
        DataSet gloveTargetDataSet = objectTracker.CreateDataSet();

        gloveTargetDataSet.Load(mainGloveTarget);
        foreach (Trackable trackable in gloveTargetDataSet.GetTrackables())
        {
            if (trackable is ModelTarget)
            {
                ModelTarget mTrackable = trackable as ModelTarget;
                mTrackable.SetActiveGuideViewIndex(guideViewIndex);
            }
        }

        objectTracker.ActivateDataSet(gloveTargetDataSet);

        //restart tracking
        objectTracker.Start();

        foreach (TrackableBehaviour trackableBehaviour in GetTargets())
        {
            print(trackableBehaviour.TrackableName);
        }
    }
Пример #16
0
    private void CreateMissingDataSetTrackableBehaviours(DataSet dataSet)
    {
        foreach (Trackable trackable in dataSet.GetTrackables())
        {
            if (!mTrackableBehaviours.ContainsKey(trackable.ID))
            {
                if (trackable is ImageTarget)
                {
                    ImageTargetBehaviour itb = CreateImageTargetBehaviour((ImageTarget)trackable);

                    // Create Virtual Buttons for this Image Target.
                    ((IEditorImageTargetBehaviour)itb).CreateMissingVirtualButtonBehaviours();

                    // Add newly created Image Target to dictionary.
                    mTrackableBehaviours[trackable.ID] = itb;
                }
                else if (trackable is MultiTarget)
                {
                    MultiTargetBehaviour mtb = CreateMultiTargetBehaviour((MultiTarget)trackable);

                    // Add newly created Multi Target to dictionary.
                    mTrackableBehaviours[trackable.ID] = mtb;
                }
            }
        }
    }
Пример #17
0
    /// <summary>
    /// Finds DataSetTrackableBehaviours for this dataset and associates them with the Trackables in the DataSet.
    /// VirtualButtonBehaviours created in the scene are associated with the VirtualButtons in the DataSet or created there.
    /// 
    /// If there is a Trackable in the DataSet where no TrackableBehaviour exists yet, this Behaviour is created, together with its VirtualButtons.
    /// </summary>
    public void AssociateTrackableBehavioursForDataSet(DataSet dataSet)
    {
        // Step: Add all TrackableBehaviours that belong to this data set and
        // are already instantiated in the scene to the dictionary.
        DataSetTrackableBehaviour[] trackableBehaviours = (DataSetTrackableBehaviour[])
            Object.FindObjectsOfType(typeof(DataSetTrackableBehaviour));

        // Initialize all Image Targets
        foreach (DataSetTrackableBehaviour trackableBehaviour in trackableBehaviours)
        {
            IEditorDataSetTrackableBehaviour editorTrackableBehaviour = trackableBehaviour;
            if (editorTrackableBehaviour.TrackableName == null)
            {
                Debug.LogError("Found Trackable without name.");
                continue;
            }

            // check if the TrackableBehaviour references this DataSet
            if (editorTrackableBehaviour.DataSetPath.Equals(dataSet.Path))
            {
                bool matchFound = false;

                // find the trackable to be associated with this TrackableBehaviour:
                foreach(Trackable trackable in dataSet.GetTrackables())
                {
                    if (trackable.Name.Equals(editorTrackableBehaviour.TrackableName))
                    {
                        if (trackableBehaviour is ImageTargetBehaviour &&
                            trackable is ImageTarget)
                        {
                            IEditorImageTargetBehaviour editorImageTargetBehaviour = (ImageTargetBehaviour)trackableBehaviour;

                            matchFound = true;

                            editorImageTargetBehaviour.InitializeImageTarget((ImageTarget)trackable);
                            mTrackableBehaviours[trackable.ID] = trackableBehaviour;
                            Debug.Log("Found Trackable named " + trackableBehaviour.Trackable.Name +
                                        " with id " + trackableBehaviour.Trackable.ID);
                        }
                        else if (trackableBehaviour is MultiTargetBehaviour &&
                                 trackable is MultiTarget)
                        {
                            matchFound = true;

                            IEditorMultiTargetBehaviour editorMultiTargetBehaviour = (MultiTargetBehaviour)trackableBehaviour;
                            editorMultiTargetBehaviour.InitializeMultiTarget((MultiTarget)trackable);
                            mTrackableBehaviours[trackable.ID] = trackableBehaviour;
                            Debug.Log("Found Trackable named " + trackableBehaviour.Trackable.Name +
                                        " with id " + trackableBehaviour.Trackable.ID);
                        }
                    }
                }

                if (!matchFound)
                {
                    Debug.LogError("Could not associate DataSetTrackableBehaviour '" + editorTrackableBehaviour.TrackableName +
                        "' - no matching Trackable found in DataSet!");
                }
            }
        }

        // Step 2: Add all VirtualButtonBehaviours that belong to this data set
        // and are already instantiated in the scene to the dictionary.
        VirtualButtonBehaviour[] vbBehaviours = (VirtualButtonBehaviour[])
            Object.FindObjectsOfType(typeof(VirtualButtonBehaviour));
        AssociateVirtualButtonBehaviours(vbBehaviours, dataSet);

        // Step 3: Create TrackableBehaviours that are not existing in the scene.
        CreateMissingDataSetTrackableBehaviours(dataSet);
    }
Пример #18
0
    /// <summary>
    /// Finds DataSetTrackableBehaviours for this dataset and associates them with the Trackables in the DataSet.
    /// VirtualButtonBehaviours created in the scene are associated with the VirtualButtons in the DataSet or created there.
    /// 
    /// If there is a Trackable in the DataSet where no TrackableBehaviour exists yet, this Behaviour is created, together with its VirtualButtons.
    /// </summary>
    public void AssociateTrackableBehavioursForDataSet(DataSet dataSet)
    {
        // Step: Add all TrackableBehaviours that belong to this data set and
        // are already instantiated in the scene to the dictionary.
        DataSetTrackableBehaviour[] trackableBehaviours = (DataSetTrackableBehaviour[])
            Object.FindObjectsOfType(typeof(DataSetTrackableBehaviour));

        // Initialize all Image Targets
        foreach (DataSetTrackableBehaviour trackableBehaviour in trackableBehaviours)
        {
            // trackable has been destroyed and shouldn't be associated
            if (mBehavioursMarkedForDeletion.Contains(trackableBehaviour))
                continue;

            IEditorDataSetTrackableBehaviour editorTrackableBehaviour = trackableBehaviour;
            if (editorTrackableBehaviour.TrackableName == null)
            {
                Debug.LogError("Found Trackable without name.");
                continue;
            }

            // check if the TrackableBehaviour references this DataSet
            if (editorTrackableBehaviour.DataSetPath.Equals(dataSet.Path))
            {
                bool matchFound = false;

                // find the trackable to be associated with this TrackableBehaviour:
                foreach(Trackable trackable in dataSet.GetTrackables())
                {
                    if (trackable.Name.Equals(editorTrackableBehaviour.TrackableName))
                    {
                        if (mTrackableBehaviours.ContainsKey(trackable.ID))
                        {
                            // don't replace existing behaviour if it has been created manually
                            if (!mAutomaticallyCreatedBehaviours.Contains(trackable.ID) && !mBehavioursMarkedForDeletion.Contains(mTrackableBehaviours[trackable.ID]))
                            {
                                matchFound = true;
                                continue;
                            }

                            // destroy automatically created behaviour - will be replaced by new one
                            Object.Destroy(mTrackableBehaviours[trackable.ID].gameObject);
                            mTrackableBehaviours.Remove(trackable.ID);
                            mAutomaticallyCreatedBehaviours.Remove(trackable.ID);
                        }

                        if (trackableBehaviour is ImageTargetBehaviour &&
                            trackable is ImageTarget)
                        {
                            IEditorImageTargetBehaviour editorImageTargetBehaviour = (ImageTargetBehaviour)trackableBehaviour;

                            matchFound = true;

                            editorImageTargetBehaviour.InitializeImageTarget((ImageTarget)trackable);
                            mTrackableBehaviours[trackable.ID] = trackableBehaviour;
                            Debug.Log("Found Trackable named " + trackableBehaviour.Trackable.Name +
                                        " with id " + trackableBehaviour.Trackable.ID);
                        }
                        else if (trackableBehaviour is MultiTargetBehaviour &&
                                 trackable is MultiTarget)
                        {
                            matchFound = true;

                            IEditorMultiTargetBehaviour editorMultiTargetBehaviour = (MultiTargetBehaviour)trackableBehaviour;
                            editorMultiTargetBehaviour.InitializeMultiTarget((MultiTarget)trackable);
                            mTrackableBehaviours[trackable.ID] = trackableBehaviour;
                            Debug.Log("Found Trackable named " + trackableBehaviour.Trackable.Name +
                                        " with id " + trackableBehaviour.Trackable.ID);
                        }
                        else if (trackableBehaviour is CylinderTargetBehaviour &&
                                 trackable is CylinderTarget)
                        {
                            matchFound = true;

                            IEditorCylinderTargetBehaviour editorCylinderTargetBehaviour = (CylinderTargetBehaviour)trackableBehaviour;
                            editorCylinderTargetBehaviour.InitializeCylinderTarget((CylinderTarget)trackable);
                            mTrackableBehaviours[trackable.ID] = trackableBehaviour;
                            Debug.Log("Found Trackable named " + trackableBehaviour.Trackable.Name +
                                        " with id " + trackableBehaviour.Trackable.ID);
                        }
                    }
                }

                if (!matchFound)
                {
                    Debug.LogError("Could not associate DataSetTrackableBehaviour '" + editorTrackableBehaviour.TrackableName +
                        "' - no matching Trackable found in DataSet!");
                }
            }
        }

        // Step 2: Add all VirtualButtonBehaviours that belong to this data set
        // and are already instantiated in the scene to the dictionary.
        VirtualButtonBehaviour[] vbBehaviours = (VirtualButtonBehaviour[])
            Object.FindObjectsOfType(typeof(VirtualButtonBehaviour));
        AssociateVirtualButtonBehaviours(vbBehaviours, dataSet);

        // Step 3: Create TrackableBehaviours that are not existing in the scene.
        CreateMissingDataSetTrackableBehaviours(dataSet);
    }
Пример #19
0
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        mTargetCounter++;

        // Deactivates the dataset first
        mObjectTracker.DeactivateDataSet(mBuiltDataSet);

        // Destroy the oldest target if the dataset is full or the dataset
        // already contains five user-defined targets.
        if (mBuiltDataSet.HasReachedTrackableLimit() || mBuiltDataSet.GetTrackables().Count() >= MAX_TARGETS)
        {
            IEnumerable <Trackable> trackables = mBuiltDataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                mBuiltDataSet.Destroy(oldest, true);
            }
        }

        // Get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = (ImageTargetBehaviour)Instantiate(ImageTargetTemplate);

        imageTargetCopy.gameObject.name = "UserDefinedTarget-" + mTargetCounter;

        // Add the duplicated trackable to the data set and activate it
        mBuiltDataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        // Activate the dataset again
        mObjectTracker.ActivateDataSet(mBuiltDataSet);

        // Extended Tracking with user defined targets only works with the most recently defined target.
        // If tracking is enabled on previous target, it will not work on newly defined target.
        // Don't need to call this if you don't care about extended tracking.
        StopExtendedTracking();
        mObjectTracker.Stop();
        mObjectTracker.ResetExtendedTracking();
        mObjectTracker.Start();

        //Edited part according to application requirements
        Button     settings_button;
        GameObject BuildPanel;
        GameObject click_button;

        GameObject[] created_target;
        click_button        = GameObject.Find("BuildButton");
        click_button.active = false;
        BuildPanel          = GameObject.Find("BuildPanel");
        BuildPanel.active   = false;
        ImageTargetTemplate.gameObject.active = false;
        settings_button = GameObject.FindGameObjectWithTag("settings_button").GetComponent <Button>();
        settings_button.onClick.Invoke();
        //Edited part ends here

        // Make sure TargetBuildingBehaviour keeps scanning...
        mTargetBuildingBehaviour.StartScanning();
    }
Пример #20
0
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        m_TargetCounter++;

        // Deactivates the dataset first
        m_ObjectTracker.DeactivateDataSet(m_UDT_DataSet);

        // Destroy the oldest target if the dataset is full or the dataset
        // already contains five user-defined targets.
        int Max = 2;

        //if (controlador.GetTipoARcapturar())
        //{
        //    Max = MAX_TARGETS_GAME_MODE;
        //}
        //else
        //{
        //    Max = MAX_TARGETS;
        //}
        if (!controlador.GetIsMultiTarget())
        {
            Max = MAX_TARGETS_GAME_MODE;
        }
        else
        {
            Max = MAX_TARGETS;
        }

        if (m_UDT_DataSet.HasReachedTrackableLimit() || m_UDT_DataSet.GetTrackables().Count() >= Max)
        {
            IEnumerable <Trackable> trackables = m_UDT_DataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                m_UDT_DataSet.Destroy(oldest, true);
            }
        }

        // Get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy = Instantiate(ImageTargetTemplate);

        imageTargetCopy.gameObject.name = "UserDefinedTarget-" + m_TargetCounter;

        // Add the duplicated trackable to the data set and activate it
        m_UDT_DataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        // Activate the dataset again
        m_ObjectTracker.ActivateDataSet(m_UDT_DataSet);

        // Make sure TargetBuildingBehaviour keeps scanning...
        m_TargetBuildingBehaviour.StartScanning();
    }
Пример #21
0
 internal void AssociateTrackableBehavioursForDataSet(DataSet dataSet)
 {
     DataSetTrackableBehaviour[] behaviourArray = (DataSetTrackableBehaviour[])UnityEngine.Object.FindObjectsOfType(typeof(DataSetTrackableBehaviour));
     foreach (DataSetTrackableBehaviour behaviour in behaviourArray)
     {
         if (!this.mBehavioursMarkedForDeletion.Contains(behaviour))
         {
             IEditorDataSetTrackableBehaviour behaviour2 = behaviour;
             if (behaviour2.TrackableName == null)
             {
                 Debug.LogError("Found Trackable without name.");
             }
             else if (behaviour2.DataSetPath.Equals(dataSet.Path))
             {
                 bool flag = false;
                 foreach (Trackable trackable in dataSet.GetTrackables())
                 {
                     if (trackable.Name.Equals(behaviour2.TrackableName))
                     {
                         if (this.mTrackableBehaviours.ContainsKey(trackable.ID))
                         {
                             if (!this.mAutomaticallyCreatedBehaviours.Contains(trackable.ID) && !this.mBehavioursMarkedForDeletion.Contains(this.mTrackableBehaviours[trackable.ID]))
                             {
                                 flag = true;
                                 continue;
                             }
                             UnityEngine.Object.Destroy(this.mTrackableBehaviours[trackable.ID].gameObject);
                             this.mTrackableBehaviours.Remove(trackable.ID);
                             this.mAutomaticallyCreatedBehaviours.Remove(trackable.ID);
                         }
                         if ((behaviour is ImageTargetAbstractBehaviour) && (trackable is ImageTarget))
                         {
                             IEditorImageTargetBehaviour behaviour3 = (ImageTargetAbstractBehaviour)behaviour;
                             flag = true;
                             behaviour3.InitializeImageTarget((ImageTarget)trackable);
                             this.mTrackableBehaviours[trackable.ID] = behaviour;
                             Debug.Log(string.Concat(new object[] { "Found Trackable named ", behaviour.Trackable.Name, " with id ", behaviour.Trackable.ID }));
                         }
                         else if ((behaviour is MultiTargetAbstractBehaviour) && (trackable is MultiTarget))
                         {
                             flag = true;
                             IEditorMultiTargetBehaviour behaviour4 = (MultiTargetAbstractBehaviour)behaviour;
                             behaviour4.InitializeMultiTarget((MultiTarget)trackable);
                             this.mTrackableBehaviours[trackable.ID] = behaviour;
                             Debug.Log(string.Concat(new object[] { "Found Trackable named ", behaviour.Trackable.Name, " with id ", behaviour.Trackable.ID }));
                         }
                         else if ((behaviour is CylinderTargetAbstractBehaviour) && (trackable is CylinderTarget))
                         {
                             flag = true;
                             IEditorCylinderTargetBehaviour behaviour5 = (CylinderTargetAbstractBehaviour)behaviour;
                             behaviour5.InitializeCylinderTarget((CylinderTarget)trackable);
                             this.mTrackableBehaviours[trackable.ID] = behaviour;
                             Debug.Log(string.Concat(new object[] { "Found Trackable named ", behaviour.Trackable.Name, " with id ", behaviour.Trackable.ID }));
                         }
                         else if ((behaviour is IEditorRigidBodyTargetBehaviour) && (trackable is InternalRigidBodyTarget))
                         {
                             flag = true;
                             ((IEditorRigidBodyTargetBehaviour)behaviour).InitializeRigidBodyTarget((InternalRigidBodyTarget)trackable);
                             this.mTrackableBehaviours[trackable.ID] = behaviour;
                             Debug.Log(string.Concat(new object[] { "Found Trackable named ", behaviour.Trackable.Name, " with id ", behaviour.Trackable.ID }));
                         }
                     }
                 }
                 if (!flag)
                 {
                     Debug.LogError("Could not associate DataSetTrackableBehaviour '" + behaviour2.TrackableName + "' - no matching Trackable found in DataSet!");
                 }
             }
         }
     }
     VirtualButtonAbstractBehaviour[] vbBehaviours = (VirtualButtonAbstractBehaviour[])UnityEngine.Object.FindObjectsOfType(typeof(VirtualButtonAbstractBehaviour));
     this.AssociateVirtualButtonBehaviours(vbBehaviours, dataSet);
     this.CreateMissingDataSetTrackableBehaviours(dataSet);
 }
Пример #22
0
    /// <summary>
    /// Finds DataSetTrackableBehaviours for this dataset and associates them with the Trackables in the DataSet.
    /// VirtualButtonBehaviours created in the scene are associated with the VirtualButtons in the DataSet or created there.
    ///
    /// If there is a Trackable in the DataSet where no TrackableBehaviour exists yet, this Behaviour is created, together with its VirtualButtons.
    /// </summary>
    public void AssociateTrackableBehavioursForDataSet(DataSet dataSet)
    {
        // Step: Add all TrackableBehaviours that belong to this data set and
        // are already instantiated in the scene to the dictionary.
        DataSetTrackableBehaviour[] trackableBehaviours = (DataSetTrackableBehaviour[])
                                                          Object.FindObjectsOfType(typeof(DataSetTrackableBehaviour));

        // Initialize all Image Targets
        foreach (DataSetTrackableBehaviour trackableBehaviour in trackableBehaviours)
        {
            IEditorDataSetTrackableBehaviour editorTrackableBehaviour = trackableBehaviour;
            if (editorTrackableBehaviour.TrackableName == null)
            {
                Debug.LogError("Found Trackable without name.");
                continue;
            }

            // check if the TrackableBehaviour references this DataSet
            if (editorTrackableBehaviour.DataSetPath.Equals(dataSet.Path))
            {
                bool matchFound = false;

                // find the trackable to be associated with this TrackableBehaviour:
                foreach (Trackable trackable in dataSet.GetTrackables())
                {
                    if (trackable.Name.Equals(editorTrackableBehaviour.TrackableName))
                    {
                        if (trackableBehaviour is ImageTargetBehaviour &&
                            trackable is ImageTarget)
                        {
                            IEditorImageTargetBehaviour editorImageTargetBehaviour = (ImageTargetBehaviour)trackableBehaviour;

                            matchFound = true;

                            editorImageTargetBehaviour.InitializeImageTarget((ImageTarget)trackable);
                            mTrackableBehaviours[trackable.ID] = trackableBehaviour;
                            Debug.Log("Found Trackable named " + trackableBehaviour.Trackable.Name +
                                      " with id " + trackableBehaviour.Trackable.ID);
                        }
                        else if (trackableBehaviour is MultiTargetBehaviour &&
                                 trackable is MultiTarget)
                        {
                            matchFound = true;

                            IEditorMultiTargetBehaviour editorMultiTargetBehaviour = (MultiTargetBehaviour)trackableBehaviour;
                            editorMultiTargetBehaviour.InitializeMultiTarget((MultiTarget)trackable);
                            mTrackableBehaviours[trackable.ID] = trackableBehaviour;
                            Debug.Log("Found Trackable named " + trackableBehaviour.Trackable.Name +
                                      " with id " + trackableBehaviour.Trackable.ID);
                        }
                    }
                }

                if (!matchFound)
                {
                    Debug.LogError("Could not associate DataSetTrackableBehaviour '" + editorTrackableBehaviour.TrackableName +
                                   "' - no matching Trackable found in DataSet!");
                }
            }
        }


        // Step 2: Add all VirtualButtonBehaviours that belong to this data set
        // and are already instantiated in the scene to the dictionary.
        VirtualButtonBehaviour[] vbBehaviours = (VirtualButtonBehaviour[])
                                                Object.FindObjectsOfType(typeof(VirtualButtonBehaviour));
        AssociateVirtualButtonBehaviours(vbBehaviours, dataSet);

        // Step 3: Create TrackableBehaviours that are not existing in the scene.
        CreateMissingDataSetTrackableBehaviours(dataSet);
    }
    /// <summary>
    /// Finds DataSetTrackableBehaviours for this dataset and associates them with the Trackables in the DataSet.
    /// VirtualButtonBehaviours created in the scene are associated with the VirtualButtons in the DataSet or created there.
    ///
    /// If there is a Trackable in the DataSet where no TrackableBehaviour exists yet, this Behaviour is created, together with its VirtualButtons.
    /// </summary>
    public void AssociateTrackableBehavioursForDataSet(DataSet dataSet)
    {
        // Step: Add all TrackableBehaviours that belong to this data set and
        // are already instantiated in the scene to the dictionary.
        DataSetTrackableBehaviour[] trackableBehaviours = (DataSetTrackableBehaviour[])
                                                          Object.FindObjectsOfType(typeof(DataSetTrackableBehaviour));

        // Initialize all Image Targets
        foreach (DataSetTrackableBehaviour trackableBehaviour in trackableBehaviours)
        {
            // trackable has been destroyed and shouldn't be associated
            if (mBehavioursMarkedForDeletion.Contains(trackableBehaviour))
            {
                continue;
            }

            IEditorDataSetTrackableBehaviour editorTrackableBehaviour = trackableBehaviour;
            if (editorTrackableBehaviour.TrackableName == null)
            {
                Debug.LogError("Found Trackable without name.");
                continue;
            }

            // check if the TrackableBehaviour references this DataSet
            if (editorTrackableBehaviour.DataSetPath.Equals(dataSet.Path))
            {
                bool matchFound = false;

                // find the trackable to be associated with this TrackableBehaviour:
                foreach (Trackable trackable in dataSet.GetTrackables())
                {
                    if (trackable.Name.Equals(editorTrackableBehaviour.TrackableName))
                    {
                        if (mTrackableBehaviours.ContainsKey(trackable.ID))
                        {
                            // don't replace existing behaviour if it has been created manually
                            if (!mAutomaticallyCreatedBehaviours.Contains(trackable.ID) && !mBehavioursMarkedForDeletion.Contains(mTrackableBehaviours[trackable.ID]))
                            {
                                matchFound = true;
                                continue;
                            }

                            // destroy automatically created behaviour - will be replaced by new one
                            Object.Destroy(mTrackableBehaviours[trackable.ID].gameObject);
                            mTrackableBehaviours.Remove(trackable.ID);
                            mAutomaticallyCreatedBehaviours.Remove(trackable.ID);
                        }

                        if (trackableBehaviour is ImageTargetBehaviour &&
                            trackable is ImageTarget)
                        {
                            IEditorImageTargetBehaviour editorImageTargetBehaviour = (ImageTargetBehaviour)trackableBehaviour;

                            matchFound = true;

                            editorImageTargetBehaviour.InitializeImageTarget((ImageTarget)trackable);
                            mTrackableBehaviours[trackable.ID] = trackableBehaviour;
                            Debug.Log("Found Trackable named " + trackableBehaviour.Trackable.Name +
                                      " with id " + trackableBehaviour.Trackable.ID);
                        }
                        else if (trackableBehaviour is MultiTargetBehaviour &&
                                 trackable is MultiTarget)
                        {
                            matchFound = true;

                            IEditorMultiTargetBehaviour editorMultiTargetBehaviour = (MultiTargetBehaviour)trackableBehaviour;
                            editorMultiTargetBehaviour.InitializeMultiTarget((MultiTarget)trackable);
                            mTrackableBehaviours[trackable.ID] = trackableBehaviour;
                            Debug.Log("Found Trackable named " + trackableBehaviour.Trackable.Name +
                                      " with id " + trackableBehaviour.Trackable.ID);
                        }
                        else if (trackableBehaviour is CylinderTargetBehaviour &&
                                 trackable is CylinderTarget)
                        {
                            matchFound = true;

                            IEditorCylinderTargetBehaviour editorCylinderTargetBehaviour = (CylinderTargetBehaviour)trackableBehaviour;
                            editorCylinderTargetBehaviour.InitializeCylinderTarget((CylinderTarget)trackable);
                            mTrackableBehaviours[trackable.ID] = trackableBehaviour;
                            Debug.Log("Found Trackable named " + trackableBehaviour.Trackable.Name +
                                      " with id " + trackableBehaviour.Trackable.ID);
                        }
                    }
                }

                if (!matchFound)
                {
                    Debug.LogError("Could not associate DataSetTrackableBehaviour '" + editorTrackableBehaviour.TrackableName +
                                   "' - no matching Trackable found in DataSet!");
                }
            }
        }

        // Step 2: Add all VirtualButtonBehaviours that belong to this data set
        // and are already instantiated in the scene to the dictionary.
        VirtualButtonBehaviour[] vbBehaviours = (VirtualButtonBehaviour[])
                                                Object.FindObjectsOfType(typeof(VirtualButtonBehaviour));
        AssociateVirtualButtonBehaviours(vbBehaviours, dataSet);

        // Step 3: Create TrackableBehaviours that are not existing in the scene.
        CreateMissingDataSetTrackableBehaviours(dataSet);
    }
Пример #24
0
    void LoadDataSet()
    {
        boss = PersistantManager.Instance;
        //Vuforia.ImageTarget;
        boss.hud.addText("LoadDataSet");

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

        if (objectTracker == null)
        {
            boss.hud.addText("error : TrackerManager.Instance.GetTracker<ObjectTracker>() == null");
            return;
        }
        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>");
                boss.hud.addText("Failed to Activate DataSet: " + dataSetName);
            }

            if (!objectTracker.Start())
            {
                //Debug.Log("<color=yellow>Tracker Failed to Start.</color>");
                boss.hud.addText("Tracker Failed to Start. " + dataSetName);
            }

            int counter = 0;

            foreach (Trackable trackObj in dataSet.GetTrackables())
            {
                Debug.Log("dataSet [" + dataSetName + "]:" + trackObj.Name);
                //boss.hud.addText(trackObj.Name);
            }
            foreach (SSRP_contextResponse cr in contextElement_currentList)
            {
                Debug.Log("cr:" + cr.marker_name);
            }

            IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
            foreach (TrackableBehaviour tb in tbs)
            {
                SSRP_contextResponse hit_response = null;
                if (contextElement_currentList != null)
                {
                    foreach (SSRP_contextResponse cr in contextElement_currentList)
                    {
                        if (tb.TrackableName == cr.marker_name)
                        {
                            hit_response = cr;
                        }
                    }
                }

                if (hit_response != null && tb.name == "New Game Object")
                {
                    //importData
                    //SSRP_ContextElement el =
                    // 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 aug_anchor = (GameObject)GameObject.Instantiate(augmentationAnchor);
                        aug_anchor.transform.SetParent(tb.gameObject.transform);
                        aug_anchor.transform.localPosition = Vector3.zero;
                        aug_anchor.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
                        aug_anchor.transform.localScale    = new Vector3(0.275f, 0.275f, 0.275f);

                        // instantiate augmentation object and parent to trackable
                        GameObject aug_obj = (GameObject)GameObject.Instantiate(augmentationObject);
                        aug_obj.transform.SetParent(aug_anchor.transform);

                        aug_obj.transform.localPosition = new Vector3(0f, 1.75f, 0f);
                        aug_obj.transform.localRotation = Quaternion.identity;
                        aug_obj.transform.localScale    = new Vector3(0.01f, 0.01f, 0.01f);

                        SSRP_context_element_controller aug_obj_script = aug_obj.GetComponent <SSRP_context_element_controller>();
                        if (aug_obj_script != null)
                        {
                            aug_obj_script.importData(hit_response);
                        }
                        // */
                        aug_obj.gameObject.SetActive(true);
                    }
                    else
                    {
                        //Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>");
                        boss.hud.addText("No augmentation object specified for: " + tb.TrackableName);
                    }
                }
            }
        }
        else
        {
            //Debug.LogError("<color=yellow>Failed to load dataset: '" + dataSetName + "'</color>");
            boss.hud.addText("Failed to load dataset: '" + dataSetName + "'");
        }
    }
Пример #25
0
    // Deactivates the given dataset.
    // This can only be done when the tracker is not running.
    public override bool DeactivateDataSet(DataSet dataSet)
    {
        if (dataSet == null)
        {
            Debug.LogError("Dataset is null.");
            return false;
        }

        DataSetImpl dataSetImpl = (DataSetImpl)dataSet;
        if (QCARWrapper.Instance.ImageTrackerDeactivateDataSet(dataSetImpl.DataSetPtr) == 0)
        {
            Debug.LogError("Could not deactivate dataset.");
            return false;
        }

        StateManagerImpl stateManager = (StateManagerImpl)TrackerManager.Instance.GetStateManager();

        // Deactivate all Trackables.
        foreach (Trackable trackable in dataSet.GetTrackables())
            stateManager.EnableTrackableBehavioursForTrackable(trackable, false);

        mActiveDataSets.Remove(dataSetImpl);
        return true;
    }
Пример #26
0
    /// <summary>
    /// Takes a new trackable source and adds it to the dataset
    /// This gets called automatically as soon as you 'BuildNewTarget with UserDefinedTargetBuildingBehaviour
    /// </summary>
    public void OnNewTrackableSource(TrackableSource trackableSource)
    {
        m_TargetCounter++;

        // Deactivates the dataset first
        m_ObjectTracker.DeactivateDataSet(m_UDT_DataSet);

        // Destroy the oldest target if the dataset is full or the dataset
        // already contains five user-defined targets.
        if (m_UDT_DataSet.HasReachedTrackableLimit() || m_UDT_DataSet.GetTrackables().Count() >= MAX_TARGETS)
        {
            IEnumerable <Trackable> trackables = m_UDT_DataSet.GetTrackables();
            Trackable oldest = null;
            foreach (Trackable trackable in trackables)
            {
                if (oldest == null || trackable.ID < oldest.ID)
                {
                    oldest = trackable;
                }
            }

            if (oldest != null)
            {
                Debug.Log("Destroying oldest trackable in UDT dataset: " + oldest.Name);
                m_UDT_DataSet.Destroy(oldest, true);
            }
        }

        // Get predefined trackable and instantiate it
        ImageTargetBehaviour imageTargetCopy;

        switch (m_ChooseSound.GetCurrentSound())
        {
        /// ドラム
        case "Bass":
            imageTargetCopy = Instantiate(BassTarget);
            imageTargetCopy.gameObject.name = "Bass" + m_TargetCounter;
            break;

        case "Cymbal":
            imageTargetCopy = Instantiate(CymbalTarget);
            imageTargetCopy.gameObject.name = "Cymbal" + m_TargetCounter;

            break;

        case "Hat":
            imageTargetCopy = Instantiate(HatTarget);
            imageTargetCopy.gameObject.name = "Hat" + m_TargetCounter;
            break;

        case "Snare":
            imageTargetCopy = Instantiate(SnareTarget);
            imageTargetCopy.gameObject.name = "Snare" + m_TargetCounter;
            break;

        /// ピアノ
        case "Do":
            imageTargetCopy = Instantiate(Do);
            imageTargetCopy.gameObject.name = "Do" + m_TargetCounter;
            break;

        case "Re":
            imageTargetCopy = Instantiate(Re);
            imageTargetCopy.gameObject.name = "Re" + m_TargetCounter;
            break;

        case "Mi":
            imageTargetCopy = Instantiate(Mi);
            imageTargetCopy.gameObject.name = "Mi" + m_TargetCounter;
            break;

        case "Fa":
            imageTargetCopy = Instantiate(Fa);
            imageTargetCopy.gameObject.name = "Fa" + m_TargetCounter;
            break;

        case "So":
            imageTargetCopy = Instantiate(So);
            imageTargetCopy.gameObject.name = "So" + m_TargetCounter;
            break;

        case "Ra":
            imageTargetCopy = Instantiate(Ra);
            imageTargetCopy.gameObject.name = "Ra" + m_TargetCounter;
            break;

        case "Si":
            imageTargetCopy = Instantiate(Si);
            imageTargetCopy.gameObject.name = "Si" + m_TargetCounter;
            break;

        case "Do2":
            imageTargetCopy = Instantiate(Do2);
            imageTargetCopy.gameObject.name = "Do2" + m_TargetCounter;
            break;

        default:
            imageTargetCopy = Instantiate(Empty);
            break;
        }



        // Add the duplicated trackable to the data set and activate it
        m_UDT_DataSet.CreateTrackable(trackableSource, imageTargetCopy.gameObject);

        // Activate the dataset again
        m_ObjectTracker.ActivateDataSet(m_UDT_DataSet);

        // Make sure TargetBuildingBehaviour keeps scanning...
        m_TargetBuildingBehaviour.StartScanning();
    }