AgreementPopup.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. {
  13. //添加日文
  14. Transform content = TextAutoLanguage2.GetLanguage() == LanguageEnum.Japan? transform.Find("ContentBG_jp") : transform.Find("ContentBG_en");
  15. content.gameObject.SetActive(true);
  16. hyperlinkText = content.GetComponentInChildren<HyperlinkText>();
  17. }
  18. if (hyperlinkText) {
  19. hyperlinkText.onClickHref += (val) => {
  20. if (val == "a") EnterUserAgreement();
  21. else if (val == "b") EnterPrivacyAgreement();
  22. };
  23. }
  24. }
  25. void OnEnable()
  26. {
  27. PersistenHandler.ins?.menuBackCtr.views.Add(this);
  28. }
  29. void OnDisable()
  30. {
  31. PersistenHandler.ins?.menuBackCtr.views.Remove(this);
  32. }
  33. void Start()
  34. {
  35. if (PlayerPrefs.GetInt("AgreementPopupChecked", 0) == 1) {
  36. this.gameObject.SetActive(false);
  37. AgreenmentOption.ins.SetAgreementChecked(true);
  38. }
  39. }
  40. public bool OnMenuBack() {
  41. Disagree();
  42. return true;
  43. }
  44. public void Agree() {
  45. PlayerPrefs.SetInt("AgreementPopupChecked", 1);
  46. this.gameObject.SetActive(false);
  47. AgreenmentOption.ins.SetAgreementChecked(true);
  48. }
  49. [System.NonSerialized] public System.Action onDisagree;
  50. public void Disagree() {
  51. PlayerPrefs.SetInt("AgreementPopupChecked", 0);
  52. this.gameObject.SetActive(false);
  53. AgreenmentOption.ins.SetAgreementChecked(false);
  54. onDisagree?.Invoke();
  55. }
  56. public void EnterUserAgreement() {
  57. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
  58. o.GetComponent<AgreementView>().EnterUserAgreement();
  59. }
  60. public void EnterPrivacyAgreement() {
  61. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
  62. o.GetComponent<AgreementView>().EnterPrivacyAgreement();
  63. }
  64. }