| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.UI;
- public class InfraredResolution : MonoBehaviour
- {
- /// <summary>
- /// 建立Toggle列表,存取所有的Toggle,便于调用操作
- /// </summary>
- [SerializeField] List<Toggle> ToggleList = new List<Toggle>();
- // Start is called before the first frame update
- int _index = 0;
- void Start()
- {
- #if UNITY_ANDROID
- if (InfraredDemo.running) {
- _index = (int)InfraredDemo._ins.resoution.Get();
- }
- #endif
- //给list赋值
- //ToggleList = transform.GetComponentsInChildren<Toggle>().ToList();
- //遍历Toggle Group下的所有Toggle
- for (int i = 0; i < ToggleList.Count; i++)
- {
- var toggle = ToggleList[i];
- var a = i;
- toggle.isOn = _index == i;
- //绑定Toggle事件
- toggle.onValueChanged.AddListener(delegate (bool ison)
- {
- this.OnValueChanged(ison, a);
- });
- }
- }
- public void OnValueChanged(bool ison, int value)
- {
- if (ison)
- {
- print("执行你的选中方法:"+ value);
- _index = value;
- }
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- public void Restart()
- {
- //存储一次操作数据
- if (InfraredDemo.running) {
- InfraredDemo._ins.resolutionRestartApp(_index);
- Destroy(gameObject);
- }
-
- }
- public void Close()
- {
- Destroy(gameObject);
- }
- }
|