using System;
using Unity.Collections;
namespace UnityEngine.XR.ARSubsystems
{
///
/// Base class for a reference point subsystem.
///
///
/// A reference point is a pose in the physical environment that is tracked by an XR device.
/// As the device refines its understanding of the environment, reference points will be
/// updated, allowing developers to keep virtual content connected to a real-world position and orientation.
/// This abstract class should be implemented by an XR provider and instantiated using the SubsystemManager
/// to enumerate the available s.
///
[Obsolete("XRReferencePointSubsystem has been deprecated. Use XRAnchorSubsystem instead (UnityUpgradable) -> UnityEngine.XR.ARSubsystems.XRAnchorSubsystem", true)]
public abstract class XRReferencePointSubsystem
: TrackingSubsystem
{
///
/// Constructor. Do not invoke directly; use the SubsystemManager
/// to enumerate the available s
/// and call Create on the desired descriptor.
///
public XRReferencePointSubsystem() => m_Provider = CreateProvider();
///
/// Starts the subsystem.
///
protected sealed override void OnStart() => m_Provider.Start();
///
/// Stops the subsystem.
///
protected sealed override void OnStop() => m_Provider.Stop();
///
/// Destroys the subsystem.
///
protected sealed override void OnDestroyed() => m_Provider.Destroy();
///
/// Get the changes (added, updated, & removed) reference points since the last call
/// to .
///
/// An allocator to use for the NativeArrays in .
/// Changes since the last call to .
public override TrackableChanges GetChanges(Allocator allocator)
{
if (!running)
throw new InvalidOperationException("Can't call \"GetChanges\" without \"Start\"ing the reference-point subsystem!");
var changes = m_Provider.GetChanges(XRReferencePoint.defaultValue, allocator);
#if DEVELOPMENT_BUILD || UNITY_EDITOR
m_ValidationUtility.ValidateAndDisposeIfThrown(changes);
#endif
return changes;
}
///
/// Attempts to create a new reference point with the provide .
///
/// The pose, in session space, of the new reference point.
/// The new reference point. Only valid if this method returns true.
/// true if the new reference point was added, otherwise false.
[Obsolete("XRReferencePointSubsystem.TryAddReferencePoint() has been deprecated. Use XRAnchorSubsystem.TryAddAnchor() instead (UnityUpgradable) -> UnityEngine.XR.ARSubsystems.XRAnchorSubsystem.TryAddAnchor(Pose, XRAnchor)", true)]
public bool TryAddReferencePoint(Pose pose, out XRReferencePoint referencePoint)
{
return m_Provider.TryAddReferencePoint(pose, out referencePoint);
}
///
/// Attempts to create a new reference "attached" to the trackable with id .
/// The behavior of the reference point depends on the type of trackable to which this reference point is attached.
///
/// The id of the trackable to which to attach.
/// The pose, in session space, of the reference point to create.
/// The new reference point. Only valid if this method returns true.
/// true if the new reference point was added, otherwise false.
[Obsolete("XRReferencePointSubsystem.TryAttachReferencePoint() has been deprecated. Use XRAnchorSubsystem.TryAttachAnchor() instead (UnityUpgradable) -> UnityEngine.XR.ARSubsystems.XRAnchorSubsystem.TryAttachAnchor(TrackableId, Pose, XRAnchor)", true)]
public bool TryAttachReferencePoint(TrackableId trackableToAffix, Pose pose, out XRReferencePoint referencePoint)
{
return m_Provider.TryAttachReferencePoint(trackableToAffix, pose, out referencePoint);
}
///
/// Attempts to remove an existing reference point with .
///
/// The id of an existing reference point to remove.
/// true if the reference point was removed, otherwise false.
[Obsolete("XRReferencePointSubsystem.TryRemoveReferencePoint() has been deprecated. Use XRAnchorSubsystem.TryRemoveAnchor() instead (UnityUpgradable) -> UnityEngine.XR.ARSubsystems.XRAnchorSubsystem.TryRemoveAnchor(*)", true)]
public bool TryRemoveReferencePoint(TrackableId referencePointId)
{
return m_Provider.TryRemoveReferencePoint(referencePointId);
}
///
/// An interface to be implemented by providers of this subsystem.
///
protected abstract class Provider
{
///
/// Invoked when Start is called on the subsystem. This method is only called if the subsystem was not previously running.
///
public virtual void Start() { }
///
/// Invoked when Stop is called on the subsystem. This method is only called if the subsystem was previously running.
///
public virtual void Stop() { }
///
/// Called when Destroy is called on the subsystem.
///
public virtual void Destroy() { }
///
/// Invoked to get the changes to reference points (added, updated, & removed) since the last call to .
///
/// The default reference point. This should be used to initialize the returned
/// NativeArrays for backwards compatibility.
/// See .
///
/// An allocator to use for the NativeArrays in .
/// Changes since the last call to .
public abstract TrackableChanges GetChanges(XRReferencePoint defaultReferencePoint, Allocator allocator);
///
/// Should create a new reference point with the provide .
///
/// The pose, in session space, of the new reference point.
/// The new reference point. Must be valid only if this method returns true.
/// Should return true if the new reference point was added, otherwise false.
public virtual bool TryAddReferencePoint(Pose pose, out XRReferencePoint referencePoint)
{
referencePoint = default(XRReferencePoint);
return false;
}
///
/// Should create a new reference "attached" to the trackable with id .
/// The behavior of the reference point depends on the type of trackable to which this reference point is attached and
/// may be implemenation-defined.
///
/// The id of the trackable to which to attach.
/// The pose, in session space, of the reference point to create.
/// The new reference point. Must be valid only if this method returns true.
/// true if the new reference point was added, otherwise false.
public virtual bool TryAttachReferencePoint(
TrackableId trackableToAffix,
Pose pose,
out XRReferencePoint referencePoint)
{
referencePoint = default(XRReferencePoint);
return false;
}
///
/// Should remove an existing reference point with .
///
/// The id of an existing reference point to remove.
/// Should return true if the reference point was removed, otherwise false. If the reference
/// point does not exist, return false.
public virtual bool TryRemoveReferencePoint(TrackableId referencePointId) => false;
}
///
/// Should return an instance of .
///
/// The interface to the implementation-specific provider.
protected abstract Provider CreateProvider();
Provider m_Provider;
#if DEVELOPMENT_BUILD || UNITY_EDITOR
ValidationUtility m_ValidationUtility =
new ValidationUtility();
#endif
}
}