Unity 2020.3.15f2 更新后出现问题 Unity Ads 是适用于 iOS 和 Android 4.0.1 的视频广告网络

Unity 2020.3.15f2 problem after updating Unity Ads is a video ad network for iOS and Android 4.0.1

提问人:David B. 提问时间:10/31/2023 更新时间:10/31/2023 访问量:24

问:

这是我项目中的问题所在:

using UnityEngine;
using System.Collections;
using UnityEngine.Advertisements;

public enum WatchAdResult { Finished, Failed, Skipped}
public class UnityAds : MonoBehaviour
{
    //delegate   ()
    public delegate void RewardedAdResult(WatchAdResult result);

    //event  
    public static event RewardedAdResult AdResult;

    public static UnityAds Instance;

    [Header("UNITY AD SETUP")]
    public string UNITY_ANDROID_ID = "1486550";
    public string UNITY_IOS_ID = "1486551";
    public bool isTestMode = true;

    private void Awake()
    {
        if (UnityAds.Instance != null)
        {
            Destroy(gameObject);
            return; 
        }
        else
        {
            Instance = this;
            DontDestroyOnLoad(gameObject);
        }
    }

    void Start()
    {
        string gameId = "";
#if UNITY_IOS
        gameId = UNITY_IOS_ID;
#elif UNITY_ANDROID
        gameId = UNITY_ANDROID_ID;
#endif
        if (Advertisement.isSupported)
        {
            Advertisement.Initialize(gameId, isTestMode);
        }
    }



    #region NORMAL AD
    public void ShowNormalAd()
    {
        if (Advertisement.IsReady())
        {
            Advertisement.Show();
        }
    }

    public bool ForceShowNormalAd()
    {
        if (Advertisement.IsReady())
        {
            Advertisement.Show();
            return true;
        }
        else
            return false;
    }

    #endregion

    #region REWARD AD
    public bool isRewardedAdReady()
    {
        return Advertisement.IsReady("rewardedVideo");
    }

    public void ShowRewardVideo()
    {
        ShowRewardedAd();
    }

    private void ShowRewardedAd()
    {
        if (!allowWatch)
            return;

        if (Advertisement.IsReady("rewardedVideo"))
        {
                var options = new ShowOptions { resultCallback = HandleShowResult };
                if (!Advertisement.isShowing)
                    Advertisement.Show("rewardedVideo", options);

                allowWatch = false;
            
        }
    }

    bool allowWatch = true;
    private void HandleShowResult(ShowResult result)
    {
        switch (result)
        {
            case ShowResult.Finished:
                Debug.Log("The ad was successfully shown.");
                AdResult(WatchAdResult.Finished);
                ; break;
            case ShowResult.Skipped:
                Debug.Log("The ad was skipped before reaching the end.");
                AdResult(WatchAdResult.Skipped);
                break;
            case ShowResult.Failed:
                Debug.LogError("The ad failed to be shown.");
                AdResult(WatchAdResult.Failed);
                break;
        }

        allowWatch = true;
    }
    #endregion
}

更新后遇到的错误:

  1. UnityAds.cs(54,27):错误 CS0117:“播发”不包含“IsReady”的定义
  2. UnityAds.cs(56,27):错误 CS1501:方法“Show”没有重载接受 0 个参数
  3. UnityAds.cs(62,27):错误 CS0117:“播发”不包含“IsReady”的定义
  4. UnityAds.cs(64,27):错误 CS1501:方法“Show”没有重载,占用 0 个参数
  5. UnityAds.cs(76,30):错误 CS0117:“播发”不包含“IsReady”的定义
  6. UnityAds.cs(89,27):错误 CS0117:“播发”不包含“IsReady”的定义
  7. UnityAds.cs(91,49):错误 CS0117:“ShowOptions”不包含“resultCallback”的定义

我希望能够更新到Unity中“Advertisement Legacy”(4.4.2)的最新SDK,但不确定这是否会导致更多的问题

在我从 3.7.5 更新到 4.0.1 之前,一切都运行良好,因为 Google Play 商店删除了我的应用程序,从那以后我一直在试图弄清楚。

Android iOS Unity-游戏引擎 广告

评论

0赞 Retired Ninja 10/31/2023
您必须阅读一些文档并调整代码。docs.unity.com/ads/en-us/manual/DeprecatedAPIClasses

答: 暂无答案