| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797 |
- using DragonBones;
- using SmartBowSDK;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- using SdkAimDeviceInfo = SmartBowSDK.AimDeviceInfo;
- namespace AppUI.Bluetooth
- {
- /// <summary>
- /// AppUI 瞄准处理器:设备信息本地维护,九轴/校准走 SmartBowSDK(Axis9Handler_SDK)。
- /// </summary>
- public class AimHandler : MonoBehaviour
- {
- CameraToLook m_controlObj => CameraToLook.ins;
- #region 设备信息(MAC 走 SDK AimDeviceInfo;型号走 PlayerDeviceTypeStore)
- public const string SdkUserTags = "smartbow";
- /// <summary>当前 SideSlip / 连接上下文使用的玩家槽位(0=1P,1=2P)。</summary>
- int deviceSelectIndex;
- /// <summary>与 SDK 同步的当前槽位档案(只读用途请用 <see cref="GetAimDeviceInfo"/>)。</summary>
- public SdkAimDeviceInfo aimDeviceInfo;
- int _tempDeviceType = -1;
- public Action aimDeviceInfoChangeEvent;
- public static int GetSdkDeviceId(BluetoothPlayer player) =>
- player == BluetoothPlayer.SECOND_PLAYER ? 2 : 1;
- public static int GetSdkDeviceId(int playerIndex) =>
- playerIndex == (int)BluetoothPlayer.SECOND_PLAYER ? 2 : 1;
- static string SdkPrefsKey(int sdkDeviceId) => "aim-device-info-" + SdkUserTags + sdkDeviceId;
- SmartBowHelper GetHelperForPlayer(BluetoothPlayer player)
- {
- if (Ble == null) return null;
- return player == BluetoothPlayer.SECOND_PLAYER
- ? Ble.getSmartBowHelper2P()
- : Ble.getSmartBowHelper1P();
- }
- SdkAimDeviceInfo LoadSdkDeviceInfoFromPrefs(int sdkDeviceId)
- {
- string json = PlayerPrefs.GetString(SdkPrefsKey(sdkDeviceId), "");
- if (string.IsNullOrEmpty(json))
- return null;
- return JsonUtility.FromJson<SdkAimDeviceInfo>(json);
- }
- void SaveSdkDeviceInfo(SdkAimDeviceInfo info, int sdkDeviceId)
- {
- if (info == null) return;
- PlayerPrefs.SetString(SdkPrefsKey(sdkDeviceId), JsonUtility.ToJson(info));
- }
- public void onClearAimDeviceInfosNew()
- {
- GetHelperForPlayer(BluetoothPlayer.FIRST_PLAYER)?.ClearDeviceInfo(SdkUserTags, 1);
- GetHelperForPlayer(BluetoothPlayer.SECOND_PLAYER)?.ClearDeviceInfo(SdkUserTags, 2);
- PlayerPrefs.DeleteKey(SdkPrefsKey(1));
- PlayerPrefs.DeleteKey(SdkPrefsKey(2));
- PlayerDeviceTypeStore.ClearAll();
- aimDeviceInfo = null;
- aimDeviceInfoChangeEvent?.Invoke();
- }
- public void onClear2PAimDeviceInfosNew()
- {
- GetHelperForPlayer(BluetoothPlayer.SECOND_PLAYER)?.ClearDeviceInfo(SdkUserTags, 2);
- PlayerPrefs.DeleteKey(SdkPrefsKey(2));
- PlayerDeviceTypeStore.ClearPlayer(BluetoothPlayer.SECOND_PLAYER);
- aimDeviceInfoChangeEvent?.Invoke();
- }
- public void OnGetAimDeviceInfos()
- {
- if (deviceSelectIndex >= 0)
- aimDeviceInfo = GetAimDeviceInfo((BluetoothPlayer)deviceSelectIndex);
- aimDeviceInfoChangeEvent?.Invoke();
- }
- public void OnSaveAimDeviceInfos()
- {
- if (aimDeviceInfo != null)
- SaveSdkDeviceInfo(aimDeviceInfo, aimDeviceInfo.id);
- aimDeviceInfoChangeEvent?.Invoke();
- }
- public void onCreateTempAimDeviceInfo()
- {
- _tempDeviceType = -1;
- Debug.Log("onCreateTempAimDeviceInfo deviceSelectIndex:" + deviceSelectIndex);
- }
- public int GetTempDeviceType() => _tempDeviceType;
- public void onCreateAimDeviceInfoById()
- {
- BluetoothPlayer player = (BluetoothPlayer)deviceSelectIndex;
- int sdkDeviceId = GetSdkDeviceId(player);
- aimDeviceInfo = GetAimDeviceInfo(player);
- if (aimDeviceInfo == null)
- {
- aimDeviceInfo = new SdkAimDeviceInfo(sdkDeviceId);
- SaveSdkDeviceInfo(aimDeviceInfo, sdkDeviceId);
- }
- aimDeviceInfoChangeEvent?.Invoke();
- }
- public void SetAimDeviceSelectIndex(int selectIndex)
- {
- if (selectIndex < 0)
- {
- Debug.LogWarning("selectIndex不能小于0:" + selectIndex);
- return;
- }
- deviceSelectIndex = selectIndex;
- }
- public void SetTempAimDeviceType(AimDeviceType _aimDeviceType) => _tempDeviceType = (int)_aimDeviceType;
- public void SetAimDeviceType(AimDeviceType _aimDeviceType) => SetAimDeviceType((int)_aimDeviceType);
- public void SetAimDeviceType(int _aimDeviceType)
- {
- BluetoothPlayer player = (BluetoothPlayer)deviceSelectIndex;
- PlayerDeviceTypeStore.SetType(player, _aimDeviceType);
- aimDeviceInfoChangeEvent?.Invoke();
- }
- public int GetDeviceType(BluetoothPlayer player) => PlayerDeviceTypeStore.GetType(player);
- public int GetActivePlayerDeviceType()
- {
- BluetoothPlayer player = BluetoothPlayer.FIRST_PLAYER;
- if (Ble != null)
- player = Ble.getBLEPlayer();
- return GetDeviceType(player);
- }
- public void SetAimDeviceMac(string _mac)
- {
- BluetoothPlayer player = BluetoothPlayer.FIRST_PLAYER;
- if (Ble != null)
- player = Ble.getBLEPlayer();
- else if (deviceSelectIndex >= 0)
- player = (BluetoothPlayer)deviceSelectIndex;
- int sdkDeviceId = GetSdkDeviceId(player);
- SdkAimDeviceInfo info = GetAimDeviceInfo(player);
- if (info == null)
- info = new SdkAimDeviceInfo(sdkDeviceId);
- info.setInitMac(_mac);
- SaveSdkDeviceInfo(info, sdkDeviceId);
- if (deviceSelectIndex == (int)player)
- aimDeviceInfo = info;
- aimDeviceInfoChangeEvent?.Invoke();
- }
- public void ResetAimDeviceMac()
- {
- BluetoothPlayer player = BluetoothPlayer.FIRST_PLAYER;
- if (Ble != null)
- player = Ble.getBLEPlayer();
- else if (deviceSelectIndex >= 0)
- player = (BluetoothPlayer)deviceSelectIndex;
- int sdkDeviceId = GetSdkDeviceId(player);
- SdkAimDeviceInfo info = GetAimDeviceInfo(player);
- if (info == null)
- return;
- info.resetInitMac();
- SaveSdkDeviceInfo(info, sdkDeviceId);
- if (deviceSelectIndex == (int)player)
- aimDeviceInfo = info;
- aimDeviceInfoChangeEvent?.Invoke();
- }
- /// <summary>侧滑连接是否为「切换设备页选型覆盖」;false 表示直接连接,沿用已记录 MAC。</summary>
- bool _sideSlipOverwritesDeviceInfo;
- public bool SideSlipOverwritesDeviceInfo => _sideSlipOverwritesDeviceInfo;
- public void ClearSideSlipOverwriteFlag() => _sideSlipOverwritesDeviceInfo = false;
- public void OverwriteAimDeviceInfoForPlayer(BluetoothPlayer player, AimDeviceType deviceType)
- {
- SetAimDeviceSelectIndex((int)player);
- int sdkDeviceId = GetSdkDeviceId(player);
- SdkAimDeviceInfo info = GetAimDeviceInfo(player);
- if (info == null)
- {
- info = new SdkAimDeviceInfo(sdkDeviceId);
- }
- info.resetInitMac();
- SaveSdkDeviceInfo(info, sdkDeviceId);
- PlayerDeviceTypeStore.SetType(player, (int)deviceType);
- aimDeviceInfo = info;
- _tempDeviceType = (int)deviceType;
- _sideSlipOverwritesDeviceInfo = true;
- aimDeviceInfoChangeEvent?.Invoke();
- }
- public void PrepareDirectSideSlipConnect(int selectIndex)
- {
- SetAimDeviceSelectIndex(selectIndex);
- onCreateAimDeviceInfoById();
- _sideSlipOverwritesDeviceInfo = false;
- }
- public SdkAimDeviceInfo GetAimDeviceInfo(BluetoothPlayer player)
- {
- int sdkDeviceId = GetSdkDeviceId(player);
- SmartBowHelper helper = GetHelperForPlayer(player);
- if (helper != null)
- {
- SdkAimDeviceInfo info = helper.GetDeviceInfo(SdkUserTags, sdkDeviceId);
- if (info != null)
- return info;
- }
- return LoadSdkDeviceInfoFromPrefs(sdkDeviceId);
- }
- public bool isHOUYIPRO(BluetoothPlayer bluetoothPlayer) =>
- GetDeviceType(bluetoothPlayer) == (int)AimDeviceType.HOUYIPRO;
- public bool isARTEMISPro(BluetoothPlayer bluetoothPlayer) =>
- GetDeviceType(bluetoothPlayer) == (int)AimDeviceType.ARTEMISPRO;
- #endregion
- public int DeviceType => 9;
- [NonSerialized] public int gyrCalibrateCompleteCount;
- [NonSerialized] public int gyrCalibrateTotalCount = 2000;
- public bool bInitOne;
- public OnCrossBtnEventEvent OnCrossBtnEvent;
- public delegate void OnCrossBtnEventEvent();
- SmartBowHelper _boundSdk1P;
- SmartBowHelper _lastPollSdk;
- int _sdkAxisReadyAfterFrame = -1;
- bool _magCompleted;
- [NonSerialized] public bool lerpForRotation = true;
- [NonSerialized] public float lerpTimeRate = 7;
- Quaternion _targetRotation = Quaternion.identity;
- BluetoothAim Ble => SmartBowDeviceHub.ins?.Ble;
- void OnDestroy()
- {
- UnbindSdk1P();
- }
- public void InvokeOnCrossBtnEvent()
- {
- try { OnCrossBtnEvent?.Invoke(); }
- catch (Exception e) { Debug.LogError(e); }
- }
- #region SDK 绑定(1P 数据由 SmartBowHelper / Axis9Handler_SDK 处理)
- public void BindSdk1P(SmartBowHelper helper)
- {
- if (helper == null) return;
- if (_boundSdk1P == helper) return;
- UnbindSdk1P();
- _boundSdk1P = helper;
- helper.OnShooting += OnShot1P;
- helper.OnBleDeviceState += HandleUpdateTheMagazine;
- helper.OnRotationUpdate += OnSdkRotationUpdate;
- helper.OnFunctionKeyPress += OnSdkFunctionKeyShortPress;
- helper.OnFunctionKeyLongPress += OnSdkFunctionKeyLongPress;
- helper.OnDeviceAndSystemInfoEvent += HandleDeviceAndSystemInfo;
- MarkSdkAxisPending(helper);
- }
- public void UnbindSdk1P()
- {
- if (_boundSdk1P == null) return;
- _boundSdk1P.OnShooting -= OnShot1P;
- _boundSdk1P.OnBleDeviceState -= HandleUpdateTheMagazine;
- _boundSdk1P.OnRotationUpdate -= OnSdkRotationUpdate;
- _boundSdk1P.OnFunctionKeyPress -= OnSdkFunctionKeyShortPress;
- _boundSdk1P.OnFunctionKeyLongPress -= OnSdkFunctionKeyLongPress;
- _boundSdk1P.OnDeviceAndSystemInfoEvent -= HandleDeviceAndSystemInfo;
- _boundSdk1P = null;
- }
- SmartBowHelper GetSdk1P()
- {
- if (_boundSdk1P != null) return _boundSdk1P;
- return SmartBowDeviceHub.ins?.Ble?.getSmartBowHelper1P();
- }
- SmartBowHelper GetSdkForCalibration()
- {
- BluetoothAim ble = Ble;
- if (ble == null) return GetSdk1P();
- if (ble.getBLEPlayer() == BluetoothPlayer.SECOND_PLAYER)
- return ble.getSmartBowHelper2P();
- return GetSdk1P();
- }
- void OnSdkRotationUpdate(Quaternion rotation)
- {
- _targetRotation = rotation;
- if (!bRuning9Axis()) return;
-
- if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked)
- SB_EventSystem.ins.MoveSimulateMouse(rotation);
- if (m_controlObj == null) return;
- if (lerpForRotation)
- m_controlObj.localRotation = Quaternion.Lerp(m_controlObj.localRotation, rotation, Time.deltaTime * lerpTimeRate);
- else
- m_controlObj.localRotation = rotation;
-
- }
- void OnSdkFunctionKeyShortPress() => HandleFunctionKeyShortPress();
- void OnSdkFunctionKeyLongPress() => HandleFunctionKeyLongPress();
- #endregion
- #region 九轴 / 校准(委托 SDK,不再使用本地 Axis9Handler)
- public void ReinitAxisHandler()
- {
- if (!UsesNineAxisDevice())
- return;
- Debug.Log("[AppUI.AimHandler] 九轴设备 HOUYI/HOUYI2/ARTEMIS,旋转与校准走 SDK Axis9Handler。");
- }
- public void SetMsOldDefault() { }
- public void DoIdentity()
- {
- GetSdkForCalibration()?.ResetAim();
- if (!bRuning9Axis()) return;
- if (m_controlObj) m_controlObj.localRotation = _targetRotation;
- }
- public void NotifyAxisOnShot() { }
- public void CalibrateGyr(bool calibration)
- {
- if (!UsesNineAxisDevice()) return;
- var sdk = GetSdkForCalibration();
- if (sdk == null || !CanPollSdkAxisCalibration(sdk)) return;
- if (calibration) sdk.StartGyrCalibration();
- else sdk.StopGyrCalibration();
- }
- public void InitGyr(string record) { }
- public void InitMag(string record) { }
- public void ResetGyr()
- {
- if (!UsesNineAxisDevice()) return;
- var sdk = GetSdkForCalibration();
- if (sdk == null || !CanPollSdkAxisCalibration(sdk)) return;
- sdk.StopGyrCalibration();
- }
- public void ResetMag()
- {
- if (!UsesNineAxisDevice()) return;
- TryStartMagCalibration();
- }
- public void ApplyImpreciseMag() { }
- public bool IsGyrCompleted()
- {
- if (!UsesNineAxisDevice()) return false;
- var sdk = GetSdkForCalibration();
- return sdk != null && CanPollSdkAxisCalibration(sdk) && sdk.IsGyrCompleted();
- }
- public bool IsMagCompleted()
- {
- if (!UsesNineAxisDevice()) return false;
- var sdk = GetSdkForCalibration();
- return sdk != null && CanPollSdkAxisCalibration(sdk) && sdk.IsMagCompleted();
- }
- public bool IsGyrCalibrating()
- {
- if (!UsesNineAxisDevice()) return false;
- var sdk = GetSdkForCalibration();
- return sdk != null && CanPollSdkAxisCalibration(sdk) && sdk.IsGyrCalibrating();
- }
- public int GetGyrProgressPercent()
- {
- if (!UsesNineAxisDevice()) return 0;
- var sdk = GetSdkForCalibration();
- if (sdk == null || !CanPollSdkAxisCalibration(sdk)) return 0;
- return Mathf.Clamp(Mathf.FloorToInt(sdk.GetGyrProgress() * 100f), 0, 100);
- }
- /// <summary>校准页专用:仅校验 SDK 连接与轮询就绪,不重复判断设备档案类型。</summary>
- public bool IsSdkGyrCompleted()
- {
- var sdk = GetSdkForCalibration();
- return sdk != null && CanPollSdkAxisCalibration(sdk) && sdk.IsGyrCompleted();
- }
- /// <summary>校准页专用:仅校验 SDK 连接与轮询就绪,不重复判断设备档案类型。</summary>
- public bool IsSdkMagCompleted()
- {
- var sdk = GetSdkForCalibration();
- return sdk != null && CanPollSdkAxisCalibration(sdk) && sdk.IsMagCompleted();
- }
- public bool TryStartMagCalibration()
- {
- var sdk = GetSdkForCalibration();
- if (sdk == null || !CanPollSdkAxisCalibration(sdk))
- return false;
- sdk.StartMagCalibration();
- return true;
- }
- /// <summary>对齐 DemoStarter.OnClick_CalibrateGyr:校准中则停止,否则开始。</summary>
- public bool TryToggleGyrCalibration()
- {
- var sdk = GetSdkForCalibration();
- if (sdk == null || !CanPollSdkAxisCalibration(sdk))
- return false;
- if (sdk.IsGyrCalibrating())
- sdk.StopGyrCalibration();
- else
- sdk.StartGyrCalibration();
- return true;
- }
- public bool TryStopGyrCalibration()
- {
- var sdk = GetSdkForCalibration();
- if (sdk == null || !CanPollSdkAxisCalibration(sdk))
- return false;
- sdk.StopGyrCalibration();
- return true;
- }
- public bool IsSdkGyrCalibrating()
- {
- var sdk = GetSdkForCalibration();
- return sdk != null && CanPollSdkAxisCalibration(sdk) && sdk.IsGyrCalibrating();
- }
- public int GetSdkGyrProgressPercent()
- {
- var sdk = GetSdkForCalibration();
- if (sdk == null || !CanPollSdkAxisCalibration(sdk)) return 0;
- return Mathf.Clamp(Mathf.FloorToInt(sdk.GetGyrProgress() * 100f), 0, 100);
- }
- public IEnumerator SaveGyr()
- {
- yield return null;
- }
- public IEnumerator SaveMag()
- {
- yield return null;
- }
- public void ResumeCalibrateRecord(string record)
- {
- if (string.IsNullOrEmpty(record)) return;
- GetSdkForCalibration()?.ResumeCalibrateRecord(record);
- }
- public void CorrectMagCompleted(bool value) { _magCompleted = value; }
- public void Ban9AxisCalculate(bool ban) { }
- public bool bRuning9Axis()
- {
- return GlobalData.MyDeviceMode == DeviceMode.Archery
- && Ble != null
- && !Ble.isMainConnectToInfraredDevice()
- && UsesNineAxisDevice();
- }
- /// <summary>HOUYI / HOUYI2 / ARTEMIS 走九轴;Pro/枪等不走本地九轴校准轮询。</summary>
- public bool UsesNineAxisDevice()
- {
- BluetoothPlayer player = BluetoothPlayer.FIRST_PLAYER;
- if (Ble != null && Ble.getBLEPlayer() == BluetoothPlayer.SECOND_PLAYER)
- player = BluetoothPlayer.SECOND_PLAYER;
- return IsNineAxisArcheryType(GetDeviceType(player));
- }
- static bool IsNineAxisArcheryType(int type)
- {
- return type == (int)AimDeviceType.HOUYI
- || type == (int)AimDeviceType.HOUYI2
- || type == (int)AimDeviceType.ARTEMIS;
- }
- public static bool IsInfraredDeviceType(int type)
- {
- return type == (int)AimDeviceType.HOUYIPRO
- || type == (int)AimDeviceType.Gun
- || type == (int)AimDeviceType.ARTEMISPRO
- || type == (int)AimDeviceType.PistolM17
- || type == (int)AimDeviceType.RifleM416;
- }
- public bool IsActivePlayerInfraredDevice() =>
- IsInfraredDeviceType(GetActivePlayerDeviceType());
- public bool IsActivePlayerNineAxisDevice() =>
- IsNineAxisArcheryType(GetActivePlayerDeviceType());
- public SdkAimDeviceInfo GetActivePlayerAimDeviceInfo()
- {
- BluetoothPlayer player = BluetoothPlayer.FIRST_PLAYER;
- if (Ble != null)
- player = Ble.getBLEPlayer();
- SdkAimDeviceInfo info = GetAimDeviceInfo(player);
- if (info == null && aimDeviceInfo != null && aimDeviceInfo.id == GetSdkDeviceId(player))
- return aimDeviceInfo;
- return info;
- }
- void MarkSdkAxisPending(SmartBowHelper sdk)
- {
- if (sdk == null) return;
- _lastPollSdk = sdk;
- _sdkAxisReadyAfterFrame = Time.frameCount;
- }
- bool CanPollSdkAxisCalibration(SmartBowHelper sdk)
- {
- if (sdk == null) return false;
- if (sdk.GetBluetoothStatus() != SmartBowSDK.BluetoothStatusEnum.Connected)
- return false;
- // AimHandler_SDK 在 Start 里 new Axis9Handler_SDK,同帧调用会 NRE
- return _sdkAxisReadyAfterFrame < 0 || Time.frameCount > _sdkAxisReadyAfterFrame;
- }
- #endregion
- void Update()
- {
- if (!UsesNineAxisDevice())
- {
- _magCompleted = false;
- return;
- }
- var sdk = GetSdkForCalibration();
- if (sdk == null)
- {
- _magCompleted = false;
- return;
- }
- if (sdk != _lastPollSdk)
- MarkSdkAxisPending(sdk);
- if (!CanPollSdkAxisCalibration(sdk))
- return;
- if (sdk.IsGyrCalibrating())
- gyrCalibrateCompleteCount = (int)(sdk.GetGyrProgress() * gyrCalibrateTotalCount);
- if (IsMagCompleted())
- {
- if (!_magCompleted)
- {
- StartCoroutine(SaveMag());
- PopupMgr.ins?.ShowTipTop(TextAutoLanguage2.GetTextByKey("tip_mag-calibrate_success"));
- }
- _magCompleted = true;
- }
- else
- {
- _magCompleted = false;
- }
- }
- void HandleDeviceAndSystemInfo(ConnectPlatform connectPlatform, BluetoothDeviceType bleDeviceType)
- {
- var boxUserSettings = FindAnyObjectByType<CustomUIView.BoxUserSettings>();
- switch (bleDeviceType)
- {
- case BluetoothDeviceType.HOUYIPro:
- UserSettings.ins.selectDevicesName = "HOUYI Pro";
- UserSettings.ins.Save();
- boxUserSettings?.OnUpdateClickInfoByName();
- break;
- case BluetoothDeviceType.ARTEMISPro:
- UserSettings.ins.selectDevicesName = "ARTEMIS Pro";
- UserSettings.ins.Save();
- boxUserSettings?.OnUpdateClickInfoByName();
- break;
- case BluetoothDeviceType.PistolM9:
- UserSettings.ins.selectDevicesName = "Pistol M9";
- UserSettings.ins.Save();
- boxUserSettings?.OnUpdateClickInfoByName();
- break;
- }
- }
- //弹夹状态
- public BluetoothDeviceStatus bluetoothDeviceStatus = BluetoothDeviceStatus.MagazineLoading;
- /// <summary>
- /// 0x00 - 弹夹分离 0x01 - 弹夹上膛
- /// </summary>
- /// <param name="bytes"></param>
- void HandleUpdateTheMagazine(BluetoothDeviceType bleDeviceType, BluetoothDeviceStatus gunStatusEnum)
- {
- bluetoothDeviceStatus = gunStatusEnum;
- if (gunStatusEnum == BluetoothDeviceStatus.MagazineLoading)
- {
- //播放上弹夹时候的声音
- AudioMgr.ins.PlayBeLoaded();
- Debug.Log("弹夹上膛");
- if (Billboard.ins)
- {
- Billboard.ins.bulletManager.ResetBullets(); //game
- }
- }
- Ble.InvokeOnBleDevice(bleDeviceType, gunStatusEnum);
- }
- void HandleFunctionKeyShortPress()
- {
- if (bInitOne)
- {
- bInitOne = false;
- if (IsLegacyArcheryType(GetActivePlayerDeviceType()))
- AutoResetView.DoIdentity();
- else
- CrossBtnEvent();
- return;
- }
- if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked)
- {
- if (FindAnyObjectByType<InfraredGuider>() == null)
- DoIdentity();
- if (FindAnyObjectByType<InfraredScreenPositioningView>() != null)
- InvokeOnCrossBtnEvent();
- }
- else
- {
- if (IsLegacyArcheryType(GetActivePlayerDeviceType()))
- AutoResetView.DoIdentity();
- else
- CrossBtnEvent();
- }
- }
- void HandleFunctionKeyLongPress()
- {
- if (GlobalData.MyDeviceMode == DeviceMode.Gun || (Ble != null && Ble.isMainConnectToInfraredDevice()))
- {
- InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
- if (infraredGuider == null)
- AutoResetView.DoIdentity();
- else
- infraredGuider.onLongClickDevice();
- }
- else if (SB_EventSystem.ins)
- {
- SB_EventSystem.ins.AwakenSimulateMouse();
- }
- }
- static bool IsLegacyArcheryType(int type)
- {
- return type == (int)AimDeviceType.NONE
- || type == (int)AimDeviceType.HOUYI
- || type == (int)AimDeviceType.HOUYI2
- || type == (int)AimDeviceType.ARTEMIS;
- }
- void CrossBtnEvent()
- {
- Debug.Log("CrossBtnEvent");
- InvokeOnCrossBtnEvent();
- if (CommonConfig.StandaloneModeOrPlatformB)
- {
- FindAnyObjectByType<InfraredGuider>()?.onClickDevice();
- return;
- }
- if (GameAssistUI.ins)
- {
- InfraredGuider infraredGuider = FindAnyObjectByType<InfraredGuider>();
- if (infraredGuider == null)
- {
- Transform button5 = GameAssistUI.ins.transform.Find("Button5");
- if (button5 != null && button5.gameObject.activeSelf)
- button5.GetComponent<Button>()?.onClick.Invoke();
- else
- {
- bool onlyShow = !CrossHair.ins.GetOnlyShow();
- CrossHair.ins.SetOnlyShow(onlyShow);
- InfraredDemo._ins?.setCrosshairValue(onlyShow);
- }
- }
- else
- {
- infraredGuider.onClickDevice();
- }
- }
- }
- #region 旧逻辑射击触发
- float _lastShootTime;
- void OnShot1P(float shootSpeed)
- {
- if (GlobalData.MyDeviceMode == DeviceMode.Gun)
- {
- if (Time.realtimeSinceStartup - _lastShootTime >= 1)
- {
- _lastShootTime = Time.realtimeSinceStartup;
- if (FindAnyObjectByType<View.Infrared.InfraredScreenPositioningView>() != null)
- InvokeOnCrossBtnEvent();
- }
- }
- if (SB_EventSystem.ins && SB_EventSystem.ins.simulateMouseIsAwaked)
- {
- SB_EventSystem.ins.ClickMouse();
- }
- else if (ArmBow.ins)
- {
- ArmBow.ins.ADS_fire(true);
- }
- else if (DuckHunter.SmartBowController.Instance)
- {
- //野鸭射击
- DuckHunter.SmartBowController.Instance.OnShooting(shootSpeed);
- }
- else if (WildAttack.SmartBowController.Instance)
- {
- //荒野射击
- WildAttack.SmartBowController.Instance.OnShooting(shootSpeed);
- }
- else if (GameController.ins && GameController.ins.GetArmBowDoublePlayer(PlayerType.FirstPlayer) != null)
- {
- //本地双人模式下处理1p,2P 在 BluetoothAim 类处理
- GameController.ins.GetArmBowDoublePlayer(PlayerType.FirstPlayer).ADS_fire(true, shootSpeed);
- }
- else if (GeneratingTarget.gm != null)
- {
- //移动目标
- GeneratingTarget.gm.Shooting(true);
- }
- }
- public void OnShot2P(float speed)
- {
- if (SceneManager.GetActiveScene().name.Equals("WildAttackDouble"))
- {
- WildAttack.SmartBowController.Instance.OnShooting2P(speed);
- }
- else
- {
- if (GameController.ins.GetArmBowDoublePlayer(PlayerType.SecondPlayer) != null)
- {
- //本地双人模式下处理2P ,1P在 ShootCheck 类处理
- GameController.ins.GetArmBowDoublePlayer(PlayerType.SecondPlayer).ADS_fire(true, speed);
- }
- }
- }
- #endregion
- }
- }
|