Class XROrigin
The XR Origin component is typically attached to the base object of the XR Origin, and stores the GameObject that will be manipulated via locomotion. It is also used for offsetting the camera.
Inherited Members
Namespace: Unity.XR.CoreUtils
Syntax
[AddComponentMenu("XR/XR Origin")]
[DisallowMultipleComponent]
[HelpURL("https://docs.unity.cn/Packages/com.unity.xr.core-utils@2.0/api/Unity.XR.CoreUtils.XROrigin.html")]
public class XROrigin : MonoBehaviour
Properties
Camera
The Camera to associate with the XR device. It must be a child of this XROrigin.
Declaration
public Camera Camera { get; set; }
Property Value
| Type | Description |
|---|---|
| Camera |
Remarks
The Camera should update its position and rotation according to the XR device.
This is typically accomplished by adding a TrackedPoseDriver component to the
Camera.
CameraFloorOffsetObject
The GameObject to move to desired height off the floor (defaults to this object if none provided). This is used to transform the XR device from camera space to XR Origin space.
Declaration
public GameObject CameraFloorOffsetObject { get; set; }
Property Value
| Type | Description |
|---|---|
| GameObject |
CameraInOriginSpaceHeight
(Read Only) The camera's height relative to the origin.
Declaration
public float CameraInOriginSpaceHeight { get; }
Property Value
| Type | Description |
|---|---|
| Single |
CameraInOriginSpacePos
(Read Only) The camera's local position in origin space.
Declaration
public Vector3 CameraInOriginSpacePos { get; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
CameraYOffset
Camera height to be used when in Device Tracking Origin Mode to define the height of the user from the floor.
This is the amount that the camera is offset from the floor when moving the CameraFloorOffsetObject.
Declaration
public float CameraYOffset { get; set; }
Property Value
| Type | Description |
|---|---|
| Single |
CurrentTrackingOriginMode
(Read Only) The Tracking Origin Mode of this XR Origin.
Declaration
public TrackingOriginModeFlags CurrentTrackingOriginMode { get; }
Property Value
| Type | Description |
|---|---|
| TrackingOriginModeFlags |
See Also
Origin
The "Origin" GameObject is used to refer to the base of the XR Origin, by default it is this GameObject. This is the GameObject that will be manipulated via locomotion.
Declaration
public GameObject Origin { get; set; }
Property Value
| Type | Description |
|---|---|
| GameObject |
OriginInCameraSpacePos
(Read Only) The origin's local position in camera space.
Declaration
public Vector3 OriginInCameraSpacePos { get; }
Property Value
| Type | Description |
|---|---|
| Vector3 |
RequestedTrackingOriginMode
The type of tracking origin to use for this XROrigin. Tracking origins identify where (0, 0, 0) is in the world of tracking. Not all devices support all tracking origin modes.
Declaration
public XROrigin.TrackingOriginMode RequestedTrackingOriginMode { get; set; }
Property Value
| Type | Description |
|---|---|
| XROrigin.TrackingOriginMode |
See Also
TrackablesParent
The parent Transform for all "trackables" (for example, planes and feature points).
Declaration
public Transform TrackablesParent { get; }
Property Value
| Type | Description |
|---|---|
| Transform |
Methods
Awake()
See MonoBehaviour.
Declaration
protected void Awake()
MatchOriginUp(Vector3)
This function will rotate the XR Origin object such that the XR Origin's up vector will match the provided vector.
Declaration
public bool MatchOriginUp(Vector3 destinationUp)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | destinationUp | the vector to which the XR Origin object's up vector will be matched. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the rotation is performed or the vectors have already been matched. Otherwise, returns false. |
MatchOriginUpCameraForward(Vector3, Vector3)
This function will rotate the XR Origin object around the camera object using the destinationUp vector such that:
- The camera will look at the area in the direction of the
destinationForward - The projection of camera's forward vector on the plane with the normal
destinationUpwill be in the direction ofdestinationForward - The up vector of the XR Origin object will match the provided
destinationUpvector (note that the camera's Up vector can not be manipulated)
Declaration
public bool MatchOriginUpCameraForward(Vector3 destinationUp, Vector3 destinationForward)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | destinationUp | The up vector that the origin's up vector will be matched to. |
| Vector3 | destinationForward | The forward vector that will be matched to the projection of the camera's forward vector on the plane with the normal |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the rotation is performed. Otherwise, returns false. |
MatchOriginUpOriginForward(Vector3, Vector3)
This function will rotate the XR Origin object around the camera object using the destinationUp vector such that:
- The forward vector of the XR Origin object, which is the direction the player moves in Unity when walking forward in the physical world, will match the provided
destinationUpvector - The up vector of the XR Origin object will match the provided
destinationUpvector
Declaration
public bool MatchOriginUpOriginForward(Vector3 destinationUp, Vector3 destinationForward)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | destinationUp | The up vector that the origin's up vector will be matched to. |
| Vector3 | destinationForward | The forward vector that will be matched to the forward vector of the XR Origin object, which is the direction the player moves in Unity when walking forward in the physical world. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the rotation is performed. Otherwise, returns false. |
MoveCameraToWorldLocation(Vector3)
This function moves the camera to the world location provided by desiredWorldLocation.
It does this by moving the XR Origin object so that the camera's world location matches the desiredWorldLocation
Declaration
public bool MoveCameraToWorldLocation(Vector3 desiredWorldLocation)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | desiredWorldLocation | the position in world space that the camera should be moved to |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the move is performed. Otherwise, returns false. |
OnDestroy()
See MonoBehaviour.
Declaration
protected void OnDestroy()
OnDisable()
See MonoBehaviour.
Declaration
protected void OnDisable()
OnEnable()
See MonoBehaviour.
Declaration
protected void OnEnable()
OnValidate()
See MonoBehaviour.
Declaration
protected void OnValidate()
RotateAroundCameraPosition(Vector3, Single)
Rotates the XR origin object around the camera object's position in world space using the provided vector
as the rotation axis. The XR Origin object is rotated by the amount of degrees provided in angleDegrees.
Declaration
public bool RotateAroundCameraPosition(Vector3 vector, float angleDegrees)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | vector | The axis of the rotation. |
| Single | angleDegrees | The amount of rotation in degrees. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the rotation is performed. Otherwise, returns false. |
RotateAroundCameraUsingOriginUp(Single)
Rotates the XR origin object around the camera object by the provided angleDegrees.
This rotation only occurs around the origin's Up vector
Declaration
public bool RotateAroundCameraUsingOriginUp(float angleDegrees)
Parameters
| Type | Name | Description |
|---|---|---|
| Single | angleDegrees | The amount of rotation in degrees. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the rotation is performed. Otherwise, returns false. |
Start()
See MonoBehaviour.
Declaration
protected void Start()
Events
TrackablesParentTransformChanged
Invoked during Application.onBeforeRender whenever the TrackablesParent transform changes.
Declaration
public event Action<ARTrackablesParentTransformChangedEventArgs> TrackablesParentTransformChanged
Event Type
| Type | Description |
|---|---|
| Action<ARTrackablesParentTransformChangedEventArgs> |