1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
-
- namespace NRKernal
- {
- using System;
- using System.Collections.Generic;
- using UnityEngine;
-
- public class TrackableObserver : MonoBehaviour
- {
-
-
-
- public delegate void TrackingDelegate(Vector3 pos, Quaternion qua);
-
- public event TrackingDelegate FoundEvent;
-
- public event Action LostEvent;
-
- public TrackableType TargetType;
-
- private NRTrackableBehaviour m_TrackableBehaviour;
-
- private List<NRTrackableImage> m_TempTrackingImages = new List<NRTrackableImage>();
-
- private List<NRTrackablePlane> m_TempTrackingPlane = new List<NRTrackablePlane>();
-
- public enum TrackableType
- {
-
- TrackableImage,
-
- TrackablePlane,
- }
-
- void Start()
- {
- m_TrackableBehaviour = GetComponent<NRTrackableBehaviour>();
- }
-
- void Update()
- {
- if (TargetType == TrackableType.TrackableImage)
- {
- NRFrame.GetTrackables<NRTrackableImage>(m_TempTrackingImages, NRTrackableQueryFilter.All);
- foreach (var trackableImage in m_TempTrackingImages)
- {
- if (trackableImage.GetDataBaseIndex() == m_TrackableBehaviour.DatabaseIndex)
- {
- if (trackableImage.GetTrackingState() == TrackingState.Tracking)
- {
- FoundEvent?.Invoke(trackableImage.GetCenterPose().position, trackableImage.GetCenterPose().rotation);
- }
- else
- {
- LostEvent?.Invoke();
- }
- break;
- }
- }
- }
- else if (TargetType == TrackableType.TrackablePlane)
- {
- NRFrame.GetTrackables<NRTrackablePlane>(m_TempTrackingPlane, NRTrackableQueryFilter.All);
- foreach (var trackablePlane in m_TempTrackingPlane)
- {
- if (m_TrackableBehaviour.DatabaseIndex == -1)
- m_TrackableBehaviour.DatabaseIndex = trackablePlane.GetDataBaseIndex();
- if (trackablePlane.GetDataBaseIndex() == m_TrackableBehaviour.DatabaseIndex)
- {
- if (trackablePlane.GetTrackingState() == TrackingState.Tracking)
- {
- FoundEvent?.Invoke(trackablePlane.GetCenterPose().position, trackablePlane.GetCenterPose().rotation);
- }
- else
- {
- LostEvent?.Invoke();
- }
- break;
- }
- }
- }
- }
- }
- }
|