InfraredResolution.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class InfraredResolution : MonoBehaviour
  7. {
  8. /// <summary>
  9. /// 建立Toggle列表,存取所有的Toggle,便于调用操作
  10. /// </summary>
  11. [SerializeField] List<Toggle> ToggleList = new List<Toggle>();
  12. // Start is called before the first frame update
  13. int _index = 0;
  14. void Start()
  15. {
  16. #if UNITY_ANDROID
  17. if (InfraredDemo.running) {
  18. _index = (int)InfraredDemo._ins.resoution.Get();
  19. }
  20. #endif
  21. //给list赋值
  22. //ToggleList = transform.GetComponentsInChildren<Toggle>().ToList();
  23. //遍历Toggle Group下的所有Toggle
  24. for (int i = 0; i < ToggleList.Count; i++)
  25. {
  26. var toggle = ToggleList[i];
  27. var a = i;
  28. toggle.isOn = _index == i;
  29. //绑定Toggle事件
  30. toggle.onValueChanged.AddListener(delegate (bool ison)
  31. {
  32. this.OnValueChanged(ison, a);
  33. });
  34. }
  35. }
  36. public void OnValueChanged(bool ison, int value)
  37. {
  38. if (ison)
  39. {
  40. print("执行你的选中方法:"+ value);
  41. _index = value;
  42. }
  43. }
  44. // Update is called once per frame
  45. void Update()
  46. {
  47. }
  48. public void Restart()
  49. {
  50. //存储一次操作数据
  51. if (InfraredDemo.running) {
  52. InfraredDemo._ins.resolutionRestartApp(_index);
  53. Destroy(gameObject);
  54. }
  55. }
  56. public void Close()
  57. {
  58. Destroy(gameObject);
  59. }
  60. }