コード例 #1
0
    /// <summary>
    /// Takes a given GameObject to add a new ImageTargetBehaviour to. This new Behaviour is associated with the given ImageTarget
    /// </summary>
    public ImageTargetBehaviour FindOrCreateImageTargetBehaviourForTrackable(ImageTarget trackable, GameObject gameObject, DataSet dataSet)
    {
        DataSetTrackableBehaviour trackableBehaviour = gameObject.GetComponent <DataSetTrackableBehaviour>();

        // add an ImageTargetBehaviour if none is attached yet
        if (trackableBehaviour == null)
        {
            trackableBehaviour = gameObject.AddComponent <ImageTargetBehaviour>();
            ((IEditorTrackableBehaviour)trackableBehaviour).SetInitializedInEditor(true);
        }

        // configure the new ImageTargetBehaviour instance:
        if (!(trackableBehaviour is ImageTargetBehaviour))
        {
            Debug.LogError(
                string.Format("DataSet.CreateTrackable: Trackable of type ImageTarget was created, but behaviour of type {0} was provided!",
                              trackableBehaviour.GetType()));
            return(null);
        }

        IEditorImageTargetBehaviour editorImgTargetBehaviour = (ImageTargetBehaviour)trackableBehaviour;

        if (dataSet != null)
        {
            editorImgTargetBehaviour.SetDataSetPath(dataSet.Path);
        }
        editorImgTargetBehaviour.SetImageTargetType(trackable.ImageTargetType);
        editorImgTargetBehaviour.SetNameForTrackable(trackable.Name);
        editorImgTargetBehaviour.InitializeImageTarget(trackable);

        mTrackableBehaviours[trackable.ID] = trackableBehaviour;

        return(trackableBehaviour as ImageTargetBehaviour);
    }
コード例 #2
0
    internal ImageTargetAbstractBehaviour FindOrCreateImageTargetBehaviourForTrackable(ImageTarget trackable, GameObject gameObject, DataSet dataSet)
    {
        DataSetTrackableBehaviour component = gameObject.GetComponent <DataSetTrackableBehaviour>();

        if (component == null)
        {
            component = BehaviourComponentFactory.Instance.AddImageTargetBehaviour(gameObject);
            ((IEditorTrackableBehaviour)component).SetInitializedInEditor(true);
        }
        if (!(component is ImageTargetAbstractBehaviour))
        {
            Debug.LogError(string.Format("DataSet.CreateTrackable: Trackable of type ImageTarget was created, but behaviour of type {0} was provided!", component.GetType()));
            return(null);
        }
        IEditorImageTargetBehaviour behaviour2 = (ImageTargetAbstractBehaviour)component;

        if (dataSet != null)
        {
            behaviour2.SetDataSetPath(dataSet.Path);
        }
        behaviour2.SetImageTargetType(trackable.ImageTargetType);
        behaviour2.SetNameForTrackable(trackable.Name);
        behaviour2.InitializeImageTarget(trackable);
        this.mTrackableBehaviours[trackable.ID] = component;
        return(component as ImageTargetAbstractBehaviour);
    }
コード例 #3
0
    private ImageTargetAbstractBehaviour CreateImageTargetBehaviour(ImageTarget imageTarget)
    {
        GameObject gameObject = new GameObject();
        ImageTargetAbstractBehaviour behaviour  = BehaviourComponentFactory.Instance.AddImageTargetBehaviour(gameObject);
        IEditorImageTargetBehaviour  behaviour2 = behaviour;

        Debug.Log(string.Concat(new object[] { "Creating Image Target with values: \n ID:           ", imageTarget.ID, "\n Name:         ", imageTarget.Name, "\n Path:         ", behaviour2.DataSetPath, "\n Size:         ", imageTarget.GetSize().x, "x", imageTarget.GetSize().y }));
        behaviour2.SetNameForTrackable(imageTarget.Name);
        behaviour2.SetDataSetPath(behaviour2.DataSetPath);
        Vector2 size = imageTarget.GetSize();
        float   x    = Mathf.Max(size.x, size.y);

        behaviour2.transform.localScale = new Vector3(x, x, x);
        behaviour2.CorrectScale();
        behaviour2.SetAspectRatio(size.y / size.x);
        behaviour2.InitializeImageTarget(imageTarget);
        return(behaviour);
    }
コード例 #4
0
    private ImageTargetBehaviour CreateImageTargetBehaviour(ImageTarget imageTarget)
    {
        GameObject           imageTargetObject = new GameObject();
        ImageTargetBehaviour newITB            =
            imageTargetObject.AddComponent <ImageTargetBehaviour>();

        IEditorImageTargetBehaviour newEditorITB = newITB;

        Debug.Log("Creating Image Target with values: " +
                  "\n ID:           " + imageTarget.ID +
                  "\n Name:         " + imageTarget.Name +
                  "\n Path:         " + newEditorITB.DataSetPath +
                  "\n Size:         " + imageTarget.GetSize().x + "x" + imageTarget.GetSize().y);

        // Set Image Target attributes.
        newEditorITB.SetNameForTrackable(imageTarget.Name);
        newEditorITB.SetDataSetPath(newEditorITB.DataSetPath);
        newEditorITB.transform.localScale = new Vector3(imageTarget.GetSize().x, 1.0f, imageTarget.GetSize().y);
        newEditorITB.CorrectScale();
        newEditorITB.SetAspectRatio(imageTarget.GetSize()[1] / imageTarget.GetSize()[0]);
        newEditorITB.InitializeImageTarget(imageTarget);

        return(newITB);
    }
コード例 #5
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);
    }
コード例 #6
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);
    }
コード例 #7
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);
 }