Usage & Examples
Achievements
Show the achievements dialog
Example
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
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
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
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
SWAG.Instance.BeginAd(
// Ad finished playing callback
() => { Debug.Log("Ad done."); },
// Error callback
(string error) => { Debug.Log(error); }
);
Source: SWAG.cs
Banner ads
You can add Banner Ads to your game by using the Banner UI Component.
- In your
Packages
folder, navigate toSWAG SDK/Runtime/Prefabs
. - Drop the
SWAGBanner
prefab into your scene's main canvas. - 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.
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
SWAG.Instance.ShowShareDialog();
Source: SWAG.cs
Toggle fullscreen
Example
SWAG.Instance.ToggleFullscreen();
Source: SWAG.cs
User
Show the login dialog
Example
SWAG.Instance.User.ShowLoginDialog(
// Login success callback
() => { Debug.Log("User logged in."); }
);
Source: User.cs
Get information about the current user
Example
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
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
// 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