奖励用户观看视频广告。Documentation Index
Fetch the complete documentation index at: https://docs.cloudx.io/llms.txt
Use this file to discover all available pages before exploring further.
using CloudX;
using UnityEngine;
public class RewardedExample : MonoBehaviour
{
private const string RewardedAdUnitId = "rewarded_main";
void Start()
{
// Subscribe to callbacks
CloudXAdsCallbacks.Rewarded.OnAdLoadSuccess += OnRewardedLoaded;
CloudXAdsCallbacks.Rewarded.OnAdLoadFailed += OnRewardedLoadFailed;
CloudXAdsCallbacks.Rewarded.OnAdShowSuccess += OnRewardedShown;
CloudXAdsCallbacks.Rewarded.OnAdShowFailed += OnRewardedShowFailed;
CloudXAdsCallbacks.Rewarded.OnAdHidden += OnRewardedHidden;
CloudXAdsCallbacks.Rewarded.OnAdClicked += OnRewardedClicked;
CloudXAdsCallbacks.Rewarded.OnAdRewarded += OnUserRewarded;
CloudXAdsCallbacks.Rewarded.OnAdRevenuePaid += OnRewardedRevenuePaid;
// Load rewarded ad
CloudXSdk.LoadRewarded(RewardedAdUnitId);
}
public void ShowRewardedAd()
{
if (CloudXSdk.IsRewardedReady(RewardedAdUnitId))
{
// Show with optional placement and custom data
CloudXSdk.ShowRewarded(RewardedAdUnitId, "bonus_coins", "custom_data");
}
else
{
Debug.LogWarning("Rewarded ad not ready yet");
}
}
private void OnRewardedLoaded(CloudXAd ad)
{
Debug.Log($"Rewarded ad loaded: {ad.AdUnitId}");
}
private void OnRewardedLoadFailed(string adUnitId, CloudXError error)
{
Debug.LogError($"Rewarded ad failed to load: {adUnitId} - {error}");
}
private void OnRewardedShown(CloudXAd ad)
{
Debug.Log($"Rewarded ad shown: {ad.AdUnitId}");
}
private void OnRewardedShowFailed(CloudXAd ad, CloudXError error)
{
Debug.LogError($"Rewarded ad failed to show: {ad.AdUnitId} - {error}");
// Reload for next time
CloudXSdk.LoadRewarded(RewardedAdUnitId);
}
private void OnRewardedHidden(CloudXAd ad)
{
Debug.Log($"Rewarded ad hidden: {ad.AdUnitId}");
// Reload for next time
CloudXSdk.LoadRewarded(RewardedAdUnitId);
}
private void OnRewardedClicked(CloudXAd ad)
{
Debug.Log($"Rewarded ad clicked: {ad.AdUnitId}");
}
private void OnUserRewarded(CloudXAd ad, CloudXReward reward)
{
Debug.Log($"User earned reward: {reward.Amount} {reward.Label}");
// Grant reward to user here
GrantRewardToUser();
}
private void OnRewardedRevenuePaid(CloudXAd ad)
{
Debug.Log($"Rewarded ad revenue: ${ad.Revenue} from {ad.NetworkName}");
}
private void GrantRewardToUser()
{
// Your reward logic here
Debug.Log("Granting reward to user!");
}
}