123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using GoogleMobileAds.Ump.Api;
- using UnityEngine;
- using UnityEngine.UI;
- namespace James.Base
- {
- public static class ConsentManager
- {
- public static bool CanRequestAds => ConsentInformation.CanRequestAds();
- public static bool CanShowPrivacyButton => ConsentInformation.PrivacyOptionsRequirementStatus ==
- PrivacyOptionsRequirementStatus.Required;
- // private static Button _privacyButton;
- // public static Button PrivacyButton
- // {
- // set
- // {
- // _privacyButton = value;
- // UpdatePrivacyButton();
- // }
- // }
- public static void GatherConsent(Action<string> onComplete)
- {
- // Debug.Log("Gathering consent.");
- var requestParameters = new ConsentRequestParameters
- {
- // False means users are not under age.
- TagForUnderAgeOfConsent = false,
- // ConsentDebugSettings = new ConsentDebugSettings
- // {
- // // For debugging consent settings by geography.
- // DebugGeography = DebugGeography.EEA,
- // // https://developers.google.com/admob/unity/test-ads
- // TestDeviceHashedIds = GoogleMobileAdsController.TestDeviceIds,
- // }
- };
- // The Google Mobile Ads SDK provides the User Messaging Platform (Google's
- // IAB Certified consent management platform) as one solution to capture
- // consent for users in GDPR impacted countries. This is an example and
- // you can choose another consent management platform to capture consent.
- ConsentInformation.Update(requestParameters, updateError =>
- {
- // Enable the change privacy settings button.
- UpdatePrivacyButton();
- if (updateError != null)
- {
- onComplete?.Invoke(updateError.Message);
- return;
- }
- // Determine the consent-related action to take based on the ConsentStatus.
- if (CanRequestAds)
- {
- // Consent has already been gathered or not required.
- // Return control back to the user.
- onComplete?.Invoke(null);
- return;
- }
- // Consent not obtained and is required.
- // Load the initial consent request form for the user.
- ConsentForm.LoadAndShowConsentFormIfRequired(showError =>
- {
- UpdatePrivacyButton();
- onComplete?.Invoke(showError?.Message);
- });
- });
- }
- /// <summary>
- /// Shows the privacy options form to the user.
- /// </summary>
- /// <remarks>
- /// Your app needs to allow the user to change their consent status at any time.
- /// Load another form and store it to allow the user to change their consent status
- /// </remarks>
- public static void ShowPrivacyOptionsForm(Action<string> onComplete)
- {
- // Debug.Log("Showing privacy options form.");
- ConsentForm.ShowPrivacyOptionsForm(showError =>
- {
- UpdatePrivacyButton();
- onComplete?.Invoke(showError?.Message);
- });
- }
- private static void UpdatePrivacyButton()
- {
- // if (_privacyButton != null)
- // {
- // _privacyButton.interactable =
- // ConsentInformation.PrivacyOptionsRequirementStatus ==
- // PrivacyOptionsRequirementStatus.Required;
- // }
- }
- }
- }
|