-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdManager.cs
117 lines (102 loc) · 3.82 KB
/
AdManager.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
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Advertisements;
public class AdManager : MonoBehaviour , IUnityAdsListener
{
private string playStoreID = "3604661";
private string appStoreID = "3604660";
private string intersitialAd = "video";
private string rewardedVideoAd = "rewardedVideo";
public bool isTargetPlayStore;
public bool isTestAd;
private void Start()
{
Advertisement.AddListener(this);
InitializeAdvertisement();
}
private void InitializeAdvertisement()
{
if(isTargetPlayStore)
{
Advertisement.Initialize(playStoreID , isTestAd);
return;
}
Advertisement.Initialize(appStoreID, isTestAd);
}
public void PlayIntersitialAd()
{
if( !Advertisement.IsReady(intersitialAd))
{
return;
}
Advertisement.Show(intersitialAd);
}
public void PlayRewardedVideoAd()
{
if(!Advertisement.IsReady(rewardedVideoAd))
{
return;
}
Advertisement.Show(rewardedVideoAd);
}
public void OnUnityAdsReady(string placementId)
{
//throw new System.NotImplementedException();
}
public void OnUnityAdsDidError(string message)
{
//throw new System.NotImplementedException();
}
public void OnUnityAdsDidStart(string placementId)
{
FindObjectOfType<AudioManager>().Pause("GameMusic");
}
public void OnUnityAdsDidFinish(string placementId, ShowResult showResult)
{
switch (showResult)
{
case ShowResult.Failed:
if (PlayerPrefs.GetInt("MusicEnabled", 1) == 1)
FindObjectOfType<AudioManager>().Play("GameMusic");
break;
case ShowResult.Skipped:
if (PlayerPrefs.GetInt("MusicEnabled", 1) == 1)
FindObjectOfType<AudioManager>().Play("GameMusic");
break;
case ShowResult.Finished:
if( placementId == rewardedVideoAd)
{
if( PlayerPrefs.GetInt("isChallange" , 0) == 0)
{
GameObject crush = GameObject.FindGameObjectWithTag("CrushClosingAnim");
if (crush != null)
{
crush.GetComponentInChildren<Button>().interactable = false;
}
GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>().ContinueMainLevel();
GameObject.FindGameObjectWithTag("Enemy").GetComponent<EnemyWaveController>().ContinueMainLevel();
}
else
{
GameObject crush = GameObject.FindGameObjectWithTag("CrushClosingAnim");
if( crush != null)
{
crush.GetComponentInChildren<Button>().interactable = false;
}
GameObject time = GameObject.FindGameObjectWithTag("TimeClosingAnim");
if (time != null)
{
time.GetComponentInChildren<Button>().interactable = false;
}
GameObject.FindGameObjectWithTag("GameManager").GetComponent<GameManager>().ContinueMainLevel();
}
}
else if(placementId == intersitialAd)
{
if (PlayerPrefs.GetInt("MusicEnabled", 1) == 1)
FindObjectOfType<AudioManager>().Play("GameMusic");
}
break;
}
}
}