Table of Contents

Class ARSession

Namespace
easyar
Assembly
EasyAR.Sense.dll

The MonoBehaviour controlling the AR session in the scene. A session contains a set of components assembled into an ARAssembly and manages the data flow throughout the lifecycle. This component is the entry point for AR. Only one active instance is allowed at any given time.

All functionalities of EasyAR components become available only after StartSession().

The relative transform between the Camera and certain AR components is controlled by the session. One object is designated as the CenterObject, which remains stationary in the scene, while other objects move relative to this CenterObject. This object is selected based on the value of CenterMode. For more details, refer to the description of ARSession.ARCenterMode.

[DefaultExecutionOrder(-2147483648)]
[DisallowMultipleComponent]
[RequireComponent(typeof(EasyARController), typeof(DiagnosticsController))]
[RequireComponent(typeof(FrameRecorder), typeof(FramePlayer), typeof(CameraImageRenderer))]
public class ARSession : MonoBehaviour
Inheritance
ARSession

Fields

AutoStart

Automatically starts the session during MonoBehaviour.Start. If set to false, you need to manually call StartSession() to start the session.

[SerializeField]
[HideInInspector]
public bool AutoStart

CenterMode

AR center mode. Modifiable at any time, takes effect immediately. If the specified mode is unavailable, it will be automatically changed to an available mode.

[SerializeField]
[HideInInspector]
public ARSession.ARCenterMode CenterMode

HorizontalFlip

Horizontal mirror rendering mode. Modifiable at any time, takes effect immediately. Only available when using image or object tracking.

[SerializeField]
[HideInInspector]
public ARSession.FlipOptions HorizontalFlip

Properties

AssembleOptions

Session assembly options, must be set before Assemble() (implicitly called by StartSession() if not called before).

public AssembleOptions AssembleOptions { get; }

Assembly

Assembly of AR components.

public ARAssembly Assembly { get; }

AvailableCenterMode

Available center modes for the current session.

public IReadOnlyList<ARSession.ARCenterMode> AvailableCenterMode { get; }

CenterObject

The center object used by this session for the current frame.

This object represents the stationary object in Unity space or its parent node. It could be the Origin, the Camera, or a `target`. A `Target` is an object containing a TargetController or BlockRootController component. When using sparse spatial maps or EasyAR Mega, the actual center GameObject is the located map or block object under the root node; the CenterObject is its parent node. For more details, refer to the description of ARSession.ARCenterMode.

public GameObject CenterObject { get; }

Diagnostics

Session diagnostic component.

public DiagnosticsController Diagnostics { get; }

Origin

The session origin during any motion tracking functionality.

It is automatically selected from the scene or created by EasyAR or a third-party frame source extension if it doesn't exist. When using the built-in frame source, the XROrigin from the Unity XR framework will be selected if it exists. If the AR Foundation package is absent, only the default hierarchy XR Origin will be selected.

public GameObject Origin { get; }

Report

Session report. Available for viewing after assemble completion and updated when the session state changes. Used to inspect details like session failure information or component availability.

public SessionReport Report { get; }

SpecificTargetCenter

Manually specified center object. When CenterMode == SpecificTarget, CenterObject will be set to this object. Modifiable at any time, takes effect immediately.

This object must contain either a TargetController or a BlockRootController component.

public GameObject SpecificTargetCenter { get; set; }

State

Current state of the session.

public ARSession.SessionState State { get; }

TrackingStatus

Motion tracking status during any motion tracking functionality.

public Optional<MotionTrackingStatus> TrackingStatus { get; }

enabled

Enable/disable session output while running. In the disabled state, the session produces no output; camera images (if controlled by EasyAR) and the transforms of all session objects do not update.

public bool enabled { get; set; }

Methods

Assemble()

Assembles the session using AssembleOptions. If called, it is invoked automatically within StartSession().

public IEnumerator Assemble()

ImageCoordinatesFromScreenCoordinates(Vector2)

Transforms from screen coordinates ([0, 1]^2) to image coordinates ([0, 1]^2). pointInView must be normalized to [0, 1]^2. Unavailable on head-mounted displays.

public Optional<Vector2> ImageCoordinatesFromScreenCoordinates(Vector2 pointInView)

Parameters

pointInView

StartSession()

Starts the session. If AutoStart is true, it is called automatically during MonoBehaviour.Start.

public void StartSession()

StopSession(bool)

Stops the running session. All transform updates and image rendering updates cease. You can optionally retain the last frame image upon stopping, but this only works when EasyAR controls the image rendering (ineffective for AR Foundation and HMDs).

public void StopSession(bool keepLastFrame)

Parameters

keepLastFrame

Events

AssembleUpdate

Session Assemble() update event. This event is triggered 1-2 times during an Assemble() (implicitly called by StartSession() if not called before). The first trigger occurs upon Assemble completion. If the device list update finishes simultaneously with Assemble completion, there will be no second call; otherwise, the second call happens when the device list update completes.

public event Action<SessionReport.AvailabilityReport> AssembleUpdate

InputFrameUpdate

Input frame update event, triggered only when the session's displayed InputFrame changes. Not received on head-mounted displays, and if a see-through image exists, its rendering is handled by the device.

public event Action<InputFrame> InputFrameUpdate

PostSessionUpdate

Session update completion event, occurring at the same frequency as MonoBehaviour.Update (requires correct implementation by extension authors on HMDs). When this event triggers, all transform changes controlled by EasyAR for the current frame have been finalized.

public event Action PostSessionUpdate

StateChanged

Event triggered when the session State changes.

public event Action<ARSession.SessionState> StateChanged