-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppodealCmpDemo.cs
More file actions
138 lines (114 loc) · 4.61 KB
/
AppodealCmpDemo.cs
File metadata and controls
138 lines (114 loc) · 4.61 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
// ReSharper disable CheckNamespace
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using AppodealStack.Cmp;
using AppodealStack.Monetization.Api;
using AppodealStack.Monetization.Common;
namespace AppodealSample
{
public class AppodealCmpDemo : MonoBehaviour
{
[SerializeField] private Button nextSceneButton;
[SerializeField] private Text pluginVersionText;
#if UNITY_EDITOR && !UNITY_ANDROID && !UNITY_IOS
private const string DefaultAppKey = "";
#elif UNITY_ANDROID
private const string DefaultAppKey = "fee50c333ff3825fd6ad6d38cff78154de3025546d47a84f";
#elif UNITY_IOS
private const string DefaultAppKey = "466de0d625e01e8811c588588a42a55970bc7c132649eede";
#else
private const string DefaultAppKey = "";
#endif
private static string AppKey => PlayerPrefs.GetString(AppodealConstants.AppKeyPlayerPrefsKey, DefaultAppKey);
private ConsentForm _consentForm;
private void Awake()
{
Assert.IsNotNull(nextSceneButton);
Assert.IsNotNull(pluginVersionText);
}
private void Start()
{
nextSceneButton.interactable = GetSceneInfo().hasNext;
pluginVersionText.text = $"Appodeal Unity Plugin v{AppodealVersions.GetPluginVersion()}";
ConsentManager.Instance.OnConsentFormDismissed += (_, args) =>
{
string message = "[Appodeal CMP] OnConsentFormDismissed event triggered.";
if (args.Error != null) message += $" Error: {args.Error}";
Debug.Log(message);
_consentForm = null;
};
ConsentManager.Instance.OnConsentFormLoadFailed += (_, args) =>
{
Debug.Log($"[Appodeal CMP] OnConsentFormLoadFailed event triggered. Cause: {args.Cause}");
};
ConsentManager.Instance.OnConsentFormLoadSucceeded += (_, args) =>
{
Debug.Log("[Appodeal CMP] OnConsentFormLoadSucceeded event triggered.");
_consentForm = args.ConsentForm;
};
ConsentManager.Instance.OnConsentInfoUpdateFailed += (_, args) =>
{
Debug.Log($"[Appodeal CMP] OnConsentInfoUpdateFailed event triggered. Cause: {args.Cause}");
};
ConsentManager.Instance.OnConsentInfoUpdateSucceeded += (_, _) =>
{
Debug.Log("[Appodeal CMP] OnConsentInfoUpdateSucceeded event triggered.");
};
}
public void ShowNextScene()
{
var sceneInfo = GetSceneInfo();
if (sceneInfo.hasNext)
{
SceneManager.LoadScene(sceneInfo.nextIndex);
}
}
public void RequestConsentInfoUpdate()
{
Debug.Log("[Appodeal CMP] RequestInfoUpdate() method called");
var parameters = new ConsentInfoParameters
{
AppKey = AppKey,
IsUnderAgeToConsent = false,
Sdk = "Appodeal",
SdkVersion = Appodeal.GetNativeSDKVersion()
};
Debug.Log($"[Appodeal CMP] init params: {parameters.ToJsonString()}");
ConsentManager.Instance.RequestConsentInfoUpdate(parameters);
}
public void GetConsentStatus()
{
var status = ConsentManager.Instance.ConsentStatus;
Debug.Log($"[Appodeal CMP] GetConsentStatus() method called, status: {status}");
}
public void LoadConsentForm()
{
Debug.Log("[Appodeal CMP] LoadConsentForm() method called");
ConsentManager.Instance.Load();
}
public void ShowConsentForm()
{
Debug.Log("[Appodeal CMP] ShowConsentForm() method called");
_consentForm?.Show();
}
public void LoadAndShowConsentForm()
{
Debug.Log("[Appodeal CMP] LoadAndShowConsentForm() method called");
ConsentManager.Instance.LoadAndShowConsentFormIfRequired();
}
public void RevokeConsent()
{
Debug.Log("[Appodeal CMP] RevokeConsent() method called");
ConsentManager.Instance.Revoke();
}
private static (int currentIndex, int nextIndex, bool hasNext) GetSceneInfo()
{
int currentIndex = SceneManager.GetActiveScene().buildIndex;
int nextIndex = currentIndex + 1;
bool hasNext = nextIndex < SceneManager.sceneCountInBuildSettings;
return (currentIndex, nextIndex, hasNext);
}
}
}