/// <summary>
    /// Finds all MarkerBehaviours in the scene and associates them with existing Markers
    /// If a Marker does not exist yet, it is created in native.
    /// </summary>
    public void AssociateMarkerBehaviours()
    {
        MarkerTrackerImpl markerTracker = (MarkerTrackerImpl)TrackerManager.Instance.GetTracker(Tracker.Type.MARKER_TRACKER);

        if (markerTracker != null)
        {
            // go over all MarkerBehaviours in scene:
            MarkerBehaviour[] markerBehaviours = (MarkerBehaviour[])Object.FindObjectsOfType(typeof(MarkerBehaviour));

            foreach (MarkerBehaviour markerBehaviour in markerBehaviours)
            {
                // this trackable has been removed
                if (mBehavioursMarkedForDeletion.Contains(markerBehaviour))
                {
                    mTrackableBehaviours.Remove(markerBehaviour.Trackable.ID);
                    mBehavioursMarkedForDeletion.Remove(markerBehaviour);
                    continue;
                }

                // check if the marker has been created in native yet:
                IEditorMarkerBehaviour editorMarkerBehaviour = markerBehaviour;
                Marker marker = markerTracker.GetMarkerByMarkerID(editorMarkerBehaviour.MarkerID);
                if (marker != null)
                {
                    // if the Marker has already been created, initialize the Behaviour:
                    InitializeMarkerBehaviour(markerBehaviour, marker);
                }
                else
                {
                    // otherwise, create it first:
                    marker = markerTracker.InternalCreateMarker(editorMarkerBehaviour.MarkerID,
                                                                editorMarkerBehaviour.TrackableName,
                                                                editorMarkerBehaviour.transform.localScale.x);

                    if (marker == null)
                    {
                        Debug.LogWarning("Disabling MarkerBehaviour named " + editorMarkerBehaviour.TrackableName);
                        markerBehaviour.enabled = false;
                    }
                    else
                    {
                        InitializeMarkerBehaviour(markerBehaviour, marker);
                        markerBehaviour.enabled = true;
                    }
                }
            }
        }
    }
Example #2
0
    internal void AssociateMarkerBehaviours()
    {
        MarkerTrackerImpl tracker = (MarkerTrackerImpl)TrackerManager.Instance.GetTracker <MarkerTracker>();

        if (tracker != null)
        {
            MarkerAbstractBehaviour[] behaviourArray = (MarkerAbstractBehaviour[])UnityEngine.Object.FindObjectsOfType(typeof(MarkerAbstractBehaviour));
            foreach (MarkerAbstractBehaviour behaviour in behaviourArray)
            {
                if (this.mBehavioursMarkedForDeletion.Contains(behaviour))
                {
                    this.mTrackableBehaviours.Remove(behaviour.Trackable.ID);
                    this.mBehavioursMarkedForDeletion.Remove(behaviour);
                }
                else
                {
                    IEditorMarkerBehaviour behaviour2 = behaviour;
                    Marker markerByMarkerID           = tracker.GetMarkerByMarkerID(behaviour2.MarkerID);
                    if (markerByMarkerID != null)
                    {
                        this.InitializeMarkerBehaviour(behaviour, markerByMarkerID);
                    }
                    else
                    {
                        markerByMarkerID = tracker.InternalCreateMarker(behaviour2.MarkerID, behaviour2.TrackableName, behaviour2.transform.localScale.x);
                        if (markerByMarkerID == null)
                        {
                            Debug.LogWarning("Disabling MarkerBehaviour named " + behaviour2.TrackableName);
                            behaviour.enabled = false;
                        }
                        else
                        {
                            this.InitializeMarkerBehaviour(behaviour, markerByMarkerID);
                            behaviour.enabled = true;
                        }
                    }
                }
            }
        }
    }