Class Extensions
Helper Unity side extensions to enable the core abstraction to be Unity agnostic.
Inherited Members
Namespace: Microsoft.MixedReality.SpatialAlignment
Assembly: cs.temp.dll.dll
Syntax
public static class Extensions
Methods
AsNumericsQuaternion(UQuaternion)
Converts a UnityEngine.Quaternion to a System.Numerics.Quaternion.
Declaration
public static Quaternion AsNumericsQuaternion(this UQuaternion input)
Parameters
Type | Name | Description |
---|---|---|
UQuaternion | input |
Returns
Type | Description |
---|---|
Quaternion |
AsNumericsVector(UVector3)
Converts a UnityEngine.Vector3. to a System.Numerics.Vector3.
Declaration
public static Vector3 AsNumericsVector(this UVector3 input)
Parameters
Type | Name | Description |
---|---|---|
UVector3 | input |
Returns
Type | Description |
---|---|
Vector3 |
AsTask(CancellationToken)
A simple helper to enable "awaiting" a CancellationToken by creating a task wrapping it.
Declaration
public static Task AsTask(this CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | The CancellationToken to await. |
Returns
Type | Description |
---|---|
Task | The task that can be awaited. |
AsUnityQuaternion(Quaternion)
Converts a System.Numerics.Quaternion to a UnityEngine.Quaternion.
Declaration
public static UQuaternion AsUnityQuaternion(this Quaternion input)
Parameters
Type | Name | Description |
---|---|---|
Quaternion | input |
Returns
Type | Description |
---|---|
UQuaternion |
AsUnityVector(Vector3)
Converts a System.Numerics.Vector3 to a UnityEngine.Vector3.
Declaration
public static UVector3 AsUnityVector(this Vector3 input)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | input |
Returns
Type | Description |
---|---|
UVector3 |
CoordinateToWorldSpace(ISpatialCoordinate, UQuaternion)
Converst coordinate space position to world space position.
Declaration
public static UQuaternion CoordinateToWorldSpace(this ISpatialCoordinate coordinate, UQuaternion quaternion)
Parameters
Type | Name | Description |
---|---|---|
ISpatialCoordinate | coordinate | |
UQuaternion | quaternion |
Returns
Type | Description |
---|---|
UQuaternion |
CoordinateToWorldSpace(ISpatialCoordinate, UVector3)
Converst coordinate space position to world space position.
Declaration
public static UVector3 CoordinateToWorldSpace(this ISpatialCoordinate coordinate, UVector3 vector)
Parameters
Type | Name | Description |
---|---|---|
ISpatialCoordinate | coordinate | |
UVector3 | vector |
Returns
Type | Description |
---|---|
UVector3 |
FireAndForget(Task)
Gracefully allows a task to continue running without loosing any exceptions thrown or requireing to await it.
Declaration
public static void FireAndForget(this Task task)
Parameters
Type | Name | Description |
---|---|---|
Task | task | The task that should be wrapped. |
FireAndForget<T>(Task<T>)
Gracefully allows a task to continue running without loosing any exceptions thrown or requireing to await it.
Declaration
public static void FireAndForget<T>(this Task<T> task)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | The task that should be wrapped. |
Type Parameters
Name | Description |
---|---|
T |
GetAwaiter(SynchronizationContext)
Required extension method to enable awaiting on SynchronizationContext.
Declaration
public static Extensions.SynchronizationContextAwaiter GetAwaiter(this SynchronizationContext context)
Parameters
Type | Name | Description |
---|---|---|
SynchronizationContext | context | Context to await (switch execution flow to). |
Returns
Type | Description |
---|---|
Extensions.SynchronizationContextAwaiter | Awaiter for the "await" keyword to work. |
IgnoreCancellation(Task)
Prevents TaskCanceledException or OperationCanceledException from trickling up.
Declaration
public static Task IgnoreCancellation(this Task task)
Parameters
Type | Name | Description |
---|---|---|
Task | task | The task to ignore exceptions for. |
Returns
Type | Description |
---|---|
Task | A wrapping task for the given task. |
IgnoreCancellation<T>(Task<T>, T)
Prevents TaskCanceledException or OperationCanceledException from trickling up.
Declaration
public static Task<T> IgnoreCancellation<T>(this Task<T> task, T defaultCancellationReturn = null)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | The task to ignore exceptions for. |
T | defaultCancellationReturn | The default value to return in case the task is cancelled. |
Returns
Type | Description |
---|---|
Task<T> | A wrapping task for the given task. |
Type Parameters
Name | Description |
---|---|
T | The result type of the Task. |
TryCreateCoordinateAsync(ISpatialCoordinateService, UVector3, UQuaternion, CancellationToken)
Attempts to create a new coordinate with this service.
Declaration
public static Task<ISpatialCoordinate> TryCreateCoordinateAsync(this ISpatialCoordinateService spatialCoordinateService, UVector3 vector, UQuaternion quaternion, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
ISpatialCoordinateService | spatialCoordinateService | |
UVector3 | vector | |
UQuaternion | quaternion | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<ISpatialCoordinate> | The coordinate if the coordinate was succesfully created, otherwise null. |
Unless(Task, CancellationToken)
The task will be awaited until the cancellation token is triggered. (await task unless cancelled).
Declaration
public static Task Unless(this Task task, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Task | task | The task to await. |
CancellationToken | cancellationToken | The cancellation token to stop awaiting. |
Returns
Type | Description |
---|---|
Task | The task that can be awaited unless the cancellation token is triggered. |
Remarks
This is different from cancelling the task. The use case is to enable a calling method bow out of the await that it can't cancel, but doesn't require completion/cancellation in order to cancel it's own execution.
Unless<T>(Task<T>, CancellationToken)
The task will be awaited until the cancellation token is triggered. (await task unless cancelled).
Declaration
public static Task<T> Unless<T>(this Task<T> task, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Task<T> | task | The task to await. |
CancellationToken | cancellationToken | The cancellation token to stop awaiting. |
Returns
Type | Description |
---|---|
Task<T> | The task that can be awaited unless the cancellation token is triggered. |
Type Parameters
Name | Description |
---|---|
T |
Remarks
This is different from cancelling the task. The use case is to enable a calling method bow out of the await that it can't cancel, but doesn't require completion/cancellation in order to cancel it's own execution.
WorldToCoordinateSpace(ISpatialCoordinate, UQuaternion)
Converst world space rotation to coordinate space rotation.
Declaration
public static UQuaternion WorldToCoordinateSpace(this ISpatialCoordinate coordinate, UQuaternion quaternion)
Parameters
Type | Name | Description |
---|---|---|
ISpatialCoordinate | coordinate | |
UQuaternion | quaternion |
Returns
Type | Description |
---|---|
UQuaternion |
WorldToCoordinateSpace(ISpatialCoordinate, UVector3)
Converst world space position to coordinate space position.
Declaration
public static UVector3 WorldToCoordinateSpace(this ISpatialCoordinate coordinate, UVector3 vector)
Parameters
Type | Name | Description |
---|---|---|
ISpatialCoordinate | coordinate | |
UVector3 | vector |
Returns
Type | Description |
---|---|
UVector3 |