DataPrivacyButton.cs 1.4 KB

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