blob: 92ab04027429109017ad3aec0a7849079189fb9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
using System;
using System.Collections;
using GoogleMobileAds.Api;
using InnerNet;
using UnityEngine;
public static class AdPlayer
{
private static InterstitialAd interstitial;
private const string appId = "unexpected_platform";
private const string adUnitId = "unexpected_platform";
public static void ShowInterstitial(MonoBehaviour parent, bool playAgain)
{
parent.StartCoroutine(AdPlayer.CoShowAd(playAgain));
}
private static IEnumerator CoShowAd(bool playAgain)
{
if (playAgain)
{
yield return DestroyableSingleton<EndGameManager>.Instance.CoJoinGame();
}
else
{
AmongUsClient.Instance.ExitGame(DisconnectReasons.ExitGame);
}
yield break;
}
public static void RequestInterstitial()
{
try
{
MobileAds.Initialize("unexpected_platform");
if (AdPlayer.interstitial == null)
{
AdPlayer.interstitial = new InterstitialAd("unexpected_platform");
AdRequest adRequest = new AdRequest.Builder().Build();
if (SaveManager.ShowAdsScreen.HasFlag(ShowAdsState.NonPersonalized))
{
adRequest.Extras.Add("npa", "1");
}
AdPlayer.interstitial.OnAdLoaded += AdPlayer.Interstitial_OnAdLoaded;
AdPlayer.interstitial.OnAdFailedToLoad += AdPlayer.Interstitial_OnAdFailedToLoad;
AdPlayer.interstitial.OnAdClosed += AdPlayer.Interstitial_OnAdClosed;
AdPlayer.interstitial.OnAdLeavingApplication += AdPlayer.Interstitial_OnAdLeavingApplication;
AdPlayer.interstitial.LoadAd(adRequest);
}
}
catch
{
try
{
if (AdPlayer.interstitial != null)
{
AdPlayer.interstitial.Destroy();
}
}
catch
{
}
AdPlayer.interstitial = null;
}
}
private static void Interstitial_OnAdLoaded(object sender, EventArgs e)
{
}
private static void Interstitial_OnAdLeavingApplication(object sender, EventArgs e)
{
try
{
if (AdPlayer.interstitial != null)
{
AdPlayer.interstitial.Destroy();
}
}
finally
{
AdPlayer.interstitial = null;
}
}
private static void Interstitial_OnAdFailedToLoad(object sender, AdFailedToLoadEventArgs e)
{
try
{
if (AdPlayer.interstitial != null)
{
AdPlayer.interstitial.Destroy();
Debug.LogError("Couldn't load ad: " + (e.Message ?? "No Message"));
}
}
finally
{
AdPlayer.interstitial = null;
}
}
private static void Interstitial_OnAdClosed(object sender, EventArgs e)
{
try
{
if (AdPlayer.interstitial != null)
{
AdPlayer.interstitial.Destroy();
}
}
finally
{
AdPlayer.interstitial = null;
}
}
}
|