InfraredResolution.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 ||UNITY_IOS
  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. if (InfraredDemo.running)
  44. {
  45. InfraredDemo._ins.resolutionRestartApp(_index);
  46. }
  47. }
  48. }
  49. // Update is called once per frame
  50. void Update()
  51. {
  52. }
  53. public void Restart()
  54. {
  55. //存储一次操作数据
  56. if (InfraredDemo.running) {
  57. InfraredDemo._ins.resolutionRestartApp(_index);
  58. Destroy(gameObject);
  59. }
  60. }
  61. public void Close()
  62. {
  63. Destroy(gameObject);
  64. }
  65. }