Class ColocationDiscoveryFeature
Use this OpenXR feature to enable colocation discovery on Meta Quest devices.
Inheritance
Inherited Members
Namespace: UnityEngine.XR.OpenXR.Features.Meta
Assembly: Unity.XR.MetaOpenXR.dll
Syntax
[OpenXRFeature(UiName = "Meta Quest: Colocation Discovery", BuildTargetGroups = new BuildTargetGroup[] { BuildTargetGroup.Android, BuildTargetGroup.Standalone }, Company = "Unity Technologies", Desc = "Enables you to advertise messages and discover colocated OpenXR Meta devices", DocumentationLink = "https://docs.unity3d.com/Packages/com.unity.xr.meta-openxr@2.2/manual/features/colocation-discovery.html", OpenxrExtensionStrings = "XR_META_colocation_discovery", Category = "Feature", FeatureId = "com.unity.openxr.feature.meta-colocation-discovery", Version = "1.0.0")]
public class ColocationDiscoveryFeature : MetaOpenXRFeature
Fields
featureId
The feature id string. This is used to give the feature a well known id for reference.
Declaration
public const string featureId = "com.unity.openxr.feature.meta-colocation-discovery"
Field Value
Type | Description |
---|---|
string |
Properties
advertisementId
The ID of the active Colocation Advertisement.
Declaration
public SerializableGuid advertisementId { get; }
Property Value
Type | Description |
---|---|
SerializableGuid |
advertisementState
The current Colocation Advertisement ColocationState.
Declaration
public ColocationState advertisementState { get; }
Property Value
Type | Description |
---|---|
ColocationState |
discoveryState
The current Colocation Discovery ColocationState.
Declaration
public ColocationState discoveryState { get; }
Property Value
Type | Description |
---|---|
ColocationState |
Methods
OnInstanceCreate(ulong)
Called after xrCreateInstance
. Override this method to validate that any necessary OpenXR extensions were
successfully enabled
(OpenXRRuntime.IsExtensionEnabled)
and that any required system properties are supported. If this method returns false,
the feature's enabled property is set to false.
Declaration
protected override bool OnInstanceCreate(ulong xrInstance)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrInstance | Handle of the native |
Returns
Type | Description |
---|---|
bool | true if this feature successfully initialized. Otherwise, false. |
Overrides
Remarks
If this feature is a required feature of an enabled feature set, returning false here
causes the OpenXRLoader
to fail, and XR Plug-in Management will fall back to another loader if enabled.
See Also
OnInstanceDestroy(ulong)
Called before xrDestroyInstance. Destroys the Colocation Advertisement and Discovery providers.
Declaration
protected override void OnInstanceDestroy(ulong xrInstance)
Parameters
Type | Name | Description |
---|---|---|
ulong | xrInstance | Handle of the xrInstance |
Overrides
TryStartAdvertisementAsync(Span<byte>)
Attempts to start advertising, or broadcasting, the message
to colocated users of your
app that have Colocation Discovery active. If successful, the advertisementState will
transition to Starting. Subscribe to advertisementStateChanged
to know when advertisement has started and is active or if advertisement fails to start. Colocation Advertisement
can only be started if the current advertisementState is Inactive.
Calling TryStartAdvertisementAsync
will return ValidationFailure
if the current advertisement state is not Inactive
.
Declaration
public Awaitable<Result<SerializableGuid>> TryStartAdvertisementAsync(Span<byte> message)
Parameters
Type | Name | Description |
---|---|---|
Span<byte> | message | The message to advertise. The max buffer size is 1024 bytes. |
Returns
Type | Description |
---|---|
Awaitable<Result<SerializableGuid>> | The result of the request to start advertisement and the advertisement ID. |
TryStartDiscoveryAsync()
Attempts to start discovery of any colocated users of your app that is actively advertising a message. If
successful, the discoveryState will transition to Starting.
Subscribe to discoveryStateChanged to know when discovery has started and is active or if
discovery fails to start. Subscribe to messageDiscovered to know when a message is discovered.
Colocation Discovery can only be started if the current discoveryState is
Inactive. Calling TryStartDiscoveryAsync
will return
ValidationFailure if the current advertisement state is not Inactive
.
Declaration
public Awaitable<XRResultStatus> TryStartDiscoveryAsync()
Returns
Type | Description |
---|---|
Awaitable<XRResultStatus> | The result of the request to start discovery. |
TryStopAdvertisementAsync()
Attempts to stop colocation advertisement. If successful, the advertisementState will transition
to Stopping. Subscribe to advertisementStateChanged to know when
advertisement has stopped and is inactive or if advertisement fails to stop. Colocation Advertisement
can only be stopped if the current advertisementState is Active.
Calling TryStopAdvertisementAsync
will return ValidationFailure
if the current advertisement state is not Inactive
.
Declaration
public Awaitable<XRResultStatus> TryStopAdvertisementAsync()
Returns
Type | Description |
---|---|
Awaitable<XRResultStatus> | The Awaitable of the async operation. You are responsible to await this. |
TryStopDiscoveryAsync()
Attempts to Stops colocation discovery. If successful, the discoveryState will transition to
Stopping. Subscribe to discoveryStateChanged to know when
discovery has stopped and is inactive. Colocation Discovery can only be stopped if the current
discoveryState is Active. Calling TryStartDiscoveryAsync
will
return ValidationFailure if the current advertisement state is not
Inactive
.
Declaration
public Awaitable<XRResultStatus> TryStopDiscoveryAsync()
Returns
Type | Description |
---|---|
Awaitable<XRResultStatus> | The Awaitable of the async operation. You are responsible to await this. |
Events
advertisementStateChanged
Notifies when colocation advertisement state changes.
Declaration
public event EventHandler<Result<ColocationState>> advertisementStateChanged
Event Type
Type | Description |
---|---|
EventHandler<Result<ColocationState>> |
discoveryStateChanged
Notifies when colocation discovery state changes.
Declaration
public event EventHandler<Result<ColocationState>> discoveryStateChanged
Event Type
Type | Description |
---|---|
EventHandler<Result<ColocationState>> |
messageDiscovered
Notifies when a message was discovered while colocation discovery is Active.
The data is allocated with Allocator.Temp
and is automatically
disposed of at the end of the frame.
Declaration
public event EventHandler<ColocationDiscoveryMessage> messageDiscovered
Event Type
Type | Description |
---|---|
EventHandler<ColocationDiscoveryMessage> |