Copy using SFBX.AppConsent;
using UnityEngine;
using System.Collections;
public class AppConsentGUI : MonoBehaviour, ISDKCallbackListener, ISDKPresentNoticeListener
{
ACNotice bridge = null;
private bool isCmpInitialized = false;
int centerX = Screen.width / 2;
int buttonWidth = Screen.width / 2;
int buttonHeight = Screen.height / 14;
int buttonX;
GUIStyle labelStyle = new GUIStyle();
GUIStyle buttonStyle;
string status = "";
int logIndice = 0;
void Awake()
{
AndroidJNIHelper.debug = true;
// Only for Android - does not impact iOS !
ACNotice.SetNoticeCallback(this);
bridge = new ACNotice("18ecaea4-554a-4f74-9242-520fe62058a8");
UpdateStatus("bridge instanciated => " + bridge);
}
// Start is called before the first frame update
void Start()
{
labelStyle.alignment = TextAnchor.MiddleCenter;
labelStyle.normal.textColor = Color.white;
buttonX = centerX - ( buttonWidth / 2);
bridge.InitACNotice();
#if UNITY_IOS || UNITY_TVOS
// On iOS, there's no need for a callback, so you can directly change the boolean's state.
OnReadyOnSuccess();
#endif
}
// Update is called once per frame
void Update()
{
centerX = Screen.width / 2;
buttonWidth = Screen.width / 2;
buttonHeight = Screen.height / 14;
buttonX = centerX - ( buttonWidth / 2);
}
void OnGUI()
{
labelStyle.fontSize = 28;
labelStyle.wordWrap = true;
buttonStyle = new GUIStyle(GUI.skin.button);
buttonStyle.fontSize = 28;
GUI.Label(new Rect(buttonX, buttonHeight * 2, buttonWidth, buttonHeight), "SFBX AppConsent", labelStyle);
if (GUI.Button(new Rect(buttonX, buttonHeight * 4, buttonWidth, buttonHeight), "Display CMP", buttonStyle))
{
if(isCmpInitialized == true && bridge != null){
bridge.SetPresentNoticeListener(this);
bool isDisplayed = bridge.ShowNotice();
if(isDisplayed == true){
UpdateStatus("Notice displayed");
}else{
UpdateStatus("Notice not displayed, look at your consent or RGPD country.");
}
}else{
UpdateStatus("AppConsent not ready yet");
}
}
if (GUI.Button(new Rect(buttonX, buttonHeight * 6, buttonWidth, buttonHeight), "Settings", buttonStyle))
{
if(isCmpInitialized == true && bridge != null){
bridge.ShowSettings();
UpdateStatus("Settings displayed");
}else{
UpdateStatus("AppConsent not ready yet");
}
}
if (GUI.Button(new Rect(buttonX, buttonHeight * 8, buttonWidth, buttonHeight), "Check Consents", buttonStyle))
{
if(isCmpInitialized == true && bridge != null){
bool consent = bridge.ConsentGiven();
bool allConsentables = bridge.AllConsentablesAllowed();
bool gdpr = bridge.IsSubjectToGDPR();
bool acceptAll = bridge.UserAcceptAll();
bool extra = bridge.ExtraVendorAllowed("TobuM9Iw");
bool consentable = bridge.ConsentableAllowed(1,0);
UpdateStatus("consents: " + consent + allConsentables + gdpr + acceptAll + extra + consentable);
}else{
UpdateStatus("AppConsent not ready yet");
}
}
if (GUI.Button(new Rect(buttonX, buttonHeight * 10, buttonWidth, buttonHeight), "Reset Consents", buttonStyle))
{
if(isCmpInitialized == true && bridge != null){
bridge.ClearConsents();
UpdateStatus("Cleared consents");
}else{
UpdateStatus("AppConsent not ready yet");
}
}
GUI.Label(new Rect(0, buttonHeight * 12, Screen.width, buttonHeight), status, labelStyle);
}
public void OnReadyOnSuccess()
{
UpdateStatus("Appconsent onReadyOnSuccess");
isCmpInitialized = true;
Debug.Log("AppConsent is ready to be use !");
UpdateStatus("Setting listener + trying to show notice");
bridge.SetPresentNoticeListener(this);
bool isDisplayed = bridge.ShowNotice();
if(isDisplayed == true){
UpdateStatus("Notice displayed");
}else{
UpdateStatus("Notice not displayed, look at your consent or RGPD country.");
}
}
public void OnReadyOnError(AndroidJavaObject err)
{
isCmpInitialized = false;
Debug.LogError("Failed to start AppConsent");
}
public void OnConsentGiven()
{
Debug.Log("The user has given his consent");
UpdateStatus("Consent given !");
}
public void OnConsentGivenError(AndroidJavaObject err)
{
Debug.LogError("An error as occurred, please read Log.");
UpdateStatus("An error as occurred, please read Log.");
}
private void UpdateStatus(string log){
if(logIndice % 10 == 0){
status = logIndice++ + " - " + log;
}else{
status = status + "\n" + logIndice++ + " - " + log;
}
}
}