| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 | 
							- using System;
 
- using System.Collections;
 
- using System.Collections.Generic;
 
- using UnityEngine;
 
- using UnityEngine.UI;
 
- public class DeviceView_ItemShow : MonoBehaviour
 
- {
 
-     [Tooltip("当前选择的用户设备")]
 
-     [SerializeField]
 
-     BluetoothPlayer bluetoothPlayer = BluetoothPlayer.FIRST_PLAYER;
 
-     [SerializeField] Image selectPanel;
 
-     [SerializeField] Button btnBg;
 
-     [SerializeField] Button btnConnectBow;
 
-     [SerializeField] Button ConnectButton;
 
-     [SerializeField] Image ConnectButtonImage;
 
-     [SerializeField] Sprite[] ConnectButtonImages;
 
-     [SerializeField] GameObject process;
 
-     [SerializeField] GameObject connected;
 
-     [SerializeField] GameObject unConnected;
 
-     [SerializeField] Text titleText;
 
-     [SerializeField] Text statusText;
 
-     [SerializeField] GameObject initStatus;
 
-     [SerializeField] GameObject bettery;
 
-     [SerializeField] GameObject betteryBar;
 
-     [SerializeField] GameObject betteryValue;
 
-     [SerializeField] Image pointImage;
 
-     [SerializeField] Sprite[] pointImages;
 
-     [SerializeField] Image rectangle;
 
-     [SerializeField] Sprite[] rectangles;
 
-     [SerializeField] Text initStatusText;
 
-     [SerializeField] Image bowBg;
 
-     [SerializeField] Sprite[] bowBgs;
 
-     [SerializeField] Sprite[] gunBgs;
 
-     float countingTime1 = 5;
 
-     BluetoothStatusEnum bowStatus;
 
-     [SerializeField] TextAutoLanguage2 _TextAutoLanguage2;
 
-     //这个是处理设备下标
 
-     [SerializeField] int deviceIndex = 0;
 
-     //是否存在连接信息。
 
-     bool bShowInfo = false;
 
-     // Start is called before the first frame update
 
-     // bool bProcess = false;
 
-     private void Awake()
 
-     {
 
-         AimHandler.ins.aimDeviceInfoChangeEvent += onShowDeviceInfo;
 
-     }
 
-     void Start()
 
-     {   //panel 按钮,选择状态。主要控制getPanelStatus
 
-         btnBg.onClick.AddListener(OnSelectEvent);
 
-         //addBtn 按钮
 
-         //btnConnectBow.onClick.AddListener(delegate ()
 
-         //{
 
-         //    AudioMgr.ins.PlayBtn();
 
-         //    //要选中情况下,才能进行下一步操作
 
-         //    if (!getPanelStatus()) return;
 
-         //    AimHandler.ins.SetAimDeviceSelectIndex(deviceIndex);
 
-         //    AimHandler.ins.onCreateTempAimDeviceInfo();
 
-         //    //ViewMgr.Instance.ShowView<SmartArcheryView>();
 
-         //    if (GlobalData.MyDeviceMode == DeviceMode.Archery)
 
-         //    {
 
-         //        ViewMgr.Instance.ShowView<SmartArcheryView>();
 
-         //    }
 
-         //    else if (GlobalData.MyDeviceMode == DeviceMode.Gun)
 
-         //    {
 
-         //        ViewMgr.Instance.ShowView<SmartGunView>();
 
-         //    }
 
-         //    else
 
-         //    {
 
-         //        Debug.LogError("btnConnectBow 没有设置页面!!");
 
-         //    }
 
-         //});
 
-         //init 按钮(有硬件信息才显示initStatus按钮)
 
-         //initStatus.GetComponent<Button>().onClick.AddListener(delegate ()
 
-         //{
 
-         //    AudioMgr.ins.PlayBtn();
 
-         //    //要选中情况下,才能进行下一步操作
 
-         //    if (!getPanelStatus()) return;
 
-         //    //选择此device index 跳转页面
 
-         //    AimHandler.ins.SetAimDeviceSelectIndex(deviceIndex);
 
-         //    AimHandler.ins.onCreateTempAimDeviceInfo();
 
-         //    if (GlobalData.MyDeviceMode == DeviceMode.Archery)
 
-         //    {
 
-         //        //判断当前的信息是否是 HOUYI PRO,是的话直接跳转到pro初始化?
 
-         //        if (AimHandler.ins.isHOUYIPRO(bluetoothPlayer))
 
-         //        {
 
-         //            //直接进入红外引导界面
 
-         //            AimHandler.ins.SetTempAimDeviceType(AimDeviceType.HOUYIPRO);
 
-         //            ViewManager2.ShowView(ViewManager2.Path_InfraredView);
 
-         //        } else if (AimHandler.ins.isARTEMISPro(bluetoothPlayer)) {
 
-         //            //直接进入红外引导界面
 
-         //            AimHandler.ins.SetTempAimDeviceType(AimDeviceType.ARTEMISPRO);
 
-         //            ViewManager2.ShowView(ViewManager2.Path_InfraredView);
 
-         //        }
 
-         //        else
 
-         //        {
 
-         //            ViewMgr.Instance.ShowView<SmartArcheryView>();
 
-         //        }
 
-         //    }
 
-         //    else if (GlobalData.MyDeviceMode == DeviceMode.Gun)
 
-         //    {
 
-         //        ViewMgr.Instance.ShowView<SmartGunView>();
 
-         //    }
 
-         //    else {
 
-         //        Debug.LogError("initStatus 没有设置页面!!");
 
-         //    }
 
-         //});
 
-         //ConnectButton.onClick.AddListener(delegate ()
 
-         //{
 
-         //    AudioMgr.ins.PlayBtn();
 
-         //    OnConnectedEvent();
 
-         //});
 
-         //进入页面更新一次
 
-         if (BluetoothAim.ins)
 
-         {
 
-             if (bluetoothPlayer == BluetoothPlayer.FIRST_PLAYER)
 
-             {
 
-                 if (BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess)
 
-                 {
 
-                     //连接后,更新电池状态
 
-                     RenderBattery(DeviceBatteryView.ins.batteryDeviceID, DeviceBatteryView.ins.batteryValue);
 
-                     if (unConnected.activeSelf) unConnected.SetActive(false);
 
-                 }
 
-             }
 
-             else
 
-             {
 
-                 SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
 
-                 if (smartBowHelper != null &&
 
-                       smartBowHelper.GetBluetoothStatus() == SmartBowSDK.BluetoothStatusEnum.Connected &&
 
-                       BluetoothAim.ins.get2PBattery() > 0)
 
-                 {
 
-                     //连接后,更新电池状态
 
-                     RenderBattery(-1, BluetoothAim.ins.get2PBattery());
 
-                 }
 
-             }
 
-         }
 
-         onUpdateStatusInfo();
 
-     }
 
-     private void OnDestroy()
 
-     {
 
-         AimHandler.ins.aimDeviceInfoChangeEvent -= onShowDeviceInfo;
 
-     }
 
-     // Update is called once per frame
 
-     void Update()
 
-     {
 
-         if (BluetoothAim.ins)
 
-         {
 
-             if (bluetoothPlayer == BluetoothPlayer.FIRST_PLAYER)
 
-             {
 
-                 if (BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess)
 
-                 {
 
-                     //if (!connected.activeSelf) connected.SetActive(true);
 
-                     //if (unConnected.activeSelf) unConnected.SetActive(false);
 
-                     //连接后,更新电池状态
 
-                     if (countingTime1 < 5)
 
-                     {
 
-                         countingTime1 += Time.deltaTime;
 
-                     }
 
-                     else
 
-                     {
 
-                         countingTime1 = 0;
 
-                         RenderBattery(DeviceBatteryView.ins.batteryDeviceID, DeviceBatteryView.ins.batteryValue);
 
-                     }
 
-                 }
 
-                 else if (BluetoothAim.ins.status != BluetoothStatusEnum.Connecting) //BluetoothAim.ins.status == BluetoothStatusEnum.ConnectFail
 
-                 {
 
-                     //如果连接失败,重置一下状态
 
-                     onShowDeviceInfo();
 
-                     RenderBattery(-1, 0);
 
-                 }
 
-                 else
 
-                 {
 
-                     //连接状态或者正在连接等
 
-                     RenderBattery(-1, 0);
 
-                     onShowDeviceInfo();
 
-                 }
 
-             }
 
-             else if (bluetoothPlayer == BluetoothPlayer.SECONDE_PLAYER)
 
-             {
 
-                 SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
 
-                 if (smartBowHelper == null) return;
 
-                 SmartBowSDK.BluetoothStatusEnum bluetoothStatusEnum = smartBowHelper.GetBluetoothStatus();
 
-                 //Debug.Log(bluetoothStatusEnum);
 
-                 if (bluetoothStatusEnum == SmartBowSDK.BluetoothStatusEnum.Connected)
 
-                 {
 
-                     //if (!connected.activeSelf) connected.SetActive(true);
 
-                     //if (unConnected.activeSelf) unConnected.SetActive(false);
 
-                     //连接后,更新电池状态
 
-                     if (countingTime1 < 5)
 
-                     {
 
-                         countingTime1 += Time.deltaTime;
 
-                     }
 
-                     else
 
-                     {
 
-                         countingTime1 = 0;
 
-                         RenderBattery(-1, BluetoothAim.ins.getSmartBowHelper2P().GetBattery());
 
-                     }
 
-                 }
 
-                 else if (bluetoothStatusEnum != SmartBowSDK.BluetoothStatusEnum.Connecting)//bluetoothStatusEnum == SmartBowSDK.BluetoothStatusEnum.None
 
-                 {
 
-                     //如果连接失败,重置一下状态
 
-                     onShowDeviceInfo();
 
-                     RenderBattery(-1, 0);
 
-                 }
 
-                 else
 
-                 {
 
-                     //连接状态或者正在连接等
 
-                     RenderBattery(-1, 0);
 
-                     onShowDeviceInfo();
 
-                 }
 
-             }
 
-             if (connected.activeSelf) onUpdateStatusInfo();
 
-         }
 
-         //如果存在连接信息
 
-         if (bShowInfo)
 
-         {
 
-             if (unConnected.activeSelf) unConnected.SetActive(false);
 
-             if (!connected.activeSelf) connected.SetActive(true);
 
-         }
 
-         else
 
-         {
 
-             if (!unConnected.activeSelf) unConnected.SetActive(true);
 
-             if (connected.activeSelf) connected.SetActive(false);
 
-         }
 
-     }
 
-     void RequestBatteryForBow()
 
-     {
 
-         try
 
-         {
 
-             if (BluetoothAim.ins.hasData && JCUnityLib.TimeUtils.GetTimestamp() - BluetoothAim.ins.hasDataTime > 5000)
 
-             {
 
-                 BluetoothAim.ins.RequestBattery();
 
-             }
 
-         }
 
-         catch (Exception) { }
 
-     }
 
-     public void RenderBattery(int deviceID, int value)
 
-     {
 
-         //if (!bettery.activeSelf) bettery.SetActive(true);
 
-         Image img = betteryBar.GetComponent<Image>();
 
-         Text txt = betteryValue.GetComponent<Text>();
 
-         img.fillAmount = value / 100f;
 
-         txt.text = value + "%";
 
-     }
 
-     public void onShowDeviceInfo()
 
-     {
 
-         //判断是否存在当前对象
 
-         List<AimDeviceInfo> allDeviceInfo = AimHandler.ins.aimDeviceInfos.arry;
 
-         AimDeviceInfo aimDeviceInfo = allDeviceInfo.Find(obj => obj.id == deviceIndex);
 
-         //对象不存在
 
-         if (aimDeviceInfo == null || aimDeviceInfo.type == -1 || !aimDeviceInfo.bInitMac)//AimHandler.ins.aimDeviceInfos.arry.Count <= deviceIndex
 
-         {
 
-             if (!unConnected.activeSelf) unConnected.SetActive(true);
 
-             if (connected.activeSelf) connected.SetActive(false);
 
-             return;
 
-         }
 
-         //Debug.Log("show aimDeviceInfo:" +  aimDeviceInfo.id + ", deviceSelectIndex:" + deviceIndex);
 
-         //AimDeviceInfo aimDeviceInfo = AimHandler.ins.aimDeviceInfos.arry[deviceIndex];
 
-         bShowInfo = true;
 
-         switch ((AimDeviceType)aimDeviceInfo.type)
 
-         {
 
-             case AimDeviceType.HOUYI:
 
-                 titleText.text = "HOUYI";
 
-                 bowBg.sprite = bowBgs[0];
 
-                 break;
 
-             case AimDeviceType.HOUYI2:
 
-                 titleText.text = "HOUYI 2";
 
-                 bowBg.sprite = bowBgs[0];
 
-                 break;
 
-             case AimDeviceType.ARTEMIS:
 
-                 titleText.text = "ARTEMIS";
 
-                 bowBg.sprite = bowBgs[1];
 
-                 break;
 
-             case AimDeviceType.HOUYIPRO:
 
-                 titleText.text = "HOUYI Pro";
 
-                 bowBg.sprite = bowBgs[0];
 
-                 break;
 
-             case AimDeviceType.Gun:
 
-                 titleText.text = "Pistol";
 
-                 bowBg.sprite = gunBgs[0];
 
-                 break;
 
-             case AimDeviceType.ARTEMISPRO:
 
-                 titleText.text = "ARTEMIS Pro";
 
-                 bowBg.sprite = bowBgs[1];
 
-                 break;
 
-             default:
 
-                 bShowInfo = false;
 
-                 // Debug.LogWarning("onShowDeviceInfo 没有对应设备 AimDeviceType:" + ((AimDeviceType)aimDeviceInfo.type).ToString());
 
-                 break;
 
-         }
 
-         //onUpdateStatusInfo();
 
-     }
 
-     //刷新状态
 
-     public void onUpdateStatusInfo()
 
-     {
 
-         if (bluetoothPlayer == BluetoothPlayer.FIRST_PLAYER)
 
-         {
 
-             string name = BluetoothStatus.GetStatusTextKey(BluetoothAim.ins.status);
 
-             if (name != _TextAutoLanguage2.GetTextKey())
 
-                 _TextAutoLanguage2.SetTextKey(name);
 
-         }
 
-         else if (bluetoothPlayer == BluetoothPlayer.SECONDE_PLAYER)
 
-         {
 
-             SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
 
-             if (smartBowHelper == null) return;
 
-             string name = BluetoothStatus.GetBLE2StatusTextKey(smartBowHelper.GetBluetoothStatus());
 
-             if (name != _TextAutoLanguage2.GetTextKey())
 
-                 _TextAutoLanguage2.SetTextKey(name);
 
-         }
 
-     }
 
-     //设置一个面板选择状态
 
-     public void setPanelStatus(bool _active)
 
-     {
 
-         selectPanel.enabled = _active;
 
-         if (_active)
 
-         {
 
-             //赋值一下当前选择的对象
 
-             DeviceViewInfrared.ins.selectDeviceViewItem = this;
 
-             //选择框选择到的当前蓝牙用户
 
-             BluetoothAim.ins.setBLEPlayer(bluetoothPlayer);
 
-             Debug.Log("当前选择的操作蓝牙用户:" + BluetoothAim.ins.getBLEPlayer());
 
-             //true的情况下设置index
 
-             AimHandler.ins.SetAimDeviceSelectIndex(deviceIndex);
 
-             Debug.Log("当前选择的操作蓝牙用户 deviceSelectIndex:" + deviceIndex);
 
-         }
 
-     }
 
-     public bool getPanelStatus()
 
-     {
 
-         bool _enable = selectPanel.enabled;
 
-         //设置一次
 
-         DeviceViewInfrared.ins.OnCloseAllPanelStatus();
 
-         setPanelStatus(true);
 
-         return _enable;
 
-     }
 
-     public bool getCurrentPanelEnable()
 
-     {
 
-         return selectPanel.enabled;
 
-     }
 
-     public bool getBLEConnectState() {
 
-         if (bluetoothPlayer == BluetoothPlayer.FIRST_PLAYER) {
 
-             return BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess;
 
-         }
 
-         else if (bluetoothPlayer == BluetoothPlayer.SECONDE_PLAYER)
 
-         {
 
-             SmartBowSDK.SmartBowHelper smartBowHelper = BluetoothAim.ins.getSmartBowHelper2P();
 
-             if (smartBowHelper == null) return false;
 
-             SmartBowSDK.BluetoothStatusEnum bluetoothStatusEnum = smartBowHelper.GetBluetoothStatus();
 
-             return bluetoothStatusEnum == SmartBowSDK.BluetoothStatusEnum.Connected;
 
-         }else   return false;
 
-     }
 
-     /// <summary>
 
-     /// 蓝牙连接事件,连接和断开连接
 
-     /// </summary>
 
-     public void OnConnectedEvent()
 
-     {
 
-         //要选中情况下,才能进行下一步操作
 
-         if (!getPanelStatus()) return;
 
-         AimHandler.ins.SetAimDeviceSelectIndex(deviceIndex);
 
-         AimHandler.ins.onCreateAimDeviceInfoById();
 
-         Debug.Log("DeviceView_ItemShow bluetoothPlayer:" + bluetoothPlayer);
 
-         if (BluetoothAim.ins && BluetoothAim.ins.status == BluetoothStatusEnum.ConnectSuccess)
 
-         {
 
-             //断开连接
 
-             if (bluetoothPlayer == BluetoothPlayer.FIRST_PLAYER)
 
-             {
 
-                 BluetoothAim.ins.DoConnect();
 
-             }
 
-             else
 
-             {
 
-                 BluetoothAim.ins.DoConnect2P();
 
-             }
 
-             return;
 
-         }
 
-         if (HomeView.ShowProminentBeforeConnectBLE()) return;
 
-         if (bluetoothPlayer == BluetoothPlayer.FIRST_PLAYER)
 
-         {
 
-             BluetoothAim.ins.DoConnect();
 
-         }
 
-         else
 
-         {
 
-             BluetoothAim.ins.DoConnect2P();
 
-         }
 
-     }
 
-     /// <summary>
 
-     /// 选择事件
 
-     /// </summary>
 
-     public void OnSelectEvent() {
 
-         //如果是选中的状态,不再触发
 
-         if (getCurrentPanelEnable()) return;
 
-         AudioMgr.ins.PlayBtn();
 
-         AimHandler.ins.SetAimDeviceSelectIndex(deviceIndex);
 
-         DeviceViewInfrared.ins.OnCloseAllPanelStatus();
 
-         setPanelStatus(true);
 
-     }
 
-     /// <summary>
 
-     /// 如果有选择到并且显示的话
 
-     /// </summary>
 
-     /// <returns></returns>
 
-     public bool getCurrentItemVisible()
 
-     {
 
-         return selectPanel.enabled && bShowInfo;
 
-     }
 
- }
 
 
  |