| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- using AppUI.Bluetooth;
- using AppUI.Manager.View;
- using AppUI.View.Component;
- using SmartBowSDK;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- namespace AppUI.View.Home.DeviceView
- {
- public class DeviceListView : MonoBehaviour
- {
- public enum DeviceCategory
- {
- Bow,
- Gun
- }
- [System.Serializable]
- public class DeviceItemData
- {
- [Header("设备类型")]
- public AimDeviceType aimDeviceType;
- [Header("分类")]
- public DeviceCategory category;
- [Header("按钮")]
- public Button button;
- [Header("是否需要解密")]
- public bool needDecryption;
- [Header("是否红外引导")]
- public bool infraredGuide;
- }
- [Header("设备列表")]
- [SerializeField]
- List<DeviceItemData> deviceItems;
- [Header("分类")]
- public DeviceCategory category;
- [SerializeField]
- Sprite[] arrowImages;
- [SerializeField]
- Material lineMaterial;
- Material materialGrey;
- Material materialGreen;
- void Start()
- {
- materialGrey = Instantiate(lineMaterial);
- materialGreen = Instantiate(lineMaterial);
- materialGreen.SetColor("_BorderColor",
- new Color32(16, 194, 198, 255));
- for (int i = 0; i < deviceItems.Count; i++)
- {
- int temp = i;
- var item = deviceItems[i];
- // B端隐藏弓箭设备
- if (CommonConfig.StandaloneModeOrPlatformB &&
- item.category == DeviceCategory.Bow)
- {
- item.button.gameObject.SetActive(false);
- continue;
- }
- item.button.onClick.AddListener(() =>
- {
- AudioMgr.ins.PlayBtn();
- OnSelectDevice(temp);
- });
- }
- }
- void OnSelectDevice(int index)
- {
- bool selected = false;
- for (int i = 0; i < deviceItems.Count; i++)
- {
- var item = deviceItems[i];
- Button button = item.button;
- bool isCurrent = (i == index);
- Color32 titleColor;
- if (isCurrent)
- {
- selected = true;
- SmartBowDeviceHub hub = SmartBowDeviceHub.ins;
- BluetoothPlayer player = hub.GetActivePlayer();
- hub.Aim.OverwriteAimDeviceInfoForPlayer(player, item.aimDeviceType);
- titleColor = new Color32(16, 194, 198, 255);
- button.transform.Find("right/arrow")
- .GetComponent<Image>()
- .sprite = arrowImages[1];
- button.GetComponent<Image>().material =
- materialGreen;
- }
- else
- {
- titleColor = new Color32(0, 0, 0, 255);
- button.transform.Find("right/arrow")
- .GetComponent<Image>()
- .sprite = arrowImages[0];
- button.GetComponent<Image>().material =
- materialGrey;
- }
- button.transform.Find("right/title")
- .GetComponent<Text>()
- .color = titleColor;
- }
- if (!selected)
- return;
- var current = deviceItems[index];
- SmartBowDeviceHub.ins.NeedDecryption =
- current.needDecryption;
- AudioMgr.ins.PlayBtn();
- DeviceView.Active?.EndDeviceSelectionFlow();
- ModuleSideSlip.Show(guideDeviceType: current.aimDeviceType);
- //if (current.infraredGuide)
- //{
- // GameObject connectGuidanceView =
- // ViewManager2.getGameObjectAndShowView(
- // ViewManager2.Path_ConnectGuidanceView);
- // connectGuidanceView
- // .GetComponent<ConnectGuidanceView>()
- // .showTextipInfrared();
- //}
- //else
- //{
- // ViewManager2.ShowView(
- // ViewManager2.Path_ConnectGuidanceView);
- //}
- }
- public void OnChangeSmartArcheryButtonState(int index)
- {
- for (int i = 0; i < deviceItems.Count; i++)
- {
- var item = deviceItems[i];
- Button button = item.button;
- bool isCurrent = (i == index);
- Color32 titleColor;
- if (isCurrent)
- {
- SmartBowDeviceHub.ins.Aim.SetTempAimDeviceType(
- item.aimDeviceType);
- titleColor = new Color32(16, 194, 198, 255);
- button.transform.Find("right/arrow")
- .GetComponent<Image>()
- .sprite = arrowImages[1];
- button.GetComponent<Image>().material =
- materialGreen;
- }
- else
- {
- titleColor = new Color32(0, 0, 0, 255);
- button.transform.Find("right/arrow")
- .GetComponent<Image>()
- .sprite = arrowImages[0];
- button.GetComponent<Image>().material =
- materialGrey;
- }
- button.transform.Find("right/title")
- .GetComponent<Text>()
- .color = titleColor;
- }
- }
- public void OnClick_Back()
- {
- Debug.Log("DeviceListView OnClick_Back");
- AudioMgr.ins.PlayBtn();
- DeviceView.Active?.EndDeviceSelectionFlow();
- DeviceView.Active?.RefreshConnectContent(force: true);
- if (category == DeviceCategory.Bow)
- {
- ViewManager.HideView(UIViewType.DeviceArcheryView);
- }
- else {
- ViewManager.HideView(UIViewType.DeviceGunView);
- }
- }
- }
- }
|