Эх сурвалжийг харах

1.更新修改意见。
2.更新SmartBowSdk.dll 兼容性问题
3.九轴和红外程序兼容问题处理

slambb 1 жил өмнө
parent
commit
d4a49ddf94

+ 41 - 4
Assets/BowArrow/InfraredCamera/InfraredDemo.cs

@@ -128,6 +128,9 @@ public class InfraredDemo : MonoBehaviour
     //亮度过滤阈值
     public ParamFloatValue infraredFileterValue = new ParamFloatValue("ic_infraredFileterValue", 0.8f);
 
+    //十字准心
+    public ParamFloatValue crosshairValue = new ParamFloatValue("ic_crosshairValue",0);
+
     public static InfraredCameraHelper infraredCameraHelper;
     public static bool running { get => infraredCameraHelper != null; }
     private bool _inited;
@@ -366,6 +369,8 @@ public class InfraredDemo : MonoBehaviour
             infraredCameraHelper.Create();
             infraredCameraHelper.OnPositionUpdate += (Vector2 point) =>
             {
+                //跑九轴时候,不处理这里位置
+                if (AimHandler.ins && AimHandler.ins.bRuning9Axis()) return;
                 if (Camera.main == null) return;
                 Ray ray = Camera.main.ScreenPointToRay(point);
                 Vector3 rayEndPoint = ray.GetPoint(200);
@@ -426,6 +431,14 @@ public class InfraredDemo : MonoBehaviour
 
     }
 
+    public int getCrosshairValue() {
+       return (int)crosshairValue.Get();
+    }
+
+    public void setCrosshairValue(bool bshow) {
+        crosshairValue.Set(bshow?1:0);
+    }
+
     public void onStartPreview()
     {
         infraredCameraHelper.onStartPreview();
@@ -670,9 +683,19 @@ public class InfraredDemo : MonoBehaviour
             UInt64 _VALUE = currentCameraInfo.GetTypeByName(typeStr);
             UVCCtrlInfo _UVCCtrlInfo = currentCameraInfo.GetInfo(_VALUE);
             float v = currentCameraInfo.GetValue(_VALUE); // infraredCameraHelper.GetBrightness();
-            float v2 = (v / _UVCCtrlInfo.max) * 10;
+            //float v2 = (v / _UVCCtrlInfo.max) * 10;
+
+            // 目标区间 [0, 10] 的边界值
+            double targetMin = 0.0;
+            double targetMax = 10.0;
+            double originalMin = _UVCCtrlInfo.min;
+            double originalMax = _UVCCtrlInfo.max;
+            // 计算转换后的值
+            double v2 = MapValue(v, originalMin, originalMax, targetMin, targetMax);
+
+
             Debug.Log("获取相机的感光度:" + _VALUE + " = " + v + " = " + v2);
-            _slider.SetValueWithoutNotify(v2);
+            _slider.SetValueWithoutNotify((float)v2);
         }
         else _slider.SetValueWithoutNotify(5);
     }
@@ -694,8 +717,16 @@ public class InfraredDemo : MonoBehaviour
             UVCCtrlInfo _UVCCtrlInfo = currentCameraInfo.GetInfo(_VALUE);
             int _currentUVCValue = currentCameraInfo.GetValue(_VALUE);
             //value 0 ~ 10
-            int _current = (int)(_UVCCtrlInfo.max * value / 10);
-            Debug.Log("_current:" + value);
+            // 原始区间和目标区间的边界值
+            double originalMin = 0.0;
+            double originalMax = 10.0;
+            double targetMin = _UVCCtrlInfo.min;
+            double targetMax = _UVCCtrlInfo.max;
+            // 计算转换后的值
+            double result = MapValue(value, originalMin, originalMax, targetMin, targetMax);
+
+            int _current = (int)(result);
+            Debug.Log("_current:" + value + " , result:" + result);
             textObj.text = _current + "";
             slider.value = _current;
             //dUVCParameters.GetValueOrDefault(typeStr).Set(_current);
@@ -704,6 +735,12 @@ public class InfraredDemo : MonoBehaviour
 
         }
     }
+
+    double MapValue(double value, double originalMin, double originalMax, double targetMin, double targetMax)
+    {
+        // 线性插值公式
+        return targetMin + (value - originalMin) * (targetMax - targetMin) / (originalMax - originalMin);
+    }
     #endregion
 
 

+ 21 - 5
Assets/BowArrow/Scripts/Bluetooth/AimHandler.cs

@@ -243,7 +243,8 @@ public class AimDeviceInfos
     [NonSerialized] public float lerpTimeRate = 7;
     public void Update()
     {
-        if (m_controlObj && !m_ban9AxisCalculate && !InfraredDemo.running)
+        //&& !InfraredDemo.running
+        if (m_controlObj && !m_ban9AxisCalculate && bRuning9Axis())
         {
             if (lerpForRotation)
                 m_controlObj.localRotation = Quaternion.Lerp(m_controlObj.localRotation, newRotation, Time.deltaTime * lerpTimeRate);   
@@ -311,12 +312,16 @@ public class AimDeviceInfos
             return;
         }
 
-        if (InfraredDemo.running)
+        //if (InfraredDemo.running)
+        //{
+        //    BluetoothAim.ins.WriteData("4"); //关闭九轴
+        //    return;
+        //}
+
+        if (!bRuning9Axis())
         {
-            BluetoothAim.ins.WriteData("4"); //关闭九轴
             return;
         }
-        
         m_axisHandler.Update(bytes);
 
         if (BowQuatDebug.ins) BowQuatDebug.ins.ShowModuleQuat(newRotation.eulerAngles);
@@ -346,8 +351,9 @@ public class AimDeviceInfos
 
     public void DoIdentity()
     {
-        if (InfraredDemo.running) return;
+        //if (InfraredDemo.running) return;
         m_axisHandler.DoIdentity();
+        if (!bRuning9Axis()) return;
         if (m_controlObj) m_controlObj.localRotation = newRotation;
     }
     public void NotifyAxisOnShot() { m_axisHandler.NotifyAxisOnShot(); }
@@ -362,4 +368,14 @@ public class AimDeviceInfos
     public IEnumerator SaveGyr() { return m_axisHandler.SaveGyr(); }
     public IEnumerator SaveMag() { return m_axisHandler.SaveMag(); }
     public void ResumeCalibrateRecord(string record) { m_axisHandler.ResumeCalibrateRecord(record); }
+
+
+    #region 获取一个连接的设备下,对应的 Archery 是运行9轴的代码处理位置信息判断
+    public bool bRuning9Axis() {
+        bool bRuning = false;
+        //连接的设备下,对应的 Archery 是运行9轴的代码处理位置信息判断
+        bRuning = GlobalData.MyDeviceMode == DeviceMode.Archery;
+        return bRuning;
+    }
+    #endregion
 }

+ 2 - 2
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -910,11 +910,11 @@ public class BluetoothAim : MonoBehaviour
             CallDelay(1, () =>
             {
                 Debug.Log("Connect*********");
-                smartBowHelper2P.Connect(userTags,deviceId2);
+                smartBowHelper2P.Connect(userTags,deviceId2,true);//不在sdk 判断mac
             });
         }
         else {
-            smartBowHelper2P.Connect(userTags, deviceId2);
+            smartBowHelper2P.Connect(userTags, deviceId2,true);
         }
     }
 

+ 8 - 1
Assets/BowArrow/Scripts/Effect/HitTargetNumber.cs

@@ -26,9 +26,15 @@ public class HitTargetNumber : MonoBehaviour
             Destroy(this.gameObject);
         });
     }
-
+    static List<GameObject> hitTargetNumber = new();
     public static void Create(float number) {
         if (number <= 0) return;
+        //清空对象
+        for (int i = hitTargetNumber.Count - 1; i >= 0; i--)
+        {
+            Destroy(hitTargetNumber[i].gameObject);
+            hitTargetNumber.RemoveAt(i);
+        }
         GameObject o = GameObject.Instantiate(
             Resources.Load<GameObject>("Prefabs/Effects/HitTargetNumber"),
             Vector3.zero,
@@ -37,5 +43,6 @@ public class HitTargetNumber : MonoBehaviour
         );
         o.transform.localPosition = new Vector3(340, 180, 0);
         o.GetComponentInChildren<Text>().text = number.ToString($"f{CommonConfig.ringsPrecision}");
+        hitTargetNumber.Add(o);
     }
 }

+ 6 - 1
Assets/BowArrow/Scripts/Expand/AutoResetView.cs

@@ -16,7 +16,12 @@ public class AutoResetView : MonoBehaviour
     public static Action onInstantiate;
 
     public static void DoIdentity() {
-        if (InfraredDemo.running) return;
+        //if (InfraredDemo.running) return;
+        //如果不是运行九轴,不进行校准页面
+        if (!AimHandler.ins.bRuning9Axis())
+        {
+            return;
+        }
         if (SceneManager.GetActiveScene().name.StartsWith("GameDouble"))
         {
             if (GameObject.Find("AutoResetViewNewLeft")) return;

+ 5 - 1
Assets/BowArrow/Scripts/Expand/SB_EventSystem.cs

@@ -79,7 +79,11 @@ public class SB_EventSystem : MonoBehaviour
         }
         void UpdateMoveSimulateMouse() {
             if (!simulateMouseIsAwaked) return;
-            if (InfraredDemo.running) return;
+            //if (InfraredDemo.running) return;
+            if (!AimHandler.ins.bRuning9Axis())
+            {
+                return;
+            }
             nowAxisQuat = Quaternion.Lerp(nowAxisQuat, newAxisQuat, 0.033f * 8);
             Vector3 resEulerAngles = FormatQuat(nowAxisQuat).eulerAngles;
             resEulerAngles.x = Mathf.Clamp(resEulerAngles.x > 180 ? resEulerAngles.x - 360 : resEulerAngles.x, -12.5f, 12.5f);

+ 13 - 1
Assets/BowArrow/Scripts/Game/CrossHair.cs

@@ -12,6 +12,8 @@ public class CrossHair : MonoBehaviour
     private bool visiable = false;
     private bool onlyShow = true;
 
+    private GameObject infraredGuiderObj;
+
     void Awake()
     {
         ins = this;
@@ -31,12 +33,22 @@ public class CrossHair : MonoBehaviour
         //如果是靶子场景,把准心改为黑色
         if (SceneManager.GetActiveScene().name.Equals("Game")) {
             this.image.color = Color.black;
+
+            infraredGuiderObj =  FindObjectOfType<InfraredGuider>().gameObject;
         }
     }
 
     void Update()
     {
-        if (open) SetVisiable(onlyShow && ArmBow.ins && ArmBow.ins.IsCanShoot());
+        //如果是新手指引的情况
+        if (infraredGuiderObj != null && infraredGuiderObj.activeSelf == true)
+        {
+            SetVisiable(true);
+        }
+        else {
+            //按照条件显示图标
+            if (open) SetVisiable(onlyShow && ArmBow.ins && ArmBow.ins.IsCanShoot());
+        }
     }
 
     void SetVisiable(bool value)

+ 4 - 0
Assets/BowArrow/Scripts/Game/GameAssistUI.cs

@@ -80,6 +80,8 @@ public class GameAssistUI : MonoBehaviour
             //显示控制准心按钮
             Button crossHairBtn = transform.Find("Button5").GetComponent<Button>();
             crossHairBtn.gameObject.SetActive(true);
+            //设置准心是否显示
+            CrossHair.ins.SetOnlyShow(InfraredDemo._ins.getCrosshairValue() == 1);
             bool onInitOpen = CrossHair.ins.GetOpen() && CrossHair.ins.GetOnlyShow();
             Image crossHairImage = crossHairBtn.GetComponentInChildren<Image>();
             crossHairImage.material = onInitOpen? outlight:null;
@@ -87,6 +89,8 @@ public class GameAssistUI : MonoBehaviour
                 AudioMgr.ins.PlayBtn();
                 bool onlyShow = !CrossHair.ins.GetOnlyShow();
                 CrossHair.ins.SetOnlyShow(onlyShow);
+                //保存准心状态
+                InfraredDemo._ins.setCrosshairValue(onlyShow);
                 if (onlyShow)
                 {
                    crossHairImage.material = outlight;

+ 1 - 1
Assets/BowArrow/Scripts/Manager/GameMgr.cs

@@ -112,7 +112,7 @@ public class GameMgr : MonoBehaviour
         if (bShowDistance) {
             if (gameType > 0)
             {
-                if (!UserSettings.ins.deviceCalibrateGuideFinish && !InfraredDemo.running)
+                if (!UserSettings.ins.deviceCalibrateGuideFinish) //&& !InfraredDemo.running
                 {
                     DeviceCalibrateView.Create();
                     return;

+ 3 - 0
Assets/DuckHunter/Scripts/CrossHair.cs

@@ -29,6 +29,9 @@ namespace DuckHunter
 
             CrossHairOutBoundChecker1 outBoundChecker = Instantiate(Resources.Load<GameObject>("Prefabs/CrossHairOutBoundChecker1")).GetComponent<CrossHairOutBoundChecker1>();
             outBoundChecker.crossHair = transform as RectTransform;
+
+            //读取准心值
+           SetOnlyShow(InfraredDemo._ins.getCrosshairValue() == 1);
         }
         void Update()
         {

+ 3 - 1
Assets/DuckHunter/Scripts/GameUI.cs

@@ -37,11 +37,13 @@ namespace DuckHunter
                 btnAim.gameObject.SetActive(false);
 
                 btnCrosshair.gameObject.SetActive(true);
+           
                 btnCrosshair.onClick.AddListener(delegate () {
                     AudioManager.Instance.PlayBtn();
                     bool onlyShow = !CrossHair.Instance.GetOnlyShow();
                     CrossHair.Instance.SetOnlyShow(onlyShow);
-
+                    //记录准心值
+                    InfraredDemo._ins.setCrosshairValue(onlyShow);
                 });
             }
             else {

+ 2 - 1
Assets/DuckHunter/Scripts/SmartBowController.cs

@@ -12,7 +12,8 @@ namespace DuckHunter
         void Start() {
             Instance = this;
             SimulateMouseController.ins?.RemoveOpenLocker("NotGame");
-            if (InfraredDemo.running)
+            //InfraredDemo.running
+            if (!AimHandler.ins.bRuning9Axis())
             {
                 InfraredDemo.infraredCameraHelper.OnPositionUpdate += (p) =>
                 {

+ 22 - 7
Assets/FruitMaster/Scripts/GamingManager.cs

@@ -132,7 +132,8 @@ public class GamingManager : MonoBehaviour
     private void OnDestroy()
     {
         if (ShootCheck.ins) ShootCheck.ins.OnGameShoot -= SmartBowFireArrow;
-        if (InfraredDemo.running) InfraredDemo.infraredCameraHelper.OnPositionUpdate -= UpdateCrossHairPosition;
+        //InfraredDemo.running
+        if (!AimHandler.ins.bRuning9Axis()) InfraredDemo.infraredCameraHelper.OnPositionUpdate -= UpdateCrossHairPosition;
     }
 
     // Update is called once per frame
@@ -193,7 +194,7 @@ public class GamingManager : MonoBehaviour
             }
 
             // update aiming cross position
-            if (BowCamera.isTouchMode == false && !InfraredDemo.running)
+            if (BowCamera.isTouchMode == false && AimHandler.ins.bRuning9Axis())//!InfraredDemo.running
             {
                 Vector3 raw_screen_pos = Cam.WorldToScreenPoint(Cam.transform.position + (CurrentRotation * Vector3.forward));
                 float dist_to_mid_x = (raw_screen_pos.x - ScreenMidPoint.x) * AimingCrossPosMultiplier;
@@ -286,8 +287,15 @@ public class GamingManager : MonoBehaviour
     {
         Debug.Assert(FruitsInField.Count == 0);
 
-        CameraToLook.ins.onParseRotation += UpdateRotation;
-        if (InfraredDemo.running) InfraredDemo.infraredCameraHelper.OnPositionUpdate += UpdateCrossHairPosition;
+    
+        //InfraredDemo.running
+        if (AimHandler.ins.bRuning9Axis())
+        {
+            CameraToLook.ins.onParseRotation += UpdateRotation;
+        }
+        else {
+            InfraredDemo.infraredCameraHelper.OnPositionUpdate += UpdateCrossHairPosition;
+        }
 
         Scores = StartScores;
         uploadScore = Scores;
@@ -481,9 +489,16 @@ public class GamingManager : MonoBehaviour
         Cannon.ResetPos();
         Cannon.OnCannonFire -= SpawnAFruit;
 
-        CameraToLook.ins.onParseRotation -= UpdateRotation;
-        if (InfraredDemo.running) InfraredDemo.infraredCameraHelper.OnPositionUpdate -= UpdateCrossHairPosition;
-
+        //CameraToLook.ins.onParseRotation -= UpdateRotation;
+        //if (InfraredDemo.running) InfraredDemo.infraredCameraHelper.OnPositionUpdate -= UpdateCrossHairPosition;
+        if (AimHandler.ins.bRuning9Axis())
+        {
+            CameraToLook.ins.onParseRotation -= UpdateRotation;
+        }
+        else
+        {
+            InfraredDemo.infraredCameraHelper.OnPositionUpdate -= UpdateCrossHairPosition;
+        }
         // clear all fruits in the field
         foreach (var fruit in FruitsInField)
         {

+ 3 - 0
Assets/FruitMaster/Scripts/JCFruitMaster.cs

@@ -32,6 +32,9 @@ public class JCFruitMaster : MonoBehaviour
 
         this.open = UserSettings.ins.openCrossHair;
         this.visiable = aimingCross.enabled;
+
+        //读取准心值
+        SetOnlyShow(InfraredDemo._ins.getCrosshairValue() == 1);
     }
 
     void OnDestroy()

+ 3 - 0
Assets/FruitMaster/Scripts/OverallLogics.cs

@@ -42,10 +42,13 @@ public class OverallLogics : MonoBehaviour
             ResetAimBtn.gameObject.SetActive(false);
 
             CrossHairBtn.gameObject.SetActive(true);
+           
             CrossHairBtn.onClick.AddListener(delegate ()
             {
                 bool onlyShow = !JCFruitMaster.ins.GetOnlyShow();
                 JCFruitMaster.ins.SetOnlyShow(onlyShow);
+                //记录准心值
+                InfraredDemo._ins.setCrosshairValue(onlyShow);
             });
         }
         else

+ 1 - 1
Assets/SmartBow/Resources/SmartBow/Prefabs/Views/Home/InfraredScreenPositioningView.prefab

@@ -1155,7 +1155,7 @@ MonoBehaviour:
   m_Name: 
   m_EditorClassIdentifier: 
   m_Material: {fileID: 0}
-  m_Color: {r: 0, g: 0, b: 0, a: 1}
+  m_Color: {r: 1, g: 1, b: 1, a: 1}
   m_RaycastTarget: 1
   m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
   m_Maskable: 1

BIN
Assets/SmartBow/SmartBowSDK/SmartBowSDK.dll


+ 23 - 3
Assets/WildAttack/Scripts/SmartBowController.cs

@@ -13,11 +13,21 @@ namespace WildAttack
         {
             Instance = this;
             SimulateMouseController.ins?.RemoveOpenLocker("NotGame");
-            if (InfraredDemo.running)
+            //if (InfraredDemo.running)
+            //{
+            //    InfraredDemo.infraredCameraHelper.OnPositionUpdate += OnScreenPointUpdate;
+            //}
+            //else CameraToLook.ins.onParseRotation += OnRotationUpdate;
+
+            if (AimHandler.ins.bRuning9Axis())
+            {
+                CameraToLook.ins.onParseRotation += OnRotationUpdate;
+            }
+            else 
             {
+
                 InfraredDemo.infraredCameraHelper.OnPositionUpdate += OnScreenPointUpdate;
             }
-            else CameraToLook.ins.onParseRotation += OnRotationUpdate;
 
             StartCoroutine(SetOutBoundChecker());
         }
@@ -32,8 +42,18 @@ namespace WildAttack
         void OnDestroy()
         {
             if (Instance == this) Instance = null;
-            if (InfraredDemo.running)
+            //if (InfraredDemo.running)
+            //{
+            //    InfraredDemo.infraredCameraHelper.OnPositionUpdate -= OnScreenPointUpdate;
+            //}
+
+            if (AimHandler.ins.bRuning9Axis())
+            {
+                CameraToLook.ins.onParseRotation -= OnRotationUpdate;
+            }
+            else
             {
+
                 InfraredDemo.infraredCameraHelper.OnPositionUpdate -= OnScreenPointUpdate;
             }
         }

+ 3 - 0
ProjectSettings/EditorBuildSettings.asset

@@ -41,4 +41,7 @@ EditorBuildSettings:
   - enabled: 0
     path: Assets/BowArrow/Scenes/Test.unity
     guid: 14f136990a82f0042aae1edcec1f03a2
+  - enabled: 0
+    path: Assets/InfraredProject/WebCamera/zimWebCamera.unity
+    guid: 7561eb6cd780e5e4887e30791c911a9b
   m_configObjects: {}