ARSession Class¶
Description¶
MonoBehaviour which controls AR session in the scene. One session contains a set of components assembled as ARAssembly and controls data flow in the whole life cycle. This component is the entrance of AR. Multiple active instances are not allowed in the same time.
All EasyAR components can only work after ARSession.StartSession .
Relative transform between Camera and a few AR components are controlled by the session, one of those objects is called ARSession.CenterObject , it stays still in the scene, while other objects move relatively to ARSession.CenterObject . This object is selected according to the value of ARSession.CenterMode . See description of ARSession.ARCenterMode for more details.
Enums¶
public enum ARSession.ARCenterMode |
AR center mode. |
public enum ARSession.ARHorizontalFlipMode |
Horizontal flip rendering mode. |
public enum ARSession.SessionState |
The state of session. |
MonoBehaviour Messages¶
private void Awake() |
private void OnEnable() |
private void Start() |
private void Update() |
private void OnDisable() |
private void OnDestroy() |
Fields¶
AutoStart¶
- C#
public bool AutoStart
Start session automatically during MonoBehaviour .Start. You need to manually call ARSession.StartSession to start the session if set to false.
CenterMode¶
- C#
public ARSession.ARCenterMode CenterMode
AR center mode. Modify at any time and takes effect immediately. If the specified mode is not available in a session, it will be change to one of the available mode automatically.
HorizontalFlipNormal¶
- C#
public ARSession.ARHorizontalFlipMode HorizontalFlipNormal
Horizontal flip rendering mode for normal camera. Modify at any time and takes effect immediately. Only available when using image or object tracking.
HorizontalFlipFront¶
- C#
public ARSession.ARHorizontalFlipMode HorizontalFlipFront
Horizontal flip rendering mode for front camera. Modify at any time and takes effect immediately. Only available when using image or object tracking.
Properties¶
SpecificTargetCenter¶
- C#
public GameObject SpecificTargetCenter { get; set; }
Specified AR center object. ARSession.CenterObject will be set to this object when ARSession.CenterMode == ARSession.ARCenterMode.SpecificTarget . Modify at any time and takes effect immediately.
The object must contain one of the following component: TargetController , SparseSpatialMapRootController or Scene.BlockRootController .
CenterObject¶
- C#
public GameObject CenterObject { get; }
Center object this session is using in current frame.
This object represents an object or parent of object that do not move in Unity space. It can be ARSession.Origin , ARAssembly.Camera or some target. A target could be object containing one of the following component: TargetController , SparseSpatialMapRootController or Scene.BlockRootController . While in the context of sparse spatial map or EasyAR Mega, the exact center GameObject is the localized map or block object under the root, and ARSession.CenterObject is parent of this object. See description of ARSession.ARCenterMode for more details.
Assembly¶
- C#
public ARAssembly Assembly { get; }
Assembly of AR components.
Diagnostics¶
- C#
public DiagnosticsController Diagnostics { get; }
Session diagnostics component.
FrameCameraParameters¶
- C#
public Optional< CameraParameters > FrameCameraParameters { get; }
CameraParameters from current frame.
DisplayCompensation¶
- C#
public Optional< Quaternion > DisplayCompensation { get; }
Display rotation compensation of current frame.
AvailableCenterMode¶
- C#
public IReadOnlyList< ARSession.ARCenterMode > AvailableCenterMode { get; }
Available center mode in the session.
Origin¶
- C#
public GameObject Origin { get; }
Origin of session when one type of motion tracking is running.
TrackingStatus¶
- C#
public Optional< MotionTrackingStatus > TrackingStatus { get; }
Tracking status when one type of motion tracking is running.
AssembleOptions¶
- C#
public AssembleOptions AssembleOptions { get; }
Session asselble options. Need to set before ARSession.Assemble calling. ARSession.StartSession will call assemble if it was not called before.
Report¶
- C#
public SessionReport Report { get; }
Session report. It can be accessed after assemble finish, and will be updated when session state change. It can be used to check session broken details or component availablility details.
State¶
- C#
public ARSession.SessionState State { get; }
The state of current session.
Events¶
StateChanged¶
- C#
public event Action< ARSession.SessionState > StateChanged
Session ARSession.State change event.
AssembleUpdate¶
- C#
public event Action< SessionReport.AvailabilityReport > AssembleUpdate
Session ARSession.Assemble update event. This event will be triggered 1-2 times during one ARSession.Assemble calling. ARSession.StartSession will call assemble if it was not called before. The first time of the event happens when assemble finish. It will be the only one if device list finished download when trigger, otherwise another event will be triggered when the download finish.
PostFrameUpdate¶
- C#
public event Action< OutputFrame > PostFrameUpdate
Output frame update event. It has the same frequency as MonoBehaviour .Update. All transform changes controlled by EasyAR would be ended when this event triggers.
Methods¶
StartSession¶
- C#
public void StartSession()
Start session. It will be called automatically from MonoBehaviour .Start if ARSession.AutoStart is true.
Assemble¶
- C#
public System.Collections.IEnumerator Assemble()
Assemble session using ARSession.AssembleOptions . It will be called automatically from ARSession.StartSession not called before.
StopSession¶
- C#
public void StopSession(bool keepLastFrame)
Stop session. All transform update and image rendering update will stop. You can choose to keep the last image frame when stop, but it only works when EasyAR controls image rendering (not using AR Foundation and HMD, etc.).
ImageCoordinatesFromScreenCoordinates¶
Transforms points from screen coordinate system ([0, 1]^2) to image coordinate system ([0, 1]^2). pointInView should be normalized to [0, 1]^2.