本演示项目在Unity for Android Build中启用部分华为HMS和AGC服务,对应的类和函数的名称和用法相同。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

55 行
2.2 KiB

using UnityEngine;
using HuaweiHms;
namespace HuaweiHmsDemo
{
public class AdsTest:Test<AdsTest>
{
public override void RegisterEvent(TestEvent registerEvent){
registerEvent("load image ads " + Screen.width,LoadImageAds);
registerEvent("load video ads " + Screen.height,LoadVideoAds);
registerEvent("load reward ads",LoadRewardAds);
registerEvent("set consent personal",() => SetConsentStatus(true));
registerEvent("set consent non personal", ()=> SetConsentStatus(false));
registerEvent("consent",checkConsentStatus);
}
public void LoadImageAds()
{
InterstitialAd ad = new InterstitialAd(new Context());
ad.setAdId("teste9ih9j0rc3");
ad.setAdListener(new MAdListener(ad));
AdParam.Builder builder = new AdParam.Builder();
AdParam adParam = builder.build();
ad.loadAd(adParam);
}
public void LoadVideoAds()
{
InterstitialAd ad = new InterstitialAd(new Context());
ad.setAdId("testb4znbuh3n2");
ad.setAdListener(new MAdListener(ad));
AdParam.Builder builder = new AdParam.Builder();
ad.loadAd(builder.build());
}
public void LoadRewardAds()
{
RewardAd ad = new RewardAd(new Context(), "testx9dtjwj8hp");
AdParam adParam = new AdParam.Builder().build();
MRewardLoadListener rewardAdLoadListener = new MRewardLoadListener(ad);
ad.loadAd(adParam, rewardAdLoadListener);
}
public void SetConsentStatus(bool personal)
{
Consent consentInfo = Consent.getInstance(new Context());
var consentStatus = personal ? ConsentStatus.PERSONALIZED : ConsentStatus.NON_PERSONALIZED;
consentInfo.setConsentStatus(consentStatus);
Util.showToast($"set consent status as {consentStatus}");
}
public void checkConsentStatus()
{
Consent consentInfo = Consent.getInstance(new Context());
consentInfo.requestConsentUpdate(new MConsentUpdateListener());
}
}
}