Ads Demo¶
Sample scene demonstrating ad integration.
Scene Overview¶
Location: Assets/_IntelliVerseXSDK/Samples/Scenes/IVX_AdsTest.unity
This sample demonstrates:
- Banner ads (show/hide)
- Interstitial ads
- Rewarded video ads
- Reward handling
- Ad events
Scene Hierarchy¶
Canvas
├── ControlPanel
│ ├── BannerSection
│ │ ├── ShowBannerButton
│ │ └── HideBannerButton
│ ├── InterstitialSection
│ │ ├── LoadButton
│ │ ├── ShowButton
│ │ └── StatusText
│ └── RewardedSection
│ ├── LoadButton
│ ├── WatchAdButton
│ ├── StatusText
│ └── RewardDisplay
├── CoinDisplay
│ └── CoinText
└── EventLog
└── LogScrollView
Key Components¶
AdsDemoController.cs¶
using IntelliVerseX.Monetization;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class AdsDemoController : MonoBehaviour
{
[Header("Banner")]
[SerializeField] private Button _showBannerBtn;
[SerializeField] private Button _hideBannerBtn;
[Header("Interstitial")]
[SerializeField] private Button _loadInterstitialBtn;
[SerializeField] private Button _showInterstitialBtn;
[SerializeField] private TMP_Text _interstitialStatus;
[Header("Rewarded")]
[SerializeField] private Button _loadRewardedBtn;
[SerializeField] private Button _watchAdBtn;
[SerializeField] private TMP_Text _rewardedStatus;
[Header("Rewards")]
[SerializeField] private TMP_Text _coinText;
private int _coins = 0;
[Header("Log")]
[SerializeField] private TMP_Text _logText;
void Start()
{
SetupButtons();
SetupEventHandlers();
UpdateUI();
// Preload ads
LoadInterstitial();
LoadRewarded();
}
void SetupButtons()
{
_showBannerBtn.onClick.AddListener(ShowBanner);
_hideBannerBtn.onClick.AddListener(HideBanner);
_loadInterstitialBtn.onClick.AddListener(LoadInterstitial);
_showInterstitialBtn.onClick.AddListener(ShowInterstitial);
_loadRewardedBtn.onClick.AddListener(LoadRewarded);
_watchAdBtn.onClick.AddListener(ShowRewarded);
}
void SetupEventHandlers()
{
// Banner events
IVXAdsManager.OnBannerLoaded += () => Log("Banner loaded");
IVXAdsManager.OnBannerFailed += (err) => Log($"Banner failed: {err}");
// Interstitial events
IVXAdsManager.OnInterstitialLoaded += () =>
{
Log("Interstitial ready");
UpdateUI();
};
IVXAdsManager.OnInterstitialShown += () => Log("Interstitial shown");
IVXAdsManager.OnInterstitialClosed += () =>
{
Log("Interstitial closed");
LoadInterstitial();
};
// Rewarded events
IVXAdsManager.OnRewardedVideoLoaded += () =>
{
Log("Rewarded video ready");
UpdateUI();
};
IVXAdsManager.OnRewardedVideoCompleted += (reward) =>
{
Log($"Reward earned: {reward.Amount} {reward.Currency}");
AddCoins(100);
};
IVXAdsManager.OnRewardedVideoClosed += (wasRewarded) =>
{
Log($"Rewarded closed (rewarded: {wasRewarded})");
LoadRewarded();
};
}
// Banner methods
void ShowBanner()
{
IVXAdsManager.Instance.ShowBanner(BannerPosition.Bottom);
Log("Showing banner");
}
void HideBanner()
{
IVXAdsManager.Instance.HideBanner();
Log("Hiding banner");
}
// Interstitial methods
void LoadInterstitial()
{
IVXAdsManager.Instance.LoadInterstitial();
_interstitialStatus.text = "Loading...";
Log("Loading interstitial");
}
void ShowInterstitial()
{
if (IVXAdsManager.Instance.IsInterstitialReady())
{
IVXAdsManager.Instance.ShowInterstitial();
}
else
{
Log("Interstitial not ready");
}
}
// Rewarded methods
void LoadRewarded()
{
IVXAdsManager.Instance.LoadRewardedVideo();
_rewardedStatus.text = "Loading...";
Log("Loading rewarded video");
}
void ShowRewarded()
{
if (IVXAdsManager.Instance.IsRewardedVideoReady())
{
IVXAdsManager.Instance.ShowRewardedVideo();
}
else
{
Log("Rewarded video not ready");
}
}
// Helpers
void AddCoins(int amount)
{
_coins += amount;
_coinText.text = $"Coins: {_coins}";
}
void UpdateUI()
{
_showInterstitialBtn.interactable = IVXAdsManager.Instance.IsInterstitialReady();
_interstitialStatus.text = _showInterstitialBtn.interactable ? "Ready" : "Not Ready";
_watchAdBtn.interactable = IVXAdsManager.Instance.IsRewardedVideoReady();
_rewardedStatus.text = _watchAdBtn.interactable ? "Ready" : "Not Ready";
}
void Log(string message)
{
Debug.Log($"[Ads] {message}");
_logText.text = $"{System.DateTime.Now:HH:mm:ss} - {message}\n{_logText.text}";
}
}
How to Use¶
Running the Sample¶
- Open
IVX_AdsTest.unity - Configure ad provider in
IntelliVerseXConfig - Press Play
Testing Banner¶
- Click "Show Banner"
- Banner appears at bottom
- Click "Hide Banner" to remove
Testing Interstitial¶
- Click "Load" (auto-loads on start)
- Wait for "Ready" status
- Click "Show"
- Watch ad play
- Close to return
Testing Rewarded¶
- Click "Load" (auto-loads on start)
- Wait for "Ready" status
- Click "Watch Ad"
- Watch full video
- Observe coin reward
Test Mode¶
Use Test Ads
Always use test mode during development to avoid account flags.
In IntelliVerseXConfig:
- Enable "Dev Test Ads" checkbox
- Ads will show test content
Event Log¶
The sample includes a real-time event log showing:
- Ad load events
- Ad show events
- Ad completion events
- Errors
Customization¶
Change Reward Amount¶
// In IntelliVerseXConfig or code:
private const int REWARD_AMOUNT = 100;
IVXAdsManager.OnRewardedVideoCompleted += (reward) =>
{
AddCoins(REWARD_AMOUNT);
};
Different Banner Position¶
// Top banner
IVXAdsManager.Instance.ShowBanner(BannerPosition.Top);
// Center banner
IVXAdsManager.Instance.ShowBanner(BannerPosition.Center);