/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ using System.Collections.Generic; using UnityEngine; namespace NRKernal.NRExamples { /// A marker detecter. public class MarkerDetecter : MonoBehaviour { /// A prefab for tracking and visualizing detected markers. public GameObject DetectedMarkerPrefab; /// /// A list to hold new planes NRSDK began tracking in the current frame. This object is used /// across the application to avoid per-frame allocations. private List m_NewMarkers = new List(); /// Updates this object. public void Update() { NRFrame.GetTrackables(m_NewMarkers, NRTrackableQueryFilter.New); for (int i = 0; i < m_NewMarkers.Count; i++) { NRDebugger.Info("[MarkerDetecter] Get New TrackableImages!! " + m_NewMarkers[i].TrackableNativeHandle); // Instantiate a visualization marker. NRAnchor anchor = m_NewMarkers[i].CreateAnchor(); GameObject markerObject = Instantiate(DetectedMarkerPrefab, Vector3.zero, Quaternion.identity, anchor.transform); markerObject.GetComponent().Initialize(m_NewMarkers[i]); } } /// Switch image tracking mode. /// True to on. public void SwitchImageTrackingMode(bool on) { var config = NRSessionManager.Instance.NRSessionBehaviour.SessionConfig; config.ImageTrackingMode = on ? TrackableImageFindingMode.ENABLE : TrackableImageFindingMode.DISABLE; NRSessionManager.Instance.SetConfiguration(config); } } }