// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using System; using Unity.Collections; using UnityEngine.SubsystemsImplementation; using UnityEngine.XR.ARSubsystems; namespace Microsoft.MixedReality.OpenXR.ARSubsystems { /// /// Base class for marker subsystems. /// /// /// This subsystem surfaces information regarding the detection of markers such as QRCodes in the physical environment. /// public class XRMarkerSubsystem : TrackingSubsystem { public XRMarkerSubsystem() { } /// /// Get or set the list of marker types that will be detected. /// internal ARMarkerType[] EnabledMarkerTypes { get => provider.EnabledMarkerTypes; set => provider.EnabledMarkerTypes = value; } /// /// Default for newly detected markers. /// public TransformMode DefaultTransformMode { get => provider.DefaultTransformMode; set => provider.DefaultTransformMode = value; } /// /// Get the changes to markers (added, updated, and removed) since the last call to . /// /// An Allocator to use when allocating the returned NativeArrays. /// /// that describes the markers that have been added, updated, and removed /// since the last call to . The caller owns the memory allocated with Allocator. /// public override TrackableChanges GetChanges(Allocator allocator) { var changes = provider.GetChanges(XRMarker.defaultValue, allocator); #if DEVELOPMENT_BUILD || UNITY_EDITOR m_ValidationUtility.ValidateAndDisposeIfThrown(changes); #endif return changes; } /// /// Set transform mode of an existing . /// /// The of the marker to be transformed. /// The to be applied. public void SetTransformMode(TrackableId trackableId, TransformMode transformMode) { provider.SetTransformMode(trackableId, transformMode); } /// /// Get raw data for an existing . /// /// The of the marker. public NativeArray GetRawData(TrackableId trackableId, Allocator allocator) { return provider.GetRawData(trackableId, allocator); } /// /// Get decoded string for an existing . /// /// The of the marker to be transformed. public string GetDecodedString(TrackableId trackableId) { return provider.GetDecodedString(trackableId); } /// /// Get QR code properties for an existing of type . /// /// The of the QRCode marker. public QRCodeProperties GetQRCodeProperties(TrackableId trackableId) { return provider.GetQRCodeProperties(trackableId); } /// /// The API that derived classes must implement. /// public abstract class Provider : SubsystemProvider { /// /// Get the changes to markers (added, updated, and removed) since the last call to /// . /// /// /// The default marker. This should be used to initialize the returned NativeArrays for backwards compatibility. /// See . /// /// An Allocator to use when allocating the returned NativeArrays. /// /// describing the markers that have been added, updated, and removed /// since the last call to . The changes should be allocated using /// . /// public abstract TrackableChanges GetChanges(XRMarker defaultMarker, Allocator allocator); /// /// Set transform mode of an existing . /// /// The of the marker to be transformed. /// The to be applied. public abstract void SetTransformMode(TrackableId trackableId, TransformMode transformMode); /// /// Get raw data for an existing . /// /// The of the marker. public abstract NativeArray GetRawData(TrackableId trackableId, Allocator allocator); /// /// Get decoded string for an existing . /// /// The of the marker. public abstract string GetDecodedString(TrackableId trackableId); /// /// Get QR code properties for an existing of type . /// /// The of the QRCode marker. public abstract QRCodeProperties GetQRCodeProperties(TrackableId trackableId); /// /// Get or set the list of marker types that will be detected. /// internal abstract ARMarkerType[] EnabledMarkerTypes { get; set; } /// /// Default for newly detected markers. /// internal abstract TransformMode DefaultTransformMode { get; set; } } #if DEVELOPMENT_BUILD || UNITY_EDITOR private ValidationUtility m_ValidationUtility = new ValidationUtility(); #endif } }