private void SetupToggle(ConsentDialog.Toggle toggleData) { if (toggle == null) { return; } toggle.isOn = toggleData.IsOn; if (!toggleData.IsInteractable) { toggle.interactable = false; return; } toggle.OnValueChanged.AddListener(isOn => { if (toggleData.ShouldToggleDescription) { UpdateDescription(isOn ? toggleData.OnDescription : toggleData.OffDescription); } if (OnToggleStateUpdated != null) { OnToggleStateUpdated(toggleData.Id, isOn); } }); }
public EditorConsentDialogToggleUI AddToggle(ConsentDialog.Toggle toggleData) { if (togglePrefab == null || contentParent == null) { return(null); } if (createdToggles.ContainsKey(toggleData.Id)) { Debug.LogWarning("Ignored a toggle with duplicated id: " + toggleData.Id + "!!!"); return(null); } EditorConsentDialogToggleUI newToggle = GameObject.Instantiate(togglePrefab); newToggle.UpdateSettings(toggleData); newToggle.OnToggleStateUpdated += OnToggleStateUpdated; newToggle.transform.SetParent(contentParent, false); createdToggles.Add(toggleData.Id, newToggle); return(newToggle); }
/// <summary> /// Constructs the consent dialog. Set localize to true to use the /// localized content. /// </summary> /// <returns>The consent dialog.</returns> /// <param name="localize">If set to <c>true</c> localize.</param> private static ConsentDialog ConstructConsentDialog(bool localize) { /// /// Here we create a consent dialog completely from coding. /// The alternative is to use our consent dialog editor in /// the Privacy module settings UI to compose the dialog content. /// Here we manually pick the correct translation based on the /// localization requirement. In a real-world app, you may use /// a professional localization tool to do that. /// If you're showing the default consent dialog (constructed /// with the consent dialog editor), you can insert placeholder /// texts into the dialog content and then replace them /// with translated texts in script before showing /// the dialog for localization purpose. /// // First check if there's any consent saved previously. // If there is, we will set the 'isOn' state of our toggles // according to the saved consent to reflect the current consent // status on the consent dialog. DemoAppConsent consent = DemoAppConsent.LoadDemoAppConsent(); // First create a new consent dialog. ConsentDialog dialog = new ConsentDialog(); // Title. dialog.Title = localize ? FrTitle : EnTitle; // Put our disclaimer on top. dialog.AppendText(Disclaimer); // Add the first paragraph. dialog.AppendText(localize ? FrFirstParagraph : EnFirstParagraph); // Build and append the Advertising toggle. ConsentDialog.Toggle adsToggle = new ConsentDialog.Toggle(AdsToggleId); adsToggle.Title = localize ? FrAdsToggleTitle : EnAdsToggleTitle; adsToggle.OnDescription = localize ? FrAdsToggleOnDesc : EnAdsToggleOnDesc; adsToggle.OffDescription = localize ? FrAdsToggleOffDesc : EnAdsToggleOffDesc; adsToggle.ShouldToggleDescription = true; // make the description change with the toggle state. adsToggle.IsOn = consent != null ? consent.advertisingConsent == ConsentStatus.Granted : false; // reflect previous ads consent if any dialog.AppendToggle(adsToggle); // Build and append the Notifications toggle. ConsentDialog.Toggle notifsToggle = new ConsentDialog.Toggle(NotifsToggleId); notifsToggle.Title = localize ? FrNotifsToggleTitle : EnNotifsToggleTitle; notifsToggle.OnDescription = localize ? FrNotifsToggleDesc : EnNotifsToggleDesc; notifsToggle.ShouldToggleDescription = false; // use same description for both on & off states. notifsToggle.IsOn = consent != null ? consent.notificationConsent == ConsentStatus.Granted : false; // reflect previous notifs consent if any dialog.AppendToggle(notifsToggle); // Build and append the Unity Analytics toggle. // If the opt-out URL for Unity Analytics is available, we'll insert it // to the toggle description. Otherwise we'll use the "URL unavailable" description. // Note that this toggle is ON by default and is not interactable because we can't opt-out // Unity Analytics locally, instead the user must visit the fetched URL to opt-out. ConsentDialog.Toggle uaToggle = new ConsentDialog.Toggle(UnityAnalyticsToggleId); uaToggle.Title = localize ? FrAnalyticsToggleTitle : EnAnalyticsToggleTitle; uaToggle.ShouldToggleDescription = false; // the description won't change when the toggle switches between on & off states. uaToggle.IsInteractable = false; // not interactable uaToggle.IsOn = true; // consent for UnityAnalytics is ON by default, can opt-out via Unity URL if (!string.IsNullOrEmpty(UnityAnalyticsOptOutURL)) { // Unity Analytics opt-out URL is available. var description = localize ? FrAnalyticsToogleDesc : EnAnalyticsToogleDesc; description = description.Replace(UnityAnalyticsOptOutURLPlaceholder, UnityAnalyticsOptOutURL); // replace placeholder with actual URL uaToggle.OnDescription = description; } else { // Unity Analytics opt-out URL is not available. uaToggle.OnDescription = localize ? FrAnalyticsToggleUnavailDesc : EnAnalyticsToggleUnavailDesc; } dialog.AppendToggle(uaToggle); // Append the second paragraph. dialog.AppendText(localize ? FrSecondParagraph : EnSecondParagraph); // Build and append the accept button. // A consent dialog should always have at least one button! ConsentDialog.Button okButton = new ConsentDialog.Button(AcceptButtonId); okButton.Title = localize ? FrButtonTitle : EnButtonTitle; okButton.TitleColor = Color.white; okButton.BodyColor = new Color(66 / 255f, 179 / 255f, 1); dialog.AppendButton(okButton); return(dialog); }
public void UpdateSettings(ConsentDialog.Toggle toggleData) { UpdateDescription(toggleData.Description); UpdateTitle(toggleData.Title); SetupToggle(toggleData); }