AgreenmentOption.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. /* 勾选框-用户协议和隐私政策 */
  7. public class AgreenmentOption : MonoBehaviour
  8. {
  9. public static AgreenmentOption ins;
  10. Toggle toggle;
  11. void Awake()
  12. {
  13. //ins = this;
  14. toggle = transform.Find("Toggle").GetComponent<Toggle>();
  15. InitAgreementOnClickListeners();
  16. }
  17. void OnEnable()
  18. {
  19. if (ins == null || !ins.gameObject.activeInHierarchy)
  20. {
  21. ins = this;
  22. Debug.Log("AgreenmentOption:"+ ins.transform.parent.parent.name + " is active in hierarchy.");
  23. }
  24. }
  25. void OnDestroy()
  26. {
  27. if (ins == this) ins = null;
  28. }
  29. void InitAgreementOnClickListeners()
  30. {
  31. transform.Find("TextA").GetComponent<Button>().onClick.AddListener(delegate ()
  32. {
  33. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
  34. o.GetComponent<AgreementView>().EnterUserAgreement();
  35. });
  36. transform.Find("TextB").GetComponent<Button>().onClick.AddListener(delegate ()
  37. {
  38. GameObject o = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Views/AgreementView"));
  39. o.GetComponent<AgreementView>().EnterPrivacyAgreement();
  40. });
  41. }
  42. public bool IsAgreementChecked()
  43. {
  44. //transform.Find("Toggle").GetComponent<Toggle>()
  45. return toggle.isOn;
  46. }
  47. public void SetAgreementChecked(bool value)
  48. {
  49. toggle.isOn = value;
  50. }
  51. }