Пример #1
0
    void Update()
    {
        DisableAllTrackables();

        TrackingState state = TrackerManager.GetInstance().UpdateTrackingState();
        TrackedImage  image = state.GetImage();

        cameraBackgroundBehaviour.UpdateCameraBackgroundImage(state);

        TrackingResult trackingResult = state.GetTrackingResult();

        if (trackingResult.GetCount() > 0)
        {
            Trackable trackable = trackingResult.GetTrackable(0);
            if (cloudTrackablesMap.ContainsKey(trackable.GetCloudName()))
            {
                foreach (var cloudTrackable in cloudTrackablesMap[trackable.GetCloudName()])
                {
                    cloudTrackable.OnTrackSuccess(trackable.GetId(), trackable.GetName(), trackable.GetPose());
                }
            }
            else
            {
                if (cloudTrackablesMap.ContainsKey("_MaxstCloud_"))
                {
                    foreach (var cloudTrackable in cloudTrackablesMap["_MaxstCloud_"])
                    {
                        cloudTrackable.OnTrackSuccess(trackable.GetId(), trackable.GetName(), trackable.GetPose());
                    }
                }
            }
        }
    }
Пример #2
0
        /// <summary>
        /// Factory method for creating and reusing TrackedPlane references from native handles.
        /// </summary>
        /// <param name="nativeHandle">A native handle to a plane that has been acquired.  RELEASE WILL BE HANDLED BY
        /// THIS METHOD.</param>
        /// <returns>A reference to a tracked plane. </returns>
        public Trackable TrackableFactory(IntPtr nativeHandle)
        {
            if (nativeHandle == IntPtr.Zero)
            {
                return(null);
            }

            Trackable result;

            ApiTrackableType trackableType = TrackableApi.GetType(nativeHandle);

            if (trackableType == ApiTrackableType.Plane)
            {
                result = new TrackedPlane(nativeHandle, this);
            }
            else if (trackableType == ApiTrackableType.HandGesture)
            {
                result = new TrackedHandGesture(nativeHandle, this);
            }
            else if (trackableType == ApiTrackableType.Image)
            {
                result = new TrackedImage(nativeHandle, this);
            }
            else
            {
                UnityEngine.Debug.LogFormat("Cant find {0}", trackableType);
                throw new NotImplementedException("TrackableFactory:: No contructor for requested trackable type.");
            }

            return(result);
        }
Пример #3
0
    void Start()
    {
        thisTrackedImage = GetComponent <TrackedImage>();
        if (gameObject.name == "TaskStation(Clone)")
        {
            interfaceBits = new bool[2];
        }
        if (gameObject.name == "NumberStation(Clone)")
        {
            interfaceBits = new bool[4];
        }
        if (gameObject.name == "ShapeStation(Clone)")
        {
            interfaceBits = new bool[3];
        }
        if (gameObject.name == "ColorStation(Clone)")
        {
            interfaceBits = new bool[4];
        }
        if (gameObject.name == "OutputStation(Clone)")
        {
            interfaceBits = new bool[4];
        }

        for (int i = 0; i < interfaceBits.Length; i++)
        {
            //might use this in future to make the station UIs interactable
            //interfaceBits[i] = true;
        }
    }
 private void Start()
 {
     thisTrackedImage = transform.parent.GetComponent <TrackedImage>();
     mainTracker      = transform.parent.parent.GetChild(0).GetChild(0).GetComponent <TrackerBase>();
     if (transform.GetChild(1).GetComponent <Text>())
     {
         transform.GetChild(1).GetComponent <Text>().text = "";
     }
     birthTime = Time.time;
 }
 private void RemoveExistingContent()
 {
     foreach (var image in m_TempAugmentedImages)
     {
         currentlyTracked = null;
         m_TrackedImages.TryGetValue(image.DatabaseIndex, out currentlyTracked);
         if (currentlyTracked != null)
         {
             m_TrackedImages.Remove(image.DatabaseIndex);
             currentlyTracked.Remove();
         }
     }
 }
    public void SetARTrackedImageActive(ARTrackedImage arTrackedImage, bool set)
    {
        string key = arTrackedImage.referenceImage.name;

        if (trackedImageDictionary.ContainsKey(key))
        {
            TrackedImage trackedImage = trackedImageDictionary[key];

            if (set)
            {
                trackedImage.AddImage();
            }
            else
            {
                trackedImage.RemoveImage();
            }

            trackedImage.gameObject.SetActive(set);
        }
    }
 public void SetCurrentImage(TrackedImage trackedImage)
 {
     currentImage = trackedImage;
 }
Пример #8
0
 private void Start()
 {
     thisTrackedImage = transform.parent.GetComponent <TrackedImage>();
     mainTracker      = GetComponent <TrackerBase>();
 }
    public void Update()
    {
        //rotate objects with finger swipe feature
        if (Input.GetMouseButton(0))
        {
            //printToScreen.text = Input.GetTouch(0).deltaPosition.x.ToString();

            //make this check is its actively tracked first
            for (int i = 0; i < transform.childCount; i++)
            {
                //its a model, not a UI, so go rotate it
                if (transform.GetChild(i).GetChild(0).gameObject.tag == "3DModel")
                {
                    transform.GetChild(i).rotation = Quaternion.Euler(0f, transform.GetChild(i).rotation.eulerAngles.y + (Input.GetTouch(0).deltaPosition.x / 2f), 0f);
                }
            }
        }

        // Exit the app when the 'back' button is pressed.
        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }

        if (Session.Status != SessionStatus.Tracking)
        {
            Screen.sleepTimeout = SleepTimeout.SystemSetting;
        }
        else
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;
        }

        // Get updated augmented images for this frame.
        Session.GetTrackables <AugmentedImage>(m_TempAugmentedImages, TrackableQueryFilter.All);

        if (removeExistingContent)
        {
            foreach (var image in m_TempAugmentedImages)
            {
                currentlyTracked = null;
                m_TrackedImages.TryGetValue(image.DatabaseIndex, out currentlyTracked);
                if (currentlyTracked != null)
                {
                    //testing if we should remove 3D models at this point and if its a 3D model
                    if (currentlyTracked.transform.GetChild(0).gameObject.tag == "3DModel")
                    {
                        if (remove3DContent)
                        {
                            m_TrackedImages.Remove(image.DatabaseIndex);
                            currentlyTracked.Remove();
                        }
                    }
                    else
                    { //its a UI element and remove it
                        m_TrackedImages.Remove(image.DatabaseIndex);
                        currentlyTracked.Remove();
                    }
                }
            }
            removeExistingContent = false;
            remove3DContent       = false;
        }
        else if (shouldControllerBeTracking)
        {
            if (Input.GetKeyDown(KeyCode.Alpha0))
            {
                shouldImageBeTracked = gameManager.InputDetected(0);
                if (shouldImageBeTracked)
                {
                    currentlyTracked = (TrackedImage)Instantiate(
                        TrackedImagePrefab, this.transform);
                    currentlyTracked.transform.parent = this.transform;
                    m_TrackedImages.Add(0, currentlyTracked);
                    shouldImageBeTracked = false;
                }
            }

            if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                shouldImageBeTracked = gameManager.InputDetected(7);
                if (shouldImageBeTracked)
                {
                    currentlyTracked = (TrackedImage)Instantiate(
                        TrackedImagePrefab, this.transform);
                    currentlyTracked.transform.parent = this.transform;
                    m_TrackedImages.Add(7, currentlyTracked);
                    shouldImageBeTracked = false;
                }
            }

            // Create an anchor and a model for updated augmented images that are tracking and do
            // not previously have a model. Remove models for stopped images.
            foreach (var image in m_TempAugmentedImages)
            {
                currentlyTracked = null;
                m_TrackedImages.TryGetValue(image.DatabaseIndex, out currentlyTracked);
                if (image.TrackingMethod == AugmentedImageTrackingMethod.FullTracking && currentlyTracked == null) //image.TrackingState == TrackingState.Tracking &&
                {
                    //need to switch this to know the databaseElement right away if thats the one that should be spawned
                    shouldImageBeTracked = gameManager.InputDetected(image.DatabaseIndex);
                    if (shouldImageBeTracked)
                    {
                        // Create an anchor to ensure that ARCore keeps tracking this augmented image.
                        Anchor anchor = image.CreateAnchor(image.CenterPose);
                        currentlyTracked = (TrackedImage)Instantiate(
                            TrackedImagePrefab, anchor.transform);
                        currentlyTracked.image  = image;
                        currentlyTracked.anchor = anchor;
                        //currentlyTracked.transform.rotation = Quaternion.identity;
                        currentlyTracked.transform.parent = this.transform;
                        m_TrackedImages.Add(image.DatabaseIndex, currentlyTracked);
                        shouldImageBeTracked = false;
                    }
                }
                else if (image.TrackingState == TrackingState.Stopped && currentlyTracked != null)
                {
                    m_TrackedImages.Remove(image.DatabaseIndex);
                    GameObject.Destroy(currentlyTracked.gameObject);
                }
            }
        }
    }