AgreementPopup.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /* 弹窗-用户协议和隐私政策 */
  5. public class AgreementPopup : MonoBehaviour
  6. {
  7. void Awake() {
  8. HyperlinkText hyperlinkText = null;
  9. if (TextAutoLanguage2.GetLanguage() == LanguageEnum.Chinese) {
  10. transform.Find("ContentBG").gameObject.SetActive(true);
  11. } else {
  12. Transform content = transform.Find("ContentBG_en");
  13. content.gameObject.SetActive(true);
  14. hyperlinkText = content.GetComponentInChildren<HyperlinkText>();
  15. }
  16. if (hyperlinkText) {
  17. hyperlinkText.onClickHref += (val) => {
  18. if (val == "a") EnterUserAgreement();
  19. else if (val == "b") EnterPrivacyAgreement();
  20. };
  21. }
  22. }
  23. void Start()
  24. {
  25. if (PlayerPrefs.GetInt("AgreementPopupChecked", 0) == 1) {
  26. this.gameObject.SetActive(false);
  27. AgreenmentOption.ins.SetAgreementChecked(true);
  28. }
  29. }
  30. public void Agree() {
  31. PlayerPrefs.SetInt("AgreementPopupChecked", 1);
  32. this.gameObject.SetActive(false);
  33. AgreenmentOption.ins.SetAgreementChecked(true);
  34. }
  35. [System.NonSerialized] public System.Action onDisagree;
  36. public void Disagree() {
  37. PlayerPrefs.SetInt("AgreementPopupChecked", 0);
  38. this.gameObject.SetActive(false);
  39. AgreenmentOption.ins.SetAgreementChecked(false);
  40. onDisagree?.Invoke();
  41. }
  42. public void EnterUserAgreement() {
  43. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
  44. o.GetComponent<AgreementView>().EnterUserAgreement();
  45. }
  46. public void EnterPrivacyAgreement() {
  47. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
  48. o.GetComponent<AgreementView>().EnterPrivacyAgreement();
  49. }
  50. }