internal static UserConsentUI Request(ConsentRequestParameters parameters)
        {
            Audience savedAudience = Audience.Mixed;

            if (parameters.withAudienceDefinition && parameters.resetStatus < 2)
            {
                int selectedYear = GetYearOfBirth();
                savedAudience = GetAudience(selectedYear);
                if (savedAudience != Audience.Mixed)
                {
                    MobileAds.settings.taggedAudience = savedAudience;
                }

                if (selectedYear > 0)
                {
                    MobileAds.targetingOptions.age = DateTime.Now.Year - selectedYear;
                }
            }

            if (parameters.resetStatus == 0 || savedAudience == Audience.Children)
            {
                var savedStatus = GetStatus();
                if (savedStatus != ConsentStatus.Undefined)
                {
                    MobileAds.settings.userConsent = savedStatus;
                    SetMediationExtras();
                    if (parameters.OnConsent != null)
                    {
                        parameters.OnConsent();
                    }
                    return(null);
                }
            }

            if (!parameters.showInEditor && Application.isEditor)
            {
                if (parameters.OnConsent != null)
                {
                    parameters.OnConsent();
                }
                return(null);
            }

            if (!parameters.uiPrefab)
            {
                throw new NullReferenceException("Consent Request require UserConsentUI prefab!");
            }
            var instance = UnityEngine.Object.Instantiate(parameters.uiPrefab);

            instance.Init(parameters);
            return(instance);
        }
Beispiel #2
0
        private void OnEnable()
        {
            var props = serializedObject;

            requestOnAwakeProp     = props.FindProperty("requestOnAwake");
            resetUserInfoProp      = props.FindProperty("resetUserInfo");
            resetConsentStatusProp = props.FindProperty("resetConsentStatus");
            parametersProp         = props.FindProperty("parameters");
            OnConsentProp          = props.FindProperty("OnConsent");

            useGlobalParameters = parametersProp.objectReferenceValue == null;

            paramsInResources = Resources.Load <ConsentRequestParameters>(ConsentRequestParameters.defaultAssetPath);
        }
Beispiel #3
0
        public void Present()
        {
            if (!parameters)
            {
                parameters = UserConsent.BuildRequest();
            }

            if (resetConsentStatus)
            {
                parameters.WithResetConsentStatus();
            }
            if (resetUserInfo)
            {
                parameters.WithResetUserInfo();
            }
            parameters.WithCallback(OnConsentCallback)
            .Present();
        }
        public void Init(ConsentRequestParameters parameters)
        {
            this.parameters = parameters;

            var language = Application.systemLanguage;

            bool requiredAudienceDefinition = parameters.withAudienceDefinition &&
                                              (parameters.resetStatus == 2 || ConsentClient.GetYearOfBirth() < 0);

            if (audienceDefinition)
            {
                audienceDefinition.gameObject.SetActive(requiredAudienceDefinition);
                audienceDefinition.OnConsentRequired.AddListener(ShowConsentPanel);
                audienceDefinition.OnUnderAgeOfConsent.AddListener(OnConsentDenied);
            }
            else
            {
                requiredAudienceDefinition = false;
            }

            consentTextContainer.gameObject.SetActive(!requiredAudienceDefinition);

            if (mediationSettings)
            {
                mediationSettings.gameObject.SetActive(false);
                mediationSettings.OnConsent.AddListener(OnMediationSettingsApplied);
                if (parameters.settingsTogglePrefab)
                {
                    mediationSettings.policyPrefab = parameters.settingsTogglePrefab;
                }

                if (mediationSettingsBtn)
                {
                    mediationSettingsBtn.gameObject.SetActive(parameters.withMediationSettings);
                    mediationSettingsBtn.onClick.AddListener(OnOpenOptions);
                }
            }

            if (acceptBtn)
            {
                acceptBtn.gameObject.SetActive(true);
                acceptBtn.onClick.AddListener(OnConsentAccepted);
            }

            if (declineBtn)
            {
                declineBtn.gameObject.SetActive(parameters.withDeclineOption);
                declineBtn.onClick.AddListener(OnConsentDenied);
            }

            if (privacyPolicyBtn)
            {
                if (!string.IsNullOrEmpty(parameters.GetPrivacyPolicyUrl(Application.platform)))
                {
                    privacyPolicyBtn.gameObject.SetActive(true);
                    privacyPolicyBtn.onClick.AddListener(OnOpenCompanyPrivacyPolicy);
                }
                else
                {
                    privacyPolicyBtn.gameObject.SetActive(false);
                }
            }

            if (termsOfUseBtn)
            {
                if (!string.IsNullOrEmpty(parameters.GetTermsOfUseUrl(Application.platform)))
                {
                    termsOfUseBtn.gameObject.SetActive(true);
                    termsOfUseBtn.onClick.AddListener(OnOpenTermsOfUse);
                }
                else
                {
                    termsOfUseBtn.gameObject.SetActive(false);
                }
            }
        }