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
Field | Description |
---|---|
Achievements Achievements | Instance of the Achievements class. |
Scores Scores | Instance of the Scores class. |
User User | Instance of the User class. |
static SWAG Instance | A 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.
Parameter | Description |
---|---|
System.Action<string> onSuccess | Executes the onSuccess action if SWAG is ready. |
Parameter | Description |
---|---|
System.Action<string> onSuccess | Executes the onSuccess action if SWAG is ready. |
System.Action<string> onError | Callback for initialization errors. |
GetRequest
Sends a GET request and handles the response.
Parameter | Description |
---|---|
string url | The endpoint URL. |
bool useToken | If true, the request will include the user token. |
System.Action<string> onSuccess | Callback upon a successful request. |
System.Action<string> onError | Callback for request errors. |
PostRequest
Sends a POST request and handles the response.
Parameter | Description |
---|---|
string url | The endpoint URL. |
string postData | Data to post in the request. |
bool useToken | If true, the request will include the user token. |
System.Action<string> onSuccess | Callback upon a successful request. |
System.Action<string> onError | Callback for request errors. |
OpenURL
Opens the provided URL in a new tab. WebGL only.
Parameter | Description |
---|---|
string url | The 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.
Parameter | Description |
---|---|
System.Action onSuccess | Callback upon successful ad display. |
System.Action<string> onError | Callback if an error occurs during ad display. |