You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

  1. #if ENABLE_CLOUD_SERVICES_ANALYTICS
  2. using System;
  3. using UnityEngine.UI;
  4. namespace UnityEngine.Analytics
  5. {
  6. public class DataPrivacyButton : Button
  7. {
  8. bool urlOpened = false;
  9. DataPrivacyButton()
  10. {
  11. onClick.AddListener(OpenDataPrivacyUrl);
  12. }
  13. void OnFailure(string reason)
  14. {
  15. interactable = true;
  16. Debug.LogWarning(String.Format("Failed to get data privacy url: {0}", reason));
  17. }
  18. void OpenUrl(string url)
  19. {
  20. interactable = true;
  21. urlOpened = true;
  22. #if UNITY_WEBGL && !UNITY_EDITOR
  23. Application.ExternalEval("window.open(\"" + url + "\",\"_blank\")");
  24. #else
  25. Application.OpenURL(url);
  26. #endif
  27. }
  28. void OpenDataPrivacyUrl()
  29. {
  30. interactable = false;
  31. DataPrivacy.FetchPrivacyUrl(OpenUrl, OnFailure);
  32. }
  33. void OnApplicationFocus(bool hasFocus)
  34. {
  35. if (hasFocus && urlOpened)
  36. {
  37. urlOpened = false;
  38. // Immediately refresh the remote config so new privacy settings can be enabled
  39. // as soon as possible if they have changed.
  40. RemoteSettings.ForceUpdate();
  41. }
  42. }
  43. }
  44. }
  45. #endif //ENABLE_CLOUD_SERVICES_ANALYTICS