| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /* 设备界面 */
- public class DeviceViewInfrared : JCUnityLib.ViewBase, MenuBackInterface
- {
- //GameObject bowOptions;
- [SerializeField] GameObject Connect1Parent;
- [SerializeField] List<Button> smartConnect1Buttons;
- [SerializeField] GameObject Connect2Parent;
- [SerializeField] List<Button> smartConnect2Buttons;
- [SerializeField] List<Sprite> smartArcheryBg;
- [SerializeField] List<DeviceView_ItemShow> deviceViewItems;
- //当前选择的对象类
- [HideInInspector] public DeviceView_ItemShow selectDeviceViewItem;
- public static DeviceViewInfrared ins;
- public Action action_OnClickGyr;
- public Action action_OnClickMag;
- public HorizontalLayoutGroup horizontalLayoutGroup;
- bool bSwitchDevice = false;
- void Start()
- {
- ins = this;
- PersistenHandler.ins?.menuBackCtr.views.Add(this);
- //Button1 事件绑定
- for (int i = 0; i < smartConnect1Buttons.Count; i++)
- {
- int temp = i;
- smartConnect1Buttons[i].onClick.AddListener(()=>{
- OnChangeSmartConnect1Button(temp);
- });
- }
- OnChangeSmartArcheryButtonState((int)GlobalData.MyDeviceMode);
- //Button2 事件绑定
- for (int i = 0; i < smartConnect2Buttons.Count; i++)
- {
- int temp = i;
- smartConnect2Buttons[i].onClick.AddListener(() => {
- OnChangeSmartConnect2Button(temp);
- });
- }
- AimHandler.ins.onCreateAimDeviceInfoById();
- //默认选择第一个设备
- deviceViewItems[0].setPanelStatus(true);
- //先隐藏一个设备。如果连接之后,再显示2p,如果已经连接到蓝牙,直接显示
- if (deviceViewItems[1].getBLEConnectState())
- {
- ShowDeviceViewItemsTwo(true);
- }
- else {
- ShowDeviceViewItemsTwo(false);
- }
-
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- PersistenHandler.ins?.menuBackCtr.views.Remove(this);
- //退出面板时候,取消正在连接的连接
- BluetoothAim.ins.onCancelAllConnecting();
- }
- void Update()
- {
- //刷新按钮显示状态2P
- if (BluetoothAim.ins)
- {
- if (selectDeviceViewItem != null)
- {
- if (selectDeviceViewItem.getCurrentItemVisible() && !bSwitchDevice)
- {
- if (Connect1Parent.activeSelf) Connect1Parent.SetActive(false);
- if (!Connect2Parent.activeSelf) Connect2Parent.SetActive(true);
- if (Connect2Parent.activeSelf)
- {
- //判断是否显示连接还是断开按钮
- if (selectDeviceViewItem.getBLEConnectState())
- {
- if (smartConnect2Buttons[1].gameObject.activeSelf)
- {
- smartConnect2Buttons[1].gameObject.SetActive(false);
- smartConnect2Buttons[2].gameObject.SetActive(true);
- }
- }
- else
- {
- if (!smartConnect2Buttons[1].gameObject.activeSelf)
- {
- smartConnect2Buttons[1].gameObject.SetActive(true);
- smartConnect2Buttons[2].gameObject.SetActive(false);
- }
- }
- }
- }
- else
- {
- if (!Connect1Parent.activeSelf) Connect1Parent.SetActive(true);
- if (Connect2Parent.activeSelf) Connect2Parent.SetActive(false);
- }
- }
- else {
- if (!Connect1Parent.activeSelf) Connect1Parent.SetActive(true);
- if (Connect2Parent.activeSelf) Connect2Parent.SetActive(false);
- }
- }
- }
- void ShowDeviceViewItemsTwo(bool bShow) {
- if (bShow)
- {
- if (!deviceViewItems[1].gameObject.activeSelf)
- {
- deviceViewItems[1].gameObject.SetActive(true);
- horizontalLayoutGroup.spacing = 40;
- }
- }
- else
- {
- if (deviceViewItems[1].gameObject.activeSelf)
- {
- deviceViewItems[1].gameObject.SetActive(false);
- horizontalLayoutGroup.spacing = 76;
- }
- }
- }
- public bool OnMenuBack() {
- ViewMgr.Instance.DestroyView<DeviceViewInfrared>();
- return true;
- }
- public void OnClick_Back() {
- AudioMgr.ins.PlayBtn();
- ViewMgr.Instance.DestroyView<DeviceViewInfrared>();
- }
- /// <summary>
- /// 第一次进入页面选择的按钮的下标
- /// </summary>
- /// <param name="index"></param>
- public void OnChangeSmartConnect1Button(int index)
- {
- bool _selected = false;
- for (int i = 0; i < smartConnect1Buttons.Count; i++)
- {
- Button _button = smartConnect1Buttons[i];
- Color32 _white;
- if (index == i)
- {
- _white = new Color32(255, 255, 255, 255);
- _selected = true;
- _button.GetComponent<Image>().sprite = smartArcheryBg[1];
- }
- else
- {
- _white = new Color32(59, 59, 59, 255);
- //_buttonBg = new Color32(255, 255, 255, 255);
- _button.GetComponent<Image>().sprite = smartArcheryBg[0];
- }
- _button.transform.Find("icon").GetComponent<Image>().color = _white;
- _button.transform.Find("title").GetComponent<Text>().color = _white;
- _button.transform.Find("arrow").GetComponent<Image>().color = _white;
- }
- if (_selected)
- {
- //进入选中的页面
- AudioMgr.ins.PlayBtn();
- //设置一次 GlobalData.MyDeviceMode
- if (getEnabelPanelStatus())//是否处于选中状态
- {
- //取消正在连接的连接
- BluetoothAim.ins.onCancelAllConnecting(BluetoothStatusEnum.Connect);
- if (index == 0)
- {
- ViewMgr.Instance.ShowView<SmartArcheryView>();
- }
- else if (index == 1)
- {
- Debug.Log("Gun");
- ViewMgr.Instance.ShowView<SmartGunView>();
- }
- bSwitchDevice = false;
- AimHandler.ins.onCreateTempAimDeviceInfo();
- }
- }
- }
- /// <summary>
- /// 第二次进入页面时候。
- /// </summary>
- /// <param name="index"></param>
- public void OnChangeSmartConnect2Button(int index)
- {
- //Debug.Log("OnChangeSmartConnect1Button按钮:" + index);
- bool _selected = false;
- for (int i = 0; i < smartConnect2Buttons.Count; i++)
- {
- Button _button = smartConnect2Buttons[i];
- Color32 _white;
- //Color32 _buttonBg;
- if (index == i)
- {
- _white = new Color32(255, 255, 255, 255);
- //_buttonBg = new Color32(16, 194, 198, 255);
- _selected = true;
- _button.GetComponent<Image>().sprite = smartArcheryBg[1];
- }
- else
- {
- _white = new Color32(59, 59, 59, 255);
- //_buttonBg = new Color32(255, 255, 255, 255);
- _button.GetComponent<Image>().sprite = smartArcheryBg[0];
- }
- _button.transform.Find("icon").GetComponent<Image>().color = _white;
- _button.transform.Find("title").GetComponent<Text>().color = _white;
- _button.transform.Find("arrow").GetComponent<Image>().color = _white;
- }
- if (_selected)
- {
- //进入选中的页面
- AudioMgr.ins.PlayBtn();
- //设置一次 GlobalData.MyDeviceMode
- switch (index)
- {
- case 0:
- //进入屏幕定位
- ViewManager2.ShowView(ViewManager2.Path_InfraredView);
- break;
- case 1:
- //连接设备
- if (getEnabelPanelStatus())//是否处于选中状态
- {
- //取消正在连接的连接
- BluetoothAim.ins.onCancelAllConnecting(BluetoothStatusEnum.Connect);
- //进入弓箭选择页面
- ViewMgr.Instance.ShowView<SmartArcheryView>();
- AimHandler.ins.onCreateTempAimDeviceInfo();
- }
- break;
- case 2:
- //断开连接设备
- if (selectDeviceViewItem)
- {
- selectDeviceViewItem.OnConnectedEvent();
- }
- break;
- case 3:
- //增加2p todo HOUYI Pro/ARTEMIS Pro时,先不能增加2P;(先隐藏,待后续增加2P后,再显示)
- if (!(BluetoothAim.ins && (BluetoothAim.ins.isMainConnectToInfraredDevice() || BluetoothAim.ins.isMainConnectToGun())))
- {
- ShowDeviceViewItemsTwo(true);
- }
- break;
- case 4:
- bSwitchDevice = true;
- break;
- }
- }
- }
- //暂时先更新一个
- public void RenderBattery(int deviceID, int value)
- {
- //smartConnect1Buttons[0].GetComponent<DeviceView_ItemShow>().RenderBattery(deviceID,value);
- }
- public void OnChangeSmartArcheryButtonState(int index)
- {
- for (int i = 0; i < smartConnect1Buttons.Count; i++)
- {
- Button _button = smartConnect1Buttons[i];
- Color32 _white;
- //Color32 _buttonBg;
- if (index == i)
- {
- _white = new Color32(255, 255, 255, 255);
- _button.GetComponent<Image>().sprite = smartArcheryBg[1];
- }
- else
- {
- _white = new Color32(59, 59, 59, 255);
- _button.GetComponent<Image>().sprite = smartArcheryBg[0];
- }
- _button.transform.Find("icon").GetComponent<Image>().color = _white;
- _button.transform.Find("title").GetComponent<Text>().color = _white;
- _button.transform.Find("arrow").GetComponent<Image>().color = _white;
- }
- }
- public void OnChangeSmartConnect2ButtonState(int index)
- {
- for (int i = 0; i < smartConnect2Buttons.Count; i++)
- {
- Button _button = smartConnect2Buttons[i];
- Color32 _white;
- //Color32 _buttonBg;
- if (index == i)
- {
- _white = new Color32(255, 255, 255, 255);
- _button.GetComponent<Image>().sprite = smartArcheryBg[1];
- }
- else
- {
- _white = new Color32(59, 59, 59, 255);
- _button.GetComponent<Image>().sprite = smartArcheryBg[0];
- }
- _button.transform.Find("icon").GetComponent<Image>().color = _white;
- _button.transform.Find("title").GetComponent<Text>().color = _white;
- _button.transform.Find("arrow").GetComponent<Image>().color = _white;
- }
- }
- /// <summary>
- /// 一般是切换选择硬件时调用
- /// </summary>
- public void OnCloseAllPanelStatus() {
- //重置一些按钮状态和参数
- OnChangeSmartConnect1Button(-1);
- OnChangeSmartConnect2Button(-1);
- bSwitchDevice = false;
- for (int i = 0; i < deviceViewItems.Count; i++)
- {
- deviceViewItems[i].setPanelStatus(false);
- }
- }
- //检测是否选择一个设备情况。用选择框判断
- public bool getEnabelPanelStatus() {
- bool bHasEnabel = false;
- for (int i = 0; i < deviceViewItems.Count; i++)
- {
- if (deviceViewItems[i].getCurrentPanelEnable()) {
- bHasEnabel = true;
- break;
- }
- }
- return bHasEnabel;
- }
- public void onTestClear() {
- AimHandler.ins.onClearAimDeviceInfosNew();
- }
- }
|