| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- namespace CustomUIView
- {
- public class BoxUserSettings : MonoBehaviour
- {
- [SerializeField] Transform boxSelectDevices;
- [SerializeField] GameObject[] boxDevices;
- readonly string[] SelectDevicesStrs = { "ARTEMIS Pro", "Pistol M9", "HOUYI Pro" };
- int selectDevicesIndex = 0; // 用于保存当前选择的设备索引
- // Start is called before the first frame update
- void Start()
- {
- for (int i = 0; i < boxDevices.Length; i++)
- {
- Text text = boxDevices[i].GetComponentInChildren<Text>();
- text.text = SelectDevicesStrs[i];
- Button button = boxDevices[i].GetComponent<Button>();
- string deviceName = SelectDevicesStrs[i]; // 捕获当前的设备名称
- button.onClick.AddListener(() =>
- {
- OnClick_SelectDevice(deviceName);
- });
- }
- // 获取用户设置中保存的设备名称
- string selectDeviceName = UserSettings.ins.selectDevicesName;
- // 如果名称存在于数组中,则获取其索引,否则默认选第一个
- selectDevicesIndex = System.Array.IndexOf(SelectDevicesStrs, selectDeviceName);
- if (selectDevicesIndex < 0) selectDevicesIndex = 0;
- // 渲染选择的设备
- RenderSelectDevicesIndex(selectDevicesIndex);
- }
- public void RenderSelectDevicesIndex(int value)
- {
- for (int i = 0; i < SelectDevicesStrs.Length; i++)
- {
- var item = boxSelectDevices.GetChild(i);
- var text = item.GetComponentInChildren<Text>();
- // 根据是否为选中设备设置颜色
- if (i == value)
- {
- item.GetComponent<Image>().color = new Color(16 / 255f, 194 / 255f, 198 / 255f, 1f);
- }
- else
- {
- item.GetComponent<Image>().color = new Color(96 / 255f, 96 / 255f, 96 / 255f, 1f);
- }
- // 设置设备名称
- text.text = SelectDevicesStrs[i];
- }
- }
- // 当用户点击选择设备时调用
- void OnClick_SelectDevice(string name)
- {
- // 获取选中设备的索引
- int newValue = System.Array.IndexOf(SelectDevicesStrs, name);
- // 如果选择不同设备,更新选择
- if (selectDevicesIndex != newValue)
- {
- // 播放按钮音效
- AudioMgr.ins.PlayBtn();
- // 更新选择的设备索引和名称
- selectDevicesIndex = newValue;
- UserSettings.ins.selectDevicesName = SelectDevicesStrs[selectDevicesIndex];
- UserSettings.ins.Save();
- // 渲染更新后的选择
- RenderSelectDevicesIndex(selectDevicesIndex);
- //todo 调用串口后续流程?
- }
- }
- /**
- * 调试
- */
- public void OnClick_EnterDebuggingInfrared() {
- if (InfraredDemo._ins != null) {
- InfraredDemo._ins.OnClick_See();
- }
- }
- public void OnClick_EnterDeviceConnect() {
- AudioMgr.ins.PlayBtn();
- ViewMgr.Instance.ShowView<DeviceViewInfrared>();
- }
- public void OnClick_EnterInfraredCenterCalibration()
- {
- //红外设备校准偏离点
- InfraredDemo._ins?.OnClick_SetAdjustPointsOffset();
- }
- public void OnClick_ScreenCalibration()
- {
- //进入屏幕定位
- ViewManager2.ShowView(ViewManager2.Path_InfraredView);
- }
- // Update is called once per frame
- //void Update()
- //{
- //}
- }
- }
|