Skip to content
On this page

Usage & Examples

Achievements

Show the achievements dialog

Example

c#
SWAG.Instance.Achievements.ShowDialog(
    // Dialog closed callback
    () => { Debug.Log("Dialog closed."); },
    // Error callback
    (string error) => { Debug.Log(error); }
);

Source: Achievements.cs

Record an achievement

Example

c#
var key = "my_achievement_key";

SWAG.Instance.Achievements.currentUser.RecordAchievement(
    key,
    // Success callback
    () => { Debug.Log("Achievement recorded."); },
    // Error callback
    (string error) => { Debug.Log(error); }
);

Source: AchievementsCurrentUser.cs

Leaderboards

Show the scores dialog

Example

c#
SWAG.Instance.Scores.ShowDialog(
    // Dialog closed callback
    () => { Debug.Log("Dialog closed."); },
    // Error callback
    (string error) => { Debug.Log(error); }
);

Source: Scores.cs

Record a score

Example

c#
var levelKey = "level_0";
var score = 12000f; // time in milliseconds

SWAG.Instance.Scores.currentUser.RecordScore(
    levelKey,
    score,
    // Success callback
    () => { Debug.Log("Score recorded."); },
    // Error callback
    (string error) => { Debug.Log(error); }
);

Source: ScoresCurrentUser.cs

Ads

Play an advertisement

Play a full-screen video ad. The callback is executed when the ad is finished playing.

Example

c#
SWAG.Instance.BeginAd(
    // Ad finished playing callback
    () => { Debug.Log("Ad done."); },
    // Error callback
    (string error) => { Debug.Log(error); }
);

Source: SWAG.cs

You can add Banner Ads to your game by using the Banner UI Component.

  1. In your Packages folder, navigate to SWAG SDK/Runtime/Prefabs.
  2. Drop the SWAGBanner prefab into your scene's main canvas.
  3. Configure the banner's position by adjusting it's RectTransform. You can also choose the size/type of banner from the SWAGBanner component's settings.

When you build your game, these banners will be replaced with ads during runtime.

SWAG Prefab Screenshot

Provider features

The provider API let you interact with the features of the host website (Shockwave.com), such as showing the share dialog, or toggling full-screen mode.

Show the share dialog

Example

c#
SWAG.Instance.ShowShareDialog();

Source: SWAG.cs

Toggle fullscreen

Example

c#
SWAG.Instance.ToggleFullscreen();

Source: SWAG.cs

User

Show the login dialog

Example

c#
SWAG.Instance.User.ShowLoginDialog(
    // Login success callback
    () => { Debug.Log("User logged in."); }
);

Source: User.cs

Get information about the current user

Example

c#
var id = SWAG.Instance.User.id; // User's unique ID
var memberName = SWAG.Instance.User.memberName; // User's display name
var isGuest = SWAG.Instance.User.IsGuest(); // Logged in as guest or not

Source: User.cs

Check if user is a subscriber

Checks to see if the user is a GamePass or Shockwave Unlimited subscriber.

Example

c#
SWAG.Instance.User.IsSubscriber(
    // Success callback
    (bool isSubscriber) => { Debug.Log(isSubscriber); },
    // Error callback
    (string error) => { Debug.Log(error); }
);

Source: User.cs

Set and get data for the user

Set and retrieve cloud save data for the current user. The data is stored in key-value pairs of strings.

Example

c#
// Set data
var key = "any_key";
var value = "any_value";

SWAG.Instance.User.SetData(
    key,
    value,
    // Success callback
    () => { Debug.Log("User data saved."); },
    // Error callback
    (string error) => { Debug.Log(error); }
);

// Get data
SWAG.Instance.User.GetData(
    // Success callback
    (List<UserData> data) => { Debug.Log("User data retrieved."); },
    // Error callback
    (string error) => { Debug.Log(error); }
);

Source: User.cs, UserData.cs