-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadsManager
More file actions
214 lines (189 loc) · 7.58 KB
/
adsManager
File metadata and controls
214 lines (189 loc) · 7.58 KB
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class adsManager : MonoBehaviour
{
#if UNITY_ANDROID
string appKey = "85460dcd";
#elif UNITY_IPHONE
string appKey = "8545d445";
#else
string appKey = "unexpected_platform";
#endif
public TextMeshProUGUI totalCoinsTxt;
private void Start()
{
totalCoinsTxt.text = PlayerPrefs.GetInt("totalCoins").ToString();
IronSource.Agent.validateIntegration();
IronSource.Agent.init(appKey);
}
private void OnEnable()
{
IronSourceEvents.onSdkInitializationCompletedEvent += SdkInitialized;
//Add AdInfo Banner Events
IronSourceBannerEvents.onAdLoadedEvent += BannerOnAdLoadedEvent;
IronSourceBannerEvents.onAdLoadFailedEvent += BannerOnAdLoadFailedEvent;
IronSourceBannerEvents.onAdClickedEvent += BannerOnAdClickedEvent;
IronSourceBannerEvents.onAdScreenPresentedEvent += BannerOnAdScreenPresentedEvent;
IronSourceBannerEvents.onAdScreenDismissedEvent += BannerOnAdScreenDismissedEvent;
IronSourceBannerEvents.onAdLeftApplicationEvent += BannerOnAdLeftApplicationEvent;
//Add AdInfo Interstitial Events
IronSourceInterstitialEvents.onAdReadyEvent += InterstitialOnAdReadyEvent;
IronSourceInterstitialEvents.onAdLoadFailedEvent += InterstitialOnAdLoadFailed;
IronSourceInterstitialEvents.onAdOpenedEvent += InterstitialOnAdOpenedEvent;
IronSourceInterstitialEvents.onAdClickedEvent += InterstitialOnAdClickedEvent;
IronSourceInterstitialEvents.onAdShowSucceededEvent += InterstitialOnAdShowSucceededEvent;
IronSourceInterstitialEvents.onAdShowFailedEvent += InterstitialOnAdShowFailedEvent;
IronSourceInterstitialEvents.onAdClosedEvent += InterstitialOnAdClosedEvent;
//Add AdInfo Rewarded Video Events
IronSourceRewardedVideoEvents.onAdOpenedEvent += RewardedVideoOnAdOpenedEvent;
IronSourceRewardedVideoEvents.onAdClosedEvent += RewardedVideoOnAdClosedEvent;
IronSourceRewardedVideoEvents.onAdAvailableEvent += RewardedVideoOnAdAvailable;
IronSourceRewardedVideoEvents.onAdUnavailableEvent += RewardedVideoOnAdUnavailable;
IronSourceRewardedVideoEvents.onAdShowFailedEvent += RewardedVideoOnAdShowFailedEvent;
IronSourceRewardedVideoEvents.onAdRewardedEvent += RewardedVideoOnAdRewardedEvent;
IronSourceRewardedVideoEvents.onAdClickedEvent += RewardedVideoOnAdClickedEvent;
}
void SdkInitialized() {
print("Sdk in initialized!!");
}
void OnApplicationPause(bool isPaused)
{
IronSource.Agent.onApplicationPause(isPaused);
}
#region banner
public void LoadBanner() {
IronSource.Agent.loadBanner(IronSourceBannerSize.BANNER, IronSourceBannerPosition.BOTTOM);
}
public void DestroyBanner() {
IronSource.Agent.destroyBanner();
}
/************* Banner AdInfo Delegates *************/
//Invoked once the banner has loaded
void BannerOnAdLoadedEvent(IronSourceAdInfo adInfo)
{
}
//Invoked when the banner loading process has failed.
void BannerOnAdLoadFailedEvent(IronSourceError ironSourceError)
{
}
// Invoked when end user clicks on the banner ad
void BannerOnAdClickedEvent(IronSourceAdInfo adInfo)
{
}
//Notifies the presentation of a full screen content following user click
void BannerOnAdScreenPresentedEvent(IronSourceAdInfo adInfo)
{
}
//Notifies the presented screen has been dismissed
void BannerOnAdScreenDismissedEvent(IronSourceAdInfo adInfo)
{
}
//Invoked when the user leaves the app
void BannerOnAdLeftApplicationEvent(IronSourceAdInfo adInfo)
{
}
#endregion
#region interstitial
public void LoadInterstitial() {
IronSource.Agent.loadInterstitial();
}
public void ShowInterstitial() {
if (IronSource.Agent.isInterstitialReady())
{
IronSource.Agent.showInterstitial();
}
else
{
Debug.Log("interstitial not ready!!");
}
}
/************* Interstitial AdInfo Delegates *************/
// Invoked when the interstitial ad was loaded succesfully.
void InterstitialOnAdReadyEvent(IronSourceAdInfo adInfo)
{
}
// Invoked when the initialization process has failed.
void InterstitialOnAdLoadFailed(IronSourceError ironSourceError)
{
}
// Invoked when the Interstitial Ad Unit has opened. This is the impression indication.
void InterstitialOnAdOpenedEvent(IronSourceAdInfo adInfo)
{
}
// Invoked when end user clicked on the interstitial ad
void InterstitialOnAdClickedEvent(IronSourceAdInfo adInfo)
{
}
// Invoked when the ad failed to show.
void InterstitialOnAdShowFailedEvent(IronSourceError ironSourceError, IronSourceAdInfo adInfo)
{
}
// Invoked when the interstitial ad closed and the user went back to the application screen.
void InterstitialOnAdClosedEvent(IronSourceAdInfo adInfo)
{
}
// Invoked before the interstitial ad was opened, and before the InterstitialOnAdOpenedEvent is reported.
// This callback is not supported by all networks, and we recommend using it only if
// it's supported by all networks you included in your build.
void InterstitialOnAdShowSucceededEvent(IronSourceAdInfo adInfo)
{
}
#endregion
#region rewarded
public void LoadRewarded() {
IronSource.Agent.loadRewardedVideo();
}
public void ShowRewarded() {
if (IronSource.Agent.isRewardedVideoAvailable())
{
IronSource.Agent.showRewardedVideo();
}
else
{
Debug.Log("rewarded not ready!!");
}
}
/************* RewardedVideo AdInfo Delegates *************/
// Indicates that there’s an available ad.
// The adInfo object includes information about the ad that was loaded successfully
// This replaces the RewardedVideoAvailabilityChangedEvent(true) event
void RewardedVideoOnAdAvailable(IronSourceAdInfo adInfo)
{
}
// Indicates that no ads are available to be displayed
// This replaces the RewardedVideoAvailabilityChangedEvent(false) event
void RewardedVideoOnAdUnavailable()
{
}
// The Rewarded Video ad view has opened. Your activity will loose focus.
void RewardedVideoOnAdOpenedEvent(IronSourceAdInfo adInfo)
{
}
// The Rewarded Video ad view is about to be closed. Your activity will regain its focus.
void RewardedVideoOnAdClosedEvent(IronSourceAdInfo adInfo)
{
}
// The user completed to watch the video, and should be rewarded.
// The placement parameter will include the reward data.
// When using server-to-server callbacks, you may ignore this event and wait for the ironSource server callback.
void RewardedVideoOnAdRewardedEvent(IronSourcePlacement placement, IronSourceAdInfo adInfo)
{
int crrCoin = PlayerPrefs.GetInt("totalCoins");
crrCoin += 100;
PlayerPrefs.SetInt("totalCoins", crrCoin);
totalCoinsTxt.text = PlayerPrefs.GetInt("totalCoins").ToString();
}
// The rewarded video ad was failed to show.
void RewardedVideoOnAdShowFailedEvent(IronSourceError error, IronSourceAdInfo adInfo)
{
}
// Invoked when the video ad was clicked.
// This callback is not supported by all networks, and we recommend using it only if
// it’s supported by all networks you included in your build.
void RewardedVideoOnAdClickedEvent(IronSourcePlacement placement, IronSourceAdInfo adInfo)
{
}
#endregion
}