Class XROrigin
The XR Origin represents the session-space origin (0, 0, 0) in an XR scene.
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
Remarks
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.
Properties
Camera
The Camera used to render the scene from the point of view of the XR device. Must be a child of
the GameObject containing this XROrigin
component.
Declaration
public Camera Camera { get; set; }
Property Value
Type | Description |
---|---|
Camera |
Remarks
You can add a
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 |
Remarks
See Trackables for more information.
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
destinationUp
will be in the direction ofdestinationForward
- The up vector of the XR Origin object will match the provided
destinationUp
vector (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
destinationUp
vector - The up vector of the XR Origin object will match the provided
destinationUp
vector
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> |