C# Functions

Refer various functions applicable for Unity integration

The WebAR’s functions are accessed through the global variableWEBARSDK, which is available after the WebAR SDK script has been loaded.

StartTracking()

Usage

WEBARSDK.StartTracking();
WEBARSDK.StartTracking(KeepARAfterLost);

Description

If the SDK script attribute auto-start is set to false, then the Surface Tracking experience has to be started manually by calling StartTracking() method. For example, this will be useful when the user has to be displayed some information only after the user clicks a button to enter into the Surface tracking experience.

If the user keeps the flag ‘keeARAfterLost’ to true, AR will move with the camera when tracking goes in lost mode, this can be used to implement the “peel-off” feature.

StopTracking()

Usage

WEBARSDK.StopTracking();
WEBARSDK.StopTracking(KeepARVisible);

Description

Surface Tracking experience has to be stopped manually by calling StopTracking() method. For example, this will be useful when the user has to be stop the tracking after a specific event .

keepARVisible = true, keeps AR object visible after user stops tracking. Default value is false.

GetTrackingStatus()

Usage

WEBARSDK.GetTrackingStatus();

Description

This API gives a callback once the surface tracking experience loads. It a return method and user will get the Status like TRACKING, TRACKED, STOPPED.

GetDetectedMarkerID()

Usage

WEBARSDK.GetDetectedMarkerID();

Description

This function is used to get the marker I of detected marker.

GetLostMarkerID()

Usage

WEBARSDK.GetLostMarkerID();

Description

This function will return a lost markerID or last detected marker ID.

GetTrackingQuality()

Usage

WEBARSDK.GetTrackingQuality();

Description

This function is defined for a Surface tracking and will return a tracking quality in HIGH, MEDIUM, LOW, LOST.

GetSelectedTracking()

Usage

WEBARSDK.GetSelectedTracking();

Description

This function is return an tracking method selected for current proejct(Surface Tracking, Marker Tracking)

OnTrackingFoundCallBack()

Usage

Description

On Target Found is an event attached to the WEBARSDK, user can subscribe any method and this will get execute after the tracking found.this will apply for both Marker Tracking as well as Surface Tracking

OnTrackingLostCallBack()

Usage

Description

On Target Lost is an event attached to the WEBARSDK, user can subscribe any method and this will get execute after the tracking Lost, this will apply for both Marker Tracking as well as Surface Tracking.

GetCurrentPosition

Usage

WEBARSDK.GetTransform().position;

Description

Returns the position of the stage/camera object based on attribute 'static-camera'. Please note that tracking assumes a Static-Camera-With-A-Moving-Stage by default. However, it can be changed to Moving-Camera-With-A-Static-Stage using attribute 'static-camera'.

GetCurrentScale

Usage

WEBARSDK.GetTransform().localScale;

Description

Returns the scale of the stage object.

GetCurrentRotation

Usage

WEBARSDK.GetTransform().rotation;

Description

Returns a rotation of the stage/camera object based on attribute_'static-camera'_. It is the orientation of stage/camera with respect to the world.

OnARModelPlaced()

Usage

Description

On AR Model Placed is an event attached to the WEBARSDK, users can subscribe to any method and this will get executed after the AR model is placed on surface, this will apply only for Surface Tracking.

Example

OnTrackingStarted()

Usage

Description

On Tracking Started is an event attached to the WEBARSDK, user can subscribe any method and this will get execute after the tracking started, this will apply for both Marker Tracking as well as Surface Tracking.

OnTrackingStopped()

Usage

Description

On Tracking Stopped is an event attached to the WEBARSDK, user can subscribe any method and this will get execute after the tracking stopped, this will apply for both Marker Tracking as well as Surface Tracking.

OnResetClick()

Usage

On Reset Click is an event attached to the WEBARSDK, users can subscribe to any method and this will get executed after theReset button is clicked, this will apply only for Surface Tracking.

Example

TakeScreenshot()

Usage

Taking screenshots programmatically in a Unity application allows you to capture the current state of the game or application.

Description

  • Uncheck the "Enable Photo UI" from inspector window.

  • Write a script to cature screenshot and call a method "WEBARSDK.TakeScreenshot(returnBuffer)"

  • "returnBuffer" is a boolean value if returnBuffer->false a preview UI with download button is displayed on the screen.

  • and if "returnBuffer" is true the "WEBARSDK.TakeScreenshot" method converts screenshot image data in binary format and to access this data user needs to call a method "WEBARSDK.GetScreenshotTexture" after some delay.

  • "WEBARSDK.GetScreenshotTexture" will return a image data in base64 string format, using this string user can convert or use it anywhere according to the use case.