AgreementPopup.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. /* 弹窗-用户协议和隐私政策 */
  5. public class AgreementPopup : MonoBehaviour, MenuBackInterface
  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 OnEnable()
  24. {
  25. PersistenHandler.ins?.menuBackCtr.views.Add(this);
  26. }
  27. void OnDisable()
  28. {
  29. PersistenHandler.ins?.menuBackCtr.views.Remove(this);
  30. }
  31. void Start()
  32. {
  33. if (PlayerPrefs.GetInt("AgreementPopupChecked", 0) == 1) {
  34. this.gameObject.SetActive(false);
  35. AgreenmentOption.ins.SetAgreementChecked(true);
  36. }
  37. }
  38. public bool OnMenuBack() {
  39. Disagree();
  40. return true;
  41. }
  42. public void Agree() {
  43. PlayerPrefs.SetInt("AgreementPopupChecked", 1);
  44. this.gameObject.SetActive(false);
  45. AgreenmentOption.ins.SetAgreementChecked(true);
  46. }
  47. [System.NonSerialized] public System.Action onDisagree;
  48. public void Disagree() {
  49. PlayerPrefs.SetInt("AgreementPopupChecked", 0);
  50. this.gameObject.SetActive(false);
  51. AgreenmentOption.ins.SetAgreementChecked(false);
  52. onDisagree?.Invoke();
  53. }
  54. public void EnterUserAgreement() {
  55. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
  56. o.GetComponent<AgreementView>().EnterUserAgreement();
  57. }
  58. public void EnterPrivacyAgreement() {
  59. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
  60. o.GetComponent<AgreementView>().EnterPrivacyAgreement();
  61. }
  62. }