using System using UnityEngine using UnityEngine Events summary Manage

  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
using System;
using UnityEngine;
using UnityEngine.Events;
/// <summary>
/// Manages the GDPR consent state and dialog.
/// </summary>
public class MoPubConsent : MonoBehaviour
{
public const string DefaultLocationAwarenessUsage = "Your location is used to provide more targeted advertising.";
[Tooltip("If set to true, this script will handle loading and showing the GDPR consent dialog automatically.")]
public bool AutoShowConsentDialog;
[Tooltip("(iOS Only) Indicate the reason that your app needs to be location aware. Required for App Store acceptance.")]
public string LocationAwarenessUsage;
// Need these declarations for the events to appear in the inspector.
[Serializable] public class ConsentStatusChangedEvent : UnityEvent<MoPub.Consent.Status, MoPub.Consent.Status, bool> { }
[Serializable] public class ConsentDialogLoadedEvent : UnityEvent { }
[Serializable] public class ConsentDialogFailedEvent : UnityEvent<string> { }
[Serializable] public class ConsentDialogShownEvent : UnityEvent { }
[Serializable] public class ConsentDialogDismissedEvent : UnityEvent { }
[Header("Callbacks")]
public ConsentStatusChangedEvent ConsentStatusChanged;
public ConsentDialogLoadedEvent ConsentDialogLoaded;
public ConsentDialogFailedEvent ConsentDialogFailed;
public ConsentDialogShownEvent ConsentDialogShown;
public ConsentDialogDismissedEvent ConsentDialogDismissed;
void Reset()
{
LocationAwarenessUsage = DefaultLocationAwarenessUsage;
}
public static string LocationAwarenessUsageDescription
{
get {
if (MoPubManager.Instance != null) {
var consent = MoPubManager.Instance.GetComponent<MoPubConsent>();
if (consent != null) {
var usage = consent.LocationAwarenessUsage;
if (!string.IsNullOrEmpty(usage))
return usage;
}
}
return DefaultLocationAwarenessUsage;
}
}
public static bool? IsGdprApplicable
{
get { return MoPub.IsGdprApplicable; }
}
public static MoPub.Consent.Status CurrentConsentStatus
{
get { return MoPub.CurrentConsentStatus; }
}
public static bool CanCollectPersonalInfo
{
get { return MoPub.CanCollectPersonalInfo; }
}
public static bool ShouldShowConsentDialog
{
get { return MoPub.ShouldShowConsentDialog; }
}
public static bool IsConsentDialogReady
{
get { return MoPub.IsConsentDialogReady; }
}
public static void LoadConsentDialog()
{
MoPub.LoadConsentDialog();
}
public static void ShowConsentDialog()
{
MoPub.ShowConsentDialog();
}
// Forward from the C# events to the unity events.
private void fwdConsentStatusChanged(MoPub.Consent.Status oldConsent, MoPub.Consent.Status newConsent,
bool canCollectPersonalInfo)
{
if (ConsentStatusChanged != null)
ConsentStatusChanged.Invoke(oldConsent, newConsent, canCollectPersonalInfo);
ShowConsentDialogIfNeeded();
}
private void fwdConsentDialogLoaded()
{
if (ConsentDialogLoaded != null)
ConsentDialogLoaded.Invoke();
ShowConsentDialogIfNeeded();
}
private void fwdConsentDialogFailed(string error)
{
if (ConsentDialogFailed != null)
ConsentDialogFailed.Invoke("Consent dialog failed to load: " + error);
}
private void fwdConsentDialogShown()
{
if (ConsentDialogShown != null)
ConsentDialogShown.Invoke();
}
private void fwdConsentDialogDismissed()
{
if (ConsentDialogDismissed != null)
ConsentDialogDismissed.Invoke();
}
private void OnSdkInitialized(string adUnitId)
{
ShowConsentDialogIfNeeded();
}
private void ShowConsentDialogIfNeeded()
{
if (!AutoShowConsentDialog || !ShouldShowConsentDialog) return;
if (IsConsentDialogReady)
ShowConsentDialog();
else
LoadConsentDialog();
}
void OnEnable()
{
MoPubManager.OnConsentStatusChangedEvent += fwdConsentStatusChanged;
MoPubManager.OnConsentDialogLoadedEvent += fwdConsentDialogLoaded;
MoPubManager.OnConsentDialogFailedEvent += fwdConsentDialogFailed;
MoPubManager.OnConsentDialogShownEvent += fwdConsentDialogShown;
MoPubManager.OnConsentDialogDismissedEvent += fwdConsentDialogDismissed;
MoPubManager.OnSdkInitializedEvent += OnSdkInitialized;
if (MoPubManager.Instance != null && MoPub.IsSdkInitialized)
ShowConsentDialogIfNeeded();
}
// Required to get enablement checkbox in the inspector
void Start() { }
void OnDisable()
{
MoPubManager.OnConsentStatusChangedEvent -= fwdConsentStatusChanged;
MoPubManager.OnConsentDialogLoadedEvent -= fwdConsentDialogLoaded;
MoPubManager.OnConsentDialogFailedEvent -= fwdConsentDialogFailed;
MoPubManager.OnConsentDialogShownEvent -= fwdConsentDialogShown;
MoPubManager.OnConsentDialogDismissedEvent -= fwdConsentDialogDismissed;
MoPubManager.OnSdkInitializedEvent -= OnSdkInitialized;
}
}