For AI agents: the complete documentation index is available at /AchEngine/zh/llms.txt, the full documentation bundle is available at /AchEngine/zh/llms-full.txt, and this page is available as Markdown at /AchEngine/zh/usage/managers/ads.md.
  • 简体中文
  • AdsManager

    AdsManager 使用 Unity Ads Legacy 4.16.4 作为默认提供方,负责加载和展示插屏、激励和横幅广告。 com.unity.ads 已声明为 AchEngine 1.3.2 依赖,添加包时 Package Manager 会一并解析。 AchManagerInstaller 也会自动注册 AdsManager。

    正式投放需要 Unity Dashboard 中的 Android/iOS 游戏 ID 与广告单元 ID。Editor 使用 Android 游戏 ID, 也请配置它。仅在开发期间将 testMode 保持为 true。

    快速设置

    在启动流程中、初始化之前设置一次。使用 VContainer 时,对注入的 AdsManager 调用相同代码。

    var ads = ServiceLocator.Resolve<AdsManager>();
    
    ads.Configure(new AdsConfiguration(
        androidGameId: "Android game ID",
        iosGameId: "iOS game ID",
        interstitialAdUnitId: "Interstitial_Android",
        rewardedAdUnitId: "Rewarded_Android",
        bannerAdUnitId: "Banner_Android",
        testMode: true));
    
    ads.InitializationFailed += message => Debug.LogError(message);
    
    await ads.Initialize();
    await ads.LoadInterstitialAsync();
    await ads.LoadRewardedAsync();

    如果 Android 和 iOS 使用不同的广告单元 ID,请在各平台启动流程中创建对应的 AdsConfiguration。Configure() 只能在初始化开始前调用。

    插屏和激励广告

    展示前先加载;每次尝试展示全屏广告后都要重新加载。仅当 ShouldGrantReward 为 true 时发放奖励, 跳过或失败的激励广告不得发奖。

    var result = await ads.ShowRewardedAsync();
    
    if (result.ShouldGrantReward)
        GrantCoinsToPlayer();
    else if (!result.IsSuccess)
        Debug.LogWarning(result.Message);
    
    await ads.LoadRewardedAsync();

    横幅广告

    默认 Unity Ads 提供方会将横幅显示在屏幕底部中央。ShowBannerAsync() 成功只表示已向 SDK 发出展示请求, 不代表产生了一次展示。

    await ads.LoadBannerAsync();
    await ads.ShowBannerAsync();
    ads.HideBanner();

    广告中介

    默认提供方是一个轻量 Unity Ads Legacy 集成。若要进行新项目的在线运营和多个广告网络竞价,可使用以下中介:

    选项适用场景AchEngine 接入方式
    Unity LevelPlay以 Unity Ads 为中心的运营及 Unity 当前中介栈将 LevelPlay SDK 封装为 IAdsProvider。
    AppLovin MAX需要高级变现/竞价工具和广泛网络运营实现 MAX Unity SDK 的 IAdsProvider。
    Google AdMob / Google Ad Manager已使用 Google 广告、Firebase 或 GAM 报表封装 AdMob Unity SDK 及当前支持的 Unity Ads 网络适配器。
    Digital Turbine FairBid 等已有该提供方的合同或运营工具使用相同接口封装其 Unity SDK。

    适配器可用性、竞价支持、最低 Android/iOS SDK 和隐私/ATT 要求会频繁变动。接入前请确认所选中介当前的 Unity Ads 适配器和平台要求。

    var ads = AdsManager.Create(new MyLevelPlayAdsProvider());

    IAdsProvider 仅定义初始化、加载/展示和隐藏横幅。适配器必须将回调映射为 AdsLoadResult/AdsShowResult,并且只有激励广告完整结束时才返回 Completed。同一应用会话中不要同时 初始化 Unity Ads Legacy 和 LevelPlay。

    API

    成员说明
    Configure(configuration)在初始化前设置游戏 ID 和广告单元 ID。
    Initialize()使用当前平台游戏 ID 初始化提供方。
    LoadInterstitialAsync() / LoadRewardedAsync() / LoadBannerAsync()加载可展示的广告。
    ShowInterstitialAsync() / ShowRewardedAsync() / ShowBannerAsync()展示已加载广告并返回结果。
    HideBanner()隐藏当前横幅。
    IsLoaded(placement)查询广告位是否可展示。
    AdsShowResult.ShouldGrantReward仅在激励广告完整结束时为 true。