Skip to content

Commit a58188f

Browse files
authored
Merge pull request #989 from xiashanabc/fix-xiashan-adShow
fix: 广告show报错添加
2 parents fe0bf46 + f57f772 commit a58188f

File tree

4 files changed

+57
-13
lines changed

4 files changed

+57
-13
lines changed

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

Lines changed: 13 additions & 2 deletions
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

Lines changed: 13 additions & 2 deletions
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

Lines changed: 17 additions & 5 deletions
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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using UnityEngine;
23
using WeChatWASM;
34

@@ -63,13 +64,22 @@ protected override void TestAPI(string[] args)
6364
WX.ShowToast(new ShowToastOption() { title = "已创建并加载广告" });
6465
}
6566

66-
// 展示广告
67-
private void ShowAd()
67+
private void ShowAd()
6868
{
69-
_rewardedVideoAd.Show();
70-
WX.ShowToast(new ShowToastOption() { title = "已展示广告" });
69+
_rewardedVideoAd.Show(ShowSuccess, ShowFail);
7170
}
7271

72+
private Action<WXTextResponse> ShowSuccess = (res) =>
73+
{
74+
WX.ShowModal(new ShowModalOption() { content = "RewardedVideoAd Show Success:" + JsonUtility.ToJson(res) });
75+
};
76+
77+
78+
private Action<WXTextResponse> ShowFail = (res) =>
79+
{
80+
WX.ShowModal(new ShowModalOption() { content = "RewardedVideoAd Show Fail:" + JsonUtility.ToJson(res) });
81+
};
82+
7383
// 销毁广告
7484
private void DestroyAd()
7585
{

0 commit comments

Comments
 (0)