Skip to content

Commit 92014ed

Browse files
author
v_shanxia
committed
fix:广告show报错添加
1 parent 2b7cb16 commit 92014ed

File tree

4 files changed

+64
-12
lines changed

4 files changed

+64
-12
lines changed

Demo/API_V2/Assets/API/Ad/BannerAd/BannerAd.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine;
23
using WeChatWASM;
34

@@ -71,11 +72,21 @@ private void SwitchAdState()
7172
else
7273
{
7374
// 展示广告
74-
_bannerAd.Show();
75-
WX.ShowToast(new ShowToastOption() { title = "已展示广告" });
75+
_bannerAd.Show(ShowSuccess, ShowFail);
7676
}
7777
}
7878

79+
private Action<WXTextResponse> ShowSuccess = (res) =>
80+
{
81+
WX.ShowModal(new ShowModalOption() { content = "BannerAd Show Success:" + JsonUtility.ToJson(res) });
82+
};
83+
84+
85+
private Action<WXTextResponse> ShowFail = (res) =>
86+
{
87+
WX.ShowModal(new ShowModalOption() { content = "BannerAd Show Fail:" + JsonUtility.ToJson(res) });
88+
};
89+
7990
// 销毁广告
8091
private void DestroyAd()
8192
{

Demo/API_V2/Assets/API/Ad/CustomAd/CustomAd.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine;
23
using WeChatWASM;
34

@@ -72,11 +73,21 @@ private void SwitchAdState()
7273
else
7374
{
7475
// 展示广告
75-
_customAd.Show();
76-
WX.ShowToast(new ShowToastOption() { title = "已展示广告" });
76+
_customAd.Show(ShowSuccess, ShowFail);
7777
}
7878
}
7979

80+
private Action<WXTextResponse> ShowSuccess = (res) =>
81+
{
82+
WX.ShowModal(new ShowModalOption() { content = "CustomAd Show Success:" + JsonUtility.ToJson(res) });
83+
};
84+
85+
86+
private Action<WXTextResponse> ShowFail = (res) =>
87+
{
88+
WX.ShowModal(new ShowModalOption() { content = "CustomAd Show Fail:" + JsonUtility.ToJson(res) });
89+
};
90+
8091
// 销毁广告
8192
private void DestroyAd()
8293
{

Demo/API_V2/Assets/API/Ad/InterstitalAd/InterstitalAd.cs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine;
23
using WeChatWASM;
34

@@ -30,7 +31,7 @@ protected override void TestAPI(string[] args)
3031
WX.ShowModal(
3132
new ShowModalOption()
3233
{
33-
content = "RewardedVideoAd OnLoad Result:" + JsonUtility.ToJson(res)
34+
content = "InterstitialAd OnLoad Result:" + JsonUtility.ToJson(res)
3435
}
3536
);
3637
}
@@ -41,14 +42,14 @@ protected override void TestAPI(string[] args)
4142
WX.ShowModal(
4243
new ShowModalOption()
4344
{
44-
content = "RewardedVideoAd onError Result:" + JsonUtility.ToJson(res)
45+
content = "InterstitialAd onError Result:" + JsonUtility.ToJson(res)
4546
}
4647
);
4748
}
4849
);
4950
_interstitialAd.OnClose(() =>
5051
{
51-
WX.ShowModal(new ShowModalOption() { content = "RewardedVideoAd onClose" });
52+
WX.ShowModal(new ShowModalOption() { content = "InterstitialAd onClose" });
5253
});
5354
// 预加载广告
5455
_interstitialAd.Load();
@@ -59,10 +60,21 @@ protected override void TestAPI(string[] args)
5960
// 展示广告
6061
private void ShowAd()
6162
{
62-
_interstitialAd.Show();
63-
WX.ShowToast(new ShowToastOption() { title = "已展示广告" });
63+
_interstitialAd.Show(ShowSuccess, ShowFail);
6464
}
6565

66+
private Action<WXTextResponse> ShowSuccess = (res) =>
67+
{
68+
WX.ShowModal(new ShowModalOption() { content = "InterstitialAd Show Success:" + JsonUtility.ToJson(res) });
69+
};
70+
71+
72+
private Action<WXTextResponse> ShowFail = (res) =>
73+
{
74+
WX.ShowModal(new ShowModalOption() { content = "InterstitialAd Show Fail:" + JsonUtility.ToJson(res) });
75+
};
76+
77+
6678
// 销毁广告
6779
private void DestroyAd()
6880
{

Demo/API_V2/Assets/API/Ad/RewardedVideoAd/RewardedVideoAd.cs

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine;
23
using WeChatWASM;
34

@@ -64,12 +65,29 @@ protected override void TestAPI(string[] args)
6465
}
6566

6667
// 展示广告
67-
private void ShowAd()
68+
// private void ShowAd()
69+
// {
70+
// _rewardedVideoAd.Show();
71+
// WX.ShowToast(new ShowToastOption() { title = "已展示广告" });
72+
// }
73+
74+
75+
private void ShowAd()
6876
{
69-
_rewardedVideoAd.Show();
70-
WX.ShowToast(new ShowToastOption() { title = "已展示广告" });
77+
_rewardedVideoAd.Show(ShowSuccess, ShowFail);
7178
}
7279

80+
private Action<WXTextResponse> ShowSuccess = (res) =>
81+
{
82+
WX.ShowModal(new ShowModalOption() { content = "RewardedVideoAd Show Success:" + JsonUtility.ToJson(res) });
83+
};
84+
85+
86+
private Action<WXTextResponse> ShowFail = (res) =>
87+
{
88+
WX.ShowModal(new ShowModalOption() { content = "RewardedVideoAd Show Fail:" + JsonUtility.ToJson(res) });
89+
};
90+
7391
// 销毁广告
7492
private void DestroyAd()
7593
{

0 commit comments

Comments
 (0)