Skip to content
On this page

SWAG (Class)

The SWAG class manages the complete functionality for the SWAG API and is the main entry-point into the SDK. This class inherits from MonoBehavior and should be placed on a GameObject in your scene.

Fields

FieldDescription
Achievements AchievementsInstance of the Achievements class.
Scores ScoresInstance of the Scores class.
User UserInstance of the User class.
static SWAG InstanceA singleton instance of the SWAG class.

Methods

OnReady (Overloaded)

Executes the onSuccess action when SWAG is ready. If not ready, it prepares an async handler to execute once ready.

ParameterDescription
System.Action<string> onSuccessExecutes the onSuccess action if SWAG is ready.
ParameterDescription
System.Action<string> onSuccessExecutes the onSuccess action if SWAG is ready.
System.Action<string> onErrorCallback for initialization errors.

GetRequest

Sends a GET request and handles the response.

ParameterDescription
string urlThe endpoint URL.
bool useTokenIf true, the request will include the user token.
System.Action<string> onSuccessCallback upon a successful request.
System.Action<string> onErrorCallback for request errors.

PostRequest

Sends a POST request and handles the response.

ParameterDescription
string urlThe endpoint URL.
string postDataData to post in the request.
bool useTokenIf true, the request will include the user token.
System.Action<string> onSuccessCallback upon a successful request.
System.Action<string> onErrorCallback for request errors.

OpenURL

Opens the provided URL in a new tab. WebGL only.

ParameterDescription
string urlThe URL to open.

ToggleFullscreen

Toggles the fullscreen state of the application. WebGL only.

ShowShareDialog

Opens the share dialog. WebGL only.

BeginAd

Displays an advertisement. WebGL only.

ParameterDescription
System.Action onSuccessCallback upon successful ad display.
System.Action<string> onErrorCallback if an error occurs during ad display.