private CylinderTargetBehaviour CreateCylinderTargetBehaviour(CylinderTarget cylinderTarget)
    {
        GameObject cylinderTargetObject = new GameObject();
        CylinderTargetBehaviour newCTB  =
            cylinderTargetObject.AddComponent <CylinderTargetBehaviour>();

        IEditorCylinderTargetBehaviour newEditorCTB = newCTB;

        Debug.Log("Creating Cylinder Target with values: " +
                  "\n ID:           " + cylinderTarget.ID +
                  "\n Name:         " + cylinderTarget.Name +
                  "\n Path:         " + newEditorCTB.DataSetPath +
                  "\n Side Length:  " + cylinderTarget.GetSideLength() +
                  "\n Top Diameter: " + cylinderTarget.GetTopDiameter() +
                  "\n Bottom Diam.: " + cylinderTarget.GetBottomDiameter());


        // Set Cylinder Target attributes.
        newEditorCTB.SetNameForTrackable(cylinderTarget.Name);
        newEditorCTB.SetDataSetPath(newEditorCTB.DataSetPath);
        var sidelength = cylinderTarget.GetSideLength();

        newEditorCTB.transform.localScale = new Vector3(sidelength, sidelength, sidelength);
        newEditorCTB.CorrectScale();
        newEditorCTB.SetAspectRatio(cylinderTarget.GetTopDiameter() / sidelength,
                                    cylinderTarget.GetBottomDiameter() / sidelength);
        newEditorCTB.InitializeCylinderTarget(cylinderTarget);
        return(newCTB);
    }
Example #2
0
    private CylinderTargetAbstractBehaviour CreateCylinderTargetBehaviour(CylinderTarget cylinderTarget)
    {
        GameObject gameObject = new GameObject();
        CylinderTargetAbstractBehaviour behaviour  = BehaviourComponentFactory.Instance.AddCylinderTargetBehaviour(gameObject);
        IEditorCylinderTargetBehaviour  behaviour2 = behaviour;

        Debug.Log(string.Concat(new object[] { "Creating Cylinder Target with values: \n ID:           ", cylinderTarget.ID, "\n Name:         ", cylinderTarget.Name, "\n Path:         ", behaviour2.DataSetPath, "\n Side Length:  ", cylinderTarget.GetSideLength(), "\n Top Diameter: ", cylinderTarget.GetTopDiameter(), "\n Bottom Diam.: ", cylinderTarget.GetBottomDiameter() }));
        behaviour2.SetNameForTrackable(cylinderTarget.Name);
        behaviour2.SetDataSetPath(behaviour2.DataSetPath);
        float sideLength = cylinderTarget.GetSideLength();

        behaviour2.transform.localScale = new Vector3(sideLength, sideLength, sideLength);
        behaviour2.CorrectScale();
        behaviour2.SetAspectRatio(cylinderTarget.GetTopDiameter() / sideLength, cylinderTarget.GetBottomDiameter() / sideLength);
        behaviour2.InitializeCylinderTarget(cylinderTarget);
        return(behaviour);
    }
    /// <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);
    }
Example #4
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);
 }