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 (InfraredDemo.running) {
  17. _index = (int)InfraredDemo._ins.resoution.Get();
  18. }
  19. //给list赋值
  20. ToggleList = transform.GetComponentsInChildren<Toggle>().ToList();
  21. //遍历Toggle Group下的所有Toggle
  22. for (int i = 0; i < ToggleList.Count; i++)
  23. {
  24. var toggle = ToggleList[i];
  25. var a = i;
  26. toggle.isOn = _index == i;
  27. //绑定Toggle事件
  28. toggle.onValueChanged.AddListener(delegate (bool ison)
  29. {
  30. this.OnValueChanged(ison, a);
  31. });
  32. }
  33. }
  34. public void OnValueChanged(bool ison, int value)
  35. {
  36. if (ison)
  37. {
  38. print("执行你的选中方法:"+ value);
  39. //InfraredDemo._ins.SetResolutionGuider(value);
  40. _index = value;
  41. }
  42. }
  43. // Update is called once per frame
  44. void Update()
  45. {
  46. }
  47. public void Restart()
  48. {
  49. //存储一次操作数据
  50. if (InfraredDemo.running) {
  51. InfraredDemo._ins.resolutionRestartApp(_index);
  52. }
  53. }
  54. public void Close()
  55. {
  56. Destroy(gameObject);
  57. }
  58. }