| name | integration |
| description | Use this skill when working with Playgama Bridge SDK for Unity games. Activates for game development involving cross-platform publishing, advertisements, in-app purchases, leaderboards, or social features using Playgama Bridge in Unity/C#. |
Playgama Bridge SDK Integration for Unity
Playgama Bridge is a cross-platform SDK for publishing Unity WebGL games across 20+ platforms including Playgama, YouTube, Yandex Games, Crazy Games, Poki, Facebook, Telegram, Xiaomi, and more.
Installation
- Open Unity Package Manager (Window -> Package Manager)
- Click "+" and select "Add package from git URL"
- Enter:
https://github.com/playgama/bridge-unity.git
- Click "Add"
WebGL Export
When building for WebGL, select the appropriate index template provided by the SDK to ensure proper initialization.
Initialization
The SDK initializes automatically. Access all modules through the static Bridge class:
using Playgama;
Bridge.advertisement
Bridge.game
Bridge.storage
Bridge.platform
Bridge.social
Bridge.player
Bridge.device
Bridge.leaderboards
Bridge.payments
Bridge.achievements
Bridge.remoteConfig
Device
DeviceType type = Bridge.device.type;
Platform
string platformId = Bridge.platform.id;
string language = Bridge.platform.language;
string tld = Bridge.platform.tld;
string payload = Bridge.platform.payload;
bool isAudioEnabled = Bridge.platform.isAudioEnabled;
Bridge.platform.GetServerTime((DateTime? serverTime) =>
{
if (serverTime.HasValue) {
Debug.Log($"Server time: {serverTime.Value}");
}
});
Bridge.platform.SendMessage(PlatformMessage.GameReady);
Bridge.platform.SendMessage(PlatformMessage.InGameLoadingStarted);
Bridge.platform.SendMessage(PlatformMessage.InGameLoadingStopped);
Bridge.platform.SendMessage(PlatformMessage.GameplayStarted);
Bridge.platform.SendMessage(PlatformMessage.GameplayStopped);
Bridge.platform.SendMessage(PlatformMessage.PlayerGotAchievement);
Bridge.platform.audioStateChanged += (bool isEnabled) =>
{
AudioListener.volume = isEnabled ? 1f : 0f;
};
Bridge.platform.pauseStateChanged += (bool isPaused) =>
{
Time.timeScale = isPaused ? 0f : 1f;
};
Player
string playerId = Bridge.player.id;
string playerName = Bridge.player.name;
List<string> photos = Bridge.player.photos;
Dictionary<string, string> extra = Bridge.player.extra;
bool authSupported = Bridge.player.isAuthorizationSupported;
bool isAuthorized = Bridge.player.isAuthorized;
var options = new Dictionary<string, object>();
Bridge.player.Authorize(options, (bool success) =>
{
if (success)
{
Debug.Log("Player authorized");
Debug.Log($"Player ID: {Bridge.player.id}");
Debug.Log($"Player name: {Bridge.player.name}");
}
else
{
Debug.Log("Authorization failed or cancelled");
}
});
Storage
Bridge.storage.Get("key", (bool success, string value) =>
{
if (success) {
Debug.Log($"Value: {value}");
}
});
var keys = new List<string> { "key1", "key2" };
Bridge.storage.Get(keys, (bool success, List<string> values) =>
{
if (success)
{
for (int i = 0; i < keys.Count; i++) {
Debug.Log($"{keys[i]}: {values[i]}");
}
}
});
Bridge.storage.Set("key", "value", (bool success) =>
{
if (success) {
Debug.Log("Saved");
}
});
Bridge.storage.Set("score", 100, (bool success) =>
{
if (success) {
Debug.Log("Score saved");
}
});
Bridge.storage.Set("tutorial_complete", true);
var saveKeys = new List<string> { "key1", "key2" };
var saveValues = new List<object> { "value1", 42 };
Bridge.storage.Set(saveKeys, saveValues, (bool success) =>
{
if (success) {
Debug.Log("All values saved");
}
});
Bridge.storage.Delete("key", (bool success) =>
{
if (success) {
Debug.Log("Deleted");
}
});
Bridge.storage.Delete(new List<string> { "key1", "key2" });
Banner Ads
bool supported = Bridge.advertisement.isBannerSupported;
Bridge.advertisement.ShowBanner(BannerPosition.Bottom, "menu");
Bridge.advertisement.HideBanner();
BannerState state = Bridge.advertisement.bannerState;
Bridge.advertisement.bannerStateChanged += (BannerState state) =>
{
Debug.Log($"Banner state: {state}");
};
Interstitial Ads
bool supported = Bridge.advertisement.isInterstitialSupported;
int delay = Bridge.advertisement.minimumDelayBetweenInterstitial;
Bridge.advertisement.SetMinimumDelayBetweenInterstitial(30);
Bridge.advertisement.ShowInterstitial("level_complete");
InterstitialState state = Bridge.advertisement.interstitialState;
Bridge.advertisement.interstitialStateChanged += (InterstitialState state) =>
{
switch (state)
{
case InterstitialState.Opened:
break;
case InterstitialState.Closed:
case InterstitialState.Failed:
break;
}
};
Rewarded Ads
bool supported = Bridge.advertisement.isRewardedSupported;
Bridge.advertisement.ShowRewarded("double_coins");
string placement = Bridge.advertisement.rewardedPlacement;
RewardedState state = Bridge.advertisement.rewardedState;
Bridge.advertisement.rewardedStateChanged += (RewardedState state) =>
{
switch (state)
{
case RewardedState.Opened:
break;
case RewardedState.Rewarded:
break;
case RewardedState.Closed:
case RewardedState.Failed:
break;
}
};
AdBlock Detection
Bridge.advertisement.CheckAdBlock((bool isAdBlockEnabled) =>
{
if (isAdBlockEnabled) {
Debug.Log("AdBlock detected");
}
});
In-App Purchases
bool supported = Bridge.payments.isSupported;
Bridge.payments.GetCatalog((bool success, List<Dictionary<string, string>> items) =>
{
if (success)
{
foreach (var item in items)
{
Debug.Log($"ID: {item["id"]}");
Debug.Log($"Price: {item["price"]}");
Debug.Log($"Currency: {item["priceCurrencyCode"]}");
Debug.Log($"Value: {item["priceValue"]}");
}
}
});
Bridge.payments.Purchase("product_id", (bool success, Dictionary<string, string> purchase) =>
{
if (success)
{
Debug.Log($"Purchased: {purchase["id"]}");
}
else
{
Debug.Log("Purchase cancelled or failed");
}
});
var options = new Dictionary<string, object>
{
{ "externalId", "test_externalId" }
};
Bridge.payments.Purchase("product_id", options, (bool success, Dictionary<string, string> purchase) =>
{
if (success) {
Debug.Log($"Purchased: {purchase["id"]}");
}
});
Bridge.payments.ConsumePurchase("product_id", (bool success, Dictionary<string, string> purchase) =>
{
if (success) {
Debug.Log($"Consumed: {purchase["id"]}");
}
});
Bridge.payments.GetPurchases((bool success, List<Dictionary<string, string>> purchases) =>
{
if (success)
{
foreach (var p in purchases) {
Debug.Log($"Owned: {p["id"]}");
}
}
});
Leaderboards
LeaderboardType type = Bridge.leaderboards.type;
Bridge.leaderboards.SetScore("leaderboard_id", 1000, (bool success) =>
{
if (success) {
Debug.Log("Score saved");
}
});
Bridge.leaderboards.GetEntries("leaderboard_id", (bool success, List<Dictionary<string, string>> entries) =>
{
if (success)
{
foreach (var entry in entries)
{
Debug.Log($"Name: {entry["name"]}");
Debug.Log($"Score: {entry["score"]}");
Debug.Log($"Rank: {entry["rank"]}");
Debug.Log($"Photo: {entry["photo"]}");
}
}
});
Bridge.leaderboards.ShowNativePopup("leaderboard_id", (bool success) =>
{
Debug.Log($"Popup closed, success: {success}");
});
Social Features
Share
bool supported = Bridge.social.isShareSupported;
var options = new Dictionary<string, object>();
switch (Bridge.platform.id)
{
case "vk":
options["link"] = "https://...";
break;
case "facebook":
options["image"] = "base64...";
options["text"] = "Check this game!";
break;
}
Bridge.social.Share(options, (bool success) =>
{
Debug.Log($"Share success: {success}");
});
Invite Friends
bool supported = Bridge.social.isInviteFriendsSupported;
var options = new Dictionary<string, object>
{
{ "text", "Join me in this game!" }
};
Bridge.social.InviteFriends(options, (bool success) =>
{
Debug.Log($"Invite success: {success}");
});
Join Community
bool supported = Bridge.social.isJoinCommunitySupported;
var options = new Dictionary<string, object>();
switch (Bridge.platform.id)
{
case "vk":
case "ok":
options["groupId"] = 123456;
break;
}
Bridge.social.JoinCommunity(options, (bool success) =>
{
Debug.Log($"Join community success: {success}");
});
Other Social Methods
if (Bridge.social.isAddToFavoritesSupported)
{
Bridge.social.AddToFavorites((bool success) =>
{
Debug.Log($"Add to favorites: {success}");
});
}
if (Bridge.social.isRateSupported)
{
Bridge.social.Rate((bool success) =>
{
Debug.Log($"Rate: {success}");
});
}
if (Bridge.social.isAddToHomeScreenSupported)
{
Bridge.social.AddToHomeScreen((bool success) =>
{
Debug.Log($"Add to home screen: {success}");
});
}
if (Bridge.social.isCreatePostSupported)
{
var options = new Dictionary<string, object>
{
{ "text", "I scored 1000 points!" }
};
Bridge.social.CreatePost(options, (bool success) =>
{
Debug.Log($"Create post: {success}");
});
}
bool externalLinksAllowed = Bridge.social.isExternalLinksAllowed;
Achievements
bool supported = Bridge.achievements.isSupported;
bool getListSupported = Bridge.achievements.isGetListSupported;
bool nativePopupSupported = Bridge.achievements.isNativePopupSupported;
var options = new Dictionary<string, object>
{
{ "id", "first_win" }
};
Bridge.achievements.Unlock(options, (bool success) =>
{
Debug.Log($"Achievement unlocked: {success}");
});
Bridge.achievements.GetList(new Dictionary<string, object>(), (bool success, List<Dictionary<string, string>> achievements) =>
{
if (success)
{
foreach (var achievement in achievements)
{
Debug.Log($"ID: {achievement["id"]}");
Debug.Log($"Name: {achievement["name"]}");
Debug.Log($"Unlocked: {achievement["unlocked"]}");
}
}
});
Bridge.achievements.ShowNativePopup(new Dictionary<string, object>(), (bool success) =>
{
Debug.Log($"Popup closed: {success}");
});
Remote Config
bool supported = Bridge.remoteConfig.isSupported;
Bridge.remoteConfig.Get((bool success, Dictionary<string, string> config) =>
{
if (success)
{
foreach (var kvp in config)
{
Debug.Log($"{kvp.Key}: {kvp.Value}");
}
}
});
var options = new Dictionary<string, object>
{
{ "key", "value" }
};
Bridge.remoteConfig.Get(options, (bool success, Dictionary<string, string> config) =>
{
if (success)
{
string someValue = config["some_key"];
}
});
Best Practices
- Always call
Bridge.platform.SendMessage(PlatformMessage.GameReady) when game is fully loaded and ready
- Subscribe to
audioStateChanged and mute/unmute game audio accordingly
- Subscribe to
pauseStateChanged and pause/resume game accordingly
- Show ads at natural breakpoints (level transitions, player death), not during gameplay
- Check
isSupported properties before using platform-specific features
- Grant rewards only when
RewardedState.Rewarded is received
- Use platform-specific options for social features