最近接多个聚合的广告sdk,广告回调还是要在项目内进行一些操作,所以参考下MSDK unitypackage的代码,发现继承自AndroidJavaProxy即可实现。
就记录下自定义vivo广告 激励视频回调的代码:
/// <summary>
/// 把java层UnifiedVivoRewardVideoAdListener的结构拿过来
/// </summary>
public interface UnifiedVivoRewardVideoAdListener
{
void onAdReady();
void onAdFailed(int code, string msg);
void onAdClick();
void onAdShow();
void onAdClose();
void onRewardVerify();
}
//具体对应代码就可写到下面的方法
private sealed class RewardVideoAdListener : UnifiedVivoRewardVideoAdListener
{
private VivoAdvSdk example;
public RewardVideoAdListener(VivoAdvSdk example)
{
this.example = example;
}
public void onAdClick(){}
public void onAdClose(){}
public void onAdFailed(int code,string msg){}
public void onAdReady(){}
public void onAdShow(){}
public void onRewardVerify(){}
}
private sealed class RewardVideoAdListenerToAnd : AndroidJavaProxy
{
private readonly UnifiedVivoRewardVideoAdListener listener;
public RewardVideoAdListenerToAnd(UnifiedVivoRewardVideoAdListener listener)
: base("com.vivo.mobilead.unified.reward.UnifiedVivoRewardVideoAdListener")// //"com.bytedance.msdk.api.reward.TTRewardedAdLoadCallback"
{
this.listener = listener;
}
public void onAdReady() {
UnityDispatcher.PostTask(
() => this.listener.onAdReady());
}
public void onAdClick()
{
UnityDispatcher.PostTask(
() => this.listener.onAdClick());
}
public void onAdShow()
{
UnityDispatcher.PostTask(
() => this.listener.onAdShow());
}
public void onAdClose()
{
UnityDispatcher.PostTask(
() => this.listener.onAdClose());
}
public void onRewardVerify()
{
UnityDispatcher.PostTask(
() => this.listener.onRewardVerify());
}
public void onAdFailed(AndroidJavaObject adError)
{
if (adError != null)
{
UnityDispatcher.PostTask(
() => this.listener.onAdFailed(adError.Get<int>("code"), adError.Get<string>("msg")));
}
}
}
//传到java层参数
var rewardAdInteractionListener = new RewardVideoAdListenerToAnd(new RewardVideoAdListener(this));
|