-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReklamScript.cs
312 lines (241 loc) · 8.69 KB
/
ReklamScript.cs
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
using UnityEngine;
using System.Collections;
using System;
using GoogleMobileAds.Api;
public class ReklamScript : MonoBehaviour
{
private static ReklamScript instance = null;
private GameObject GC;
[Header("Ad Unit ID'ler")]
public string bannerID;
public string interstitialID;
public string rewardedVideoID;
[Header("Test Modu")]
public bool testMod = false;
public string testDeviceID;
[Header("Diğer Ayarlar")]
public bool cocuklaraYonelikReklamGoster = false;
public AdPosition bannerPozisyonu = AdPosition.Top;
private BannerView bannerReklam;
private InterstitialAd interstitialReklam;
private float interstitialIstekTimeoutZamani;
private float rewardedVideoIstekTimeoutZamani;
private IEnumerator interstitialGosterCoroutine;
private IEnumerator rewardedVideoGosterCoroutine;
public delegate void RewardedVideoOdul(Reward odul);
private RewardedVideoOdul odulDelegate;
void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(this);
}
else if (this != instance)
{
Destroy(gameObject);
return;
}
GC=GameObject.FindGameObjectWithTag("GameController");
}
void Start()
{
if (this != instance)
return;
BannerReklamYukle();
InterstitialReklamYukle();
RewardedReklamYukle();
}
void BannerReklamYukle()
{
if (string.IsNullOrEmpty(bannerID))
return;
bannerReklam = new BannerView(bannerID, AdSize.SmartBanner, bannerPozisyonu);
AdRequest reklamiAl = ReklamIstegiOlustur(testMod);
bannerReklam.LoadAd(reklamiAl);
bannerReklam.Hide();
}
void InterstitialReklamYukle()
{
if (string.IsNullOrEmpty(interstitialID))
return;
if (interstitialReklam != null)
interstitialReklam.Destroy();
interstitialReklam = new InterstitialAd(interstitialID);
interstitialReklam.OnAdClosed += InterstitialDelegate;
AdRequest reklamiAl = ReklamIstegiOlustur(testMod);
interstitialReklam.LoadAd(reklamiAl);
interstitialIstekTimeoutZamani = Time.realtimeSinceStartup + 10f;
}
void RewardedReklamYukle()
{
if (string.IsNullOrEmpty(rewardedVideoID))
return;
RewardBasedVideoAd rewardedReklam = RewardBasedVideoAd.Instance;
rewardedReklam.OnAdClosed -= RewardedVideoDelegate;
rewardedReklam.OnAdClosed += RewardedVideoDelegate;
rewardedReklam.OnAdRewarded -= RewardedVideoOdullendir;
rewardedReklam.OnAdRewarded += RewardedVideoOdullendir;
AdRequest reklamiAl = ReklamIstegiOlustur(false);
if (testMod) // test id: https://groups.google.com/d/msg/google-admob-ads-sdk/k-kVwVu2XBc/57YBTdxPBgAJ
rewardedReklam.LoadAd(reklamiAl, "ca-app-pub-6442067588290070/4128212231");
else
rewardedReklam.LoadAd(reklamiAl, rewardedVideoID);
rewardedVideoIstekTimeoutZamani = Time.realtimeSinceStartup + 30f;
}
AdRequest ReklamIstegiOlustur(bool testModu)
{
AdRequest.Builder reklamIstegi = new AdRequest.Builder();
if (testModu)
reklamIstegi.AddTestDevice(AdRequest.TestDeviceSimulator).AddTestDevice(testDeviceID);
if (cocuklaraYonelikReklamGoster)
reklamIstegi.TagForChildDirectedTreatment(true).AddExtra("is_designed_for_families", "true");
return reklamIstegi.Build();
}
void InterstitialDelegate(object sender, EventArgs args)
{
InterstitialReklamYukle();
}
void RewardedVideoDelegate(object sender, EventArgs e)
{
RewardedReklamYukle();
}
void OnGUI()
{
Color c = GUI.color;
//if( GUI.Button( new Rect( Screen.width / 2 - 150, 0, 300, 120 ), "Banner Goster" ) )
// ReklamScript.BannerGoster();
//if( GUI.Button( new Rect( Screen.width / 2 - 150, 120, 300, 120 ), "Banner Gizle" ) )
// ReklamScript.BannerGizle();
//GUI.color = InterstitialHazirMi() ? Color.green : Color.red;
//if( GUI.Button( new Rect( Screen.width / 2 - 150, 240, 300, 120 ), "Interstitial Goster" ) )
// ReklamScript.InsterstitialGoster();
//GUI.color = RewardedReklamHazirMi() ? Color.green : Color.red;
//if( GUI.Button( new Rect( Screen.width / 2 - 150, 360, 300, 120 ), "Rewarded Goster" ) )
//ReklamScript.RewardedReklamGoster( null );
//GUI.color = c;
}
public void reklamgoster()
{
ReklamScript.RewardedReklamGoster(null);
GC.GetComponent<GameController>().altinEkle();
}
public static void BannerGoster() // Banner Gösterceğin Zaman CAğır
{
if (instance == null)
return;
if (instance.bannerReklam == null)
instance.BannerReklamYukle();
instance.bannerReklam.Show();
}
public static void BannerGizle()
{
if (instance == null)
return;
if (instance.bannerReklam == null)
return;
instance.bannerReklam.Hide();
}
public static bool InterstitialHazirMi()
{
if (instance == null)
return false;
if (instance.interstitialReklam == null)
return false;
return instance.interstitialReklam.IsLoaded();
}
public static void InterstitialReklamAl()
{
if (instance == null)
return;
if (instance.interstitialReklam != null && instance.interstitialReklam.IsLoaded())
return;
instance.InterstitialReklamYukle();
}
public static void InsterstitialGoster()
{
if (instance == null)
return;
if (instance.interstitialReklam == null)
instance.InterstitialReklamYukle();
if (instance.interstitialGosterCoroutine != null)
{
instance.StopCoroutine(instance.interstitialGosterCoroutine);
instance.interstitialGosterCoroutine = null;
}
if (instance.interstitialReklam.IsLoaded())
instance.interstitialReklam.Show();
else
{
if (Time.realtimeSinceStartup >= instance.interstitialIstekTimeoutZamani)
instance.InterstitialReklamYukle();
instance.interstitialGosterCoroutine = instance.InsterstitialGosterCoroutine();
instance.StartCoroutine(instance.interstitialGosterCoroutine);
}
}
public static bool RewardedReklamHazirMi()
{
if (instance == null)
return false;
return RewardBasedVideoAd.Instance.IsLoaded();
}
public static void RewardedReklamAl()
{
if (instance == null)
return;
if (RewardBasedVideoAd.Instance.IsLoaded())
return;
instance.RewardedReklamYukle();
}
public static void RewardedReklamGoster(RewardedVideoOdul odulFonksiyonu)
{
if (instance == null)
return;
if (instance.rewardedVideoGosterCoroutine != null)
{
instance.StopCoroutine(instance.rewardedVideoGosterCoroutine);
instance.rewardedVideoGosterCoroutine = null;
}
instance.odulDelegate = odulFonksiyonu;
RewardBasedVideoAd rewardedReklam = RewardBasedVideoAd.Instance;
if (rewardedReklam.IsLoaded())
rewardedReklam.Show();
else
{
if (Time.realtimeSinceStartup >= instance.rewardedVideoIstekTimeoutZamani)
instance.RewardedReklamYukle();
instance.rewardedVideoGosterCoroutine = instance.RewardedVideoGosterCoroutine();
instance.StartCoroutine(instance.rewardedVideoGosterCoroutine);
}
}
IEnumerator InsterstitialGosterCoroutine()
{
float istekTimeoutAni = Time.realtimeSinceStartup + 2.5f;
while (!interstitialReklam.IsLoaded())
{
if (Time.realtimeSinceStartup > istekTimeoutAni)
yield break;
yield return null;
}
interstitialReklam.Show();
}
IEnumerator RewardedVideoGosterCoroutine()
{
RewardBasedVideoAd rewardedReklam = RewardBasedVideoAd.Instance;
float istekTimeoutAni = Time.realtimeSinceStartup + 10f;
while (!rewardedReklam.IsLoaded())
{
if (Time.realtimeSinceStartup > istekTimeoutAni)
yield break;
yield return null;
}
rewardedReklam.Show();
}
void RewardedVideoOdullendir(object sender, Reward odul)
{
if (odulDelegate != null)
odulDelegate(odul);
GameController.playerCoin += 50;
Debug.Log(GameController.playerCoin);
}
}