Ad API
Ad API
ShowRewardedAd(adUnitId, onSuccess, onFail) (Recommended)
Displays a rewarded ad in a single call. The platform automatically handles ad loading, displaying, retries on failure, and error notifications.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
adUnitId | string | ✅ | Ad unit ID |
onSuccess | Action<ShowRewardedAdResult> | - | Success callback |
onFail | Action<string> | - | Failure callback |
Success Response (ShowRewardedAdResult):
| Field | Type | Description |
|---|---|---|
isEnded | bool | Whether the ad was watched to completion |
TudadaSDK.Instance.ShowRewardedAd("ad-unit-id",
onSuccess: (result) => {
if (result.isEnded)
{
Debug.Log("Reward granted!");
GiveReward();
}
},
onFail: (err) => {
Debug.LogError("Ad display failed: " + err);
}
);
Note: When ad loading fails, the platform automatically retries and displays a notification popup on final failure. You do not need to implement separate error handling UI in your game.
CreateRewardedVideoAd(adUnitId) (Legacy)
Creates a rewarded video ad instance.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
adUnitId | string | ✅ | Ad unit ID |
Instance Members (TudadaRewardedVideoAd):
| Member | Type | Description |
|---|---|---|
Load(onSuccess?, onFail?) | Method | Load ad |
Show(onSuccess?, onFail?) | Method | Show ad |
Destroy() | Method | Destroy instance |
IsLoaded | bool | Whether loading is complete |
IsDestroyed | bool | Whether destroyed |
AdUnitId | string | Ad unit ID |
OnLoad | Event | Load complete |
OnError | Event | Error occurred |
OnClose | Event | Close (includes isEnded) |
// Create ad instance
TudadaRewardedVideoAd rewardedAd = TudadaSDK.Instance.CreateRewardedVideoAd("ad-unit-id");
// Register events
rewardedAd.OnLoad += () => {
Debug.Log("Ad loaded");
};
rewardedAd.OnError += (err) => {
Debug.LogError("Ad error: " + err.errMsg);
};
rewardedAd.OnClose += (result) => {
if (result.isEnded)
{
// User watched to the end -> grant reward
Debug.Log("Reward granted!");
GiveReward();
}
else
{
// Closed early
Debug.Log("Ad closed early");
}
// Reload for next ad
rewardedAd.Load();
};
// Load ad
rewardedAd.Load(
onSuccess: (result) => Debug.Log("Load success"),
onFail: (err) => Debug.LogError("Load failed: " + err)
);
Showing the Ad:
// Show after loading is complete
if (rewardedAd.IsLoaded)
{
rewardedAd.Show(
onSuccess: (result) => Debug.Log("Ad displayed"),
onFail: (err) => Debug.LogError("Display failed: " + err)
);
}
Important: Call
Destroy()on ad instances when they are no longer needed to clean up resources.