| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class DeviceViewSelectStatus {
- int index = 0;
- bool bShow = false;
- Sprite ItemPanel;
- }
- /* 设备界面 */
- public class DeviceView : JCUnityLib.ViewBase, MenuBackInterface
- {
- //GameObject bowOptions;
- [SerializeField] List<Button> smartArcheryButtons;
- [SerializeField] List<Sprite> smartArcheryBg;
- [SerializeField] List<DeviceView_ItemShow> deviceViewItems;
- public static DeviceView ins;
- public Action action_OnClickGyr;
- public Action action_OnClickMag;
- public HorizontalLayoutGroup horizontalLayoutGroup;
- //[SerializeField] List<DeviceViewSelectStatus> deviceViewItems;
- void Start()
- {
- ins = this;
- PersistenHandler.ins?.menuBackCtr.views.Add(this);
- for (int i = 0; i < smartArcheryButtons.Count; i++)
- {
- int temp = i;
- smartArcheryButtons[i].onClick.AddListener(()=>{
- OnChangeSmartArcheryButton(temp);
- });
- }
- OnChangeSmartArcheryButtonState((int)GlobalData.MyDeviceMode);
- //bowOptions = this.transform.Find("ItemInfo/BowOptions").gameObject;
- //初始化弓的校准按钮
- //Button[] bowOptionBtns = bowOptions.GetComponentsInChildren<Button>();
- //for (int i = 0; i < bowOptionBtns.Length; i++)
- //{
- // int optionID = i;
- // bowOptionBtns[i].onClick.AddListener(delegate() {
- // AudioMgr.ins.PlayBtn();
- // switch (optionID)
- // {
- // case 0:
- // DeviceCalibrateView.Create(DeviceCalibrateItem.Gyr);
- // action_OnClickGyr?.Invoke();
- // break;
- // case 1:
- // DeviceCalibrateView.Create(DeviceCalibrateItem.Mag);
- // action_OnClickMag?.Invoke();
- // break;
- // }
- // });
- //}
- //进入连接界面,初始化一下AimDeviceInfo
- //AimHandler.ins.OnGetAimDeviceInfos();
- AimHandler.ins.onCreateAimDeviceInfoById();
- }
- void OnDestroy()
- {
- if (ins == this) ins = null;
- PersistenHandler.ins?.menuBackCtr.views.Remove(this);
- //退出面板时候,取消正在连接的连接
- BluetoothAim.ins.onCancelAllConnecting();
- }
- void Update()
- {
- //刷新按钮显示状态2P
- if (BluetoothAim.ins && BluetoothAim.ins.isMainConnectToInfraredDevice())
- {
- if (deviceViewItems[1].gameObject.activeSelf)
- {
- deviceViewItems[1].gameObject.SetActive(false);
- horizontalLayoutGroup.spacing = 60;
- }
- }
- else
- {
- if (!deviceViewItems[1].gameObject.activeSelf)
- {
- deviceViewItems[1].gameObject.SetActive(true);
- horizontalLayoutGroup.spacing = 40;
- }
- }
- }
- public bool OnMenuBack() {
- ViewMgr.Instance.DestroyView<DeviceView>();
- return true;
- }
- public void OnClick_Back() {
- AudioMgr.ins.PlayBtn();
- ViewMgr.Instance.DestroyView<DeviceView>();
- }
- void OnChangeSmartArcheryButton(int index) {
- //Debug.Log("OnChangeSmartArcheryButton按钮:" + index);
- bool _selected = false;
- for (int i = 0; i < smartArcheryButtons.Count; i++)
- {
- Button _button = smartArcheryButtons[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
- //HomeView.ins.MyTopBarView.onChangeType(index);
- 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>();
- }
- AimHandler.ins.onCreateTempAimDeviceInfo();
- }
- }
- }
- //暂时先更新一个
- public void RenderBattery(int deviceID, int value)
- {
- //smartArcheryButtons[0].GetComponent<DeviceView_ItemShow>().RenderBattery(deviceID,value);
- }
- public void OnChangeSmartArcheryButtonState(int index)
- {
- for (int i = 0; i < smartArcheryButtons.Count; i++)
- {
- Button _button = smartArcheryButtons[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 OnCloseAllPanelStatus() {
- 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();
- }
- }
|