Răsfoiți Sursa

1.调整蓝牙名字和射箭操作,调整首页滑动问题

slambb 1 an în urmă
părinte
comite
d59fa88630

+ 1 - 0
Assets/BowArrow/FancyScrollView/FocusOn/Context.cs

@@ -10,6 +10,7 @@ namespace FancyScrollView.FocusOn
 {
     class Context
     {
+        public int ScrollSelectedIndex = 0;
         public int SelectedIndex = -1;
         public Action<int,bool> OnCellClicked;
     }

+ 90 - 10
Assets/BowArrow/FancyScrollView/FocusOn/ScrollView.cs

@@ -28,7 +28,10 @@ namespace FancyScrollView.FocusOn
             Context.OnCellClicked = onClick;
 
             scroller.OnValueChanged(UpdatePosition);
-            scroller.OnSelectionChanged(UpdateSelection);
+            scroller.OnSelectionChanged((index) => {
+                Context.ScrollSelectedIndex = index;
+                UpdateSelection(index);
+            });
         }
 
         void UpdateSelection(int index)
@@ -59,23 +62,100 @@ namespace FancyScrollView.FocusOn
             onSelectionChanged = callback;
         }
 
+        //public void SelectNextCell()
+        //{
+        //    int nextIndex = Context.SelectedIndex + 4;
+        //    int index = nextIndex < ItemsSource.Count ? nextIndex : nextIndex - ItemsSource.Count;
+        //     Debug.LogWarning("Context.SelectedIndex:"+ Context.SelectedIndex + ",nextIndex:" + nextIndex+ ",index:"+ index + ",ItemsSource.Count:"+ ItemsSource.Count);
+        //    //翻页(4个一组)
+        //    SelectCell(index);
+        //}
+
         public void SelectNextCell()
         {
-            int nextIndex = Context.SelectedIndex + 4;
-            int index = nextIndex < ItemsSource.Count ? nextIndex : nextIndex - ItemsSource.Count;
-            // Debug.LogWarning("nextIndex:" + nextIndex+ ",index:"+ index + ",ItemsSource.Count:"+ ItemsSource.Count);
-            //翻页(4个一组)
-            SelectCell(index);
+            int itemsPerPage = 4;
+            int totalItems = ItemsSource.Count;
+
+            // 计算目标索引
+            int nextIndex = Context.SelectedIndex + 1;
+            int targetIndex = Context.SelectedIndex + itemsPerPage;
+
+            //计算目标索引和起始索引的差值
+            int difIndex = targetIndex - Context.ScrollSelectedIndex;
+
+            int targetPageStartIndex = nextIndex;
+            if (difIndex >= itemsPerPage)
+            {
+                // 计算目标页的起始索引
+                targetPageStartIndex = targetIndex;
+            }
+
+            // 确保 targetPageStartIndex 在总项范围内
+            if (targetPageStartIndex >= totalItems)
+            {
+                targetPageStartIndex -= totalItems;
+            }
+
+            Debug.LogWarning(
+                             "Context.ScrollSelectedIndex:" + Context.ScrollSelectedIndex +
+                             "Context.SelectedIndex:" + Context.SelectedIndex +
+                             ", targetIndex:" + targetIndex +
+                             ", targetPageStartIndex:" + targetPageStartIndex +
+                             ", totalItems:" + totalItems);
+
+            // 翻页(4个一组)
+            Context.ScrollSelectedIndex = targetPageStartIndex;
+            SelectCell(targetPageStartIndex);
         }
 
+
+
+        //public void SelectPrevCell()
+        //{
+        //    int nextIndex = Context.SelectedIndex - 4;
+        //    int index = nextIndex >= 0 ? nextIndex : ItemsSource.Count + nextIndex;
+        //    // Debug.LogWarning("nextIndex:" + nextIndex + ",index:" + index + ",ItemsSource.Count:" + ItemsSource.Count);
+        //    SelectCell(index);
+        //}
         public void SelectPrevCell()
         {
-            int nextIndex = Context.SelectedIndex - 4;
-            int index = nextIndex >= 0 ? nextIndex : ItemsSource.Count + nextIndex;
-            // Debug.LogWarning("nextIndex:" + nextIndex + ",index:" + index + ",ItemsSource.Count:" + ItemsSource.Count);
-            SelectCell(index);
+            int itemsPerPage = 4;
+            int totalItems = ItemsSource.Count;
+
+            // 计算目标索引
+            int prevIndex = Context.SelectedIndex - 1;
+            int targetIndex = Context.SelectedIndex - itemsPerPage;
+
+            //计算目标索引和起始索引的差值
+            int difIndex = Context.ScrollSelectedIndex - targetIndex;
+
+            int targetPageStartIndex = prevIndex;
+
+            // 如果当前页面与目标页面之间的差距超过了 itemsPerPage,则跳到上一页的第一项
+            if (difIndex >= itemsPerPage)
+            {
+                targetPageStartIndex = targetIndex;
+            }
+
+            // 确保 targetPageStartIndex 在总项范围内
+            if (targetPageStartIndex < 0)
+            {
+                targetPageStartIndex += totalItems;
+            }
+
+            Debug.LogWarning(
+                "Context.ScrollSelectedIndex:" + Context.ScrollSelectedIndex +
+                ", Context.SelectedIndex:" + Context.SelectedIndex +
+                ", targetIndex:" + targetIndex +
+                ", targetPageStartIndex:" + targetPageStartIndex +
+                ", totalItems:" + totalItems);
+
+            // 翻页(4个一组)
+            Context.ScrollSelectedIndex = targetPageStartIndex;
+            SelectCell(targetPageStartIndex);
         }
 
+
         public void SelectCell(int index,bool bScrollTo = true)
         {
             if (index < 0 || index >= ItemsSource.Count || index == Context.SelectedIndex)

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

@@ -12,7 +12,7 @@ using System.Collections;
 public class BluetoothAim : MonoBehaviour
 {
     #region 弓箭蓝牙模块基本信息
-    readonly string targetDeviceName = "Bbow_20210501 | Artemis Pro";//HOUYI Pro
+    readonly string targetDeviceName = "Bbow_20210501 | ARTEMIS Pro";//HOUYI Pro
     readonly string targetDeviceNameHOUYIPro = "HOUYI Pro";
     readonly string targetDeviceNameGun = "Pistol | Pistol M9 | Bbow_20210501";
     string targetDeviceService

+ 2 - 1
Assets/BowArrow/Scripts/Bluetooth/ShootCheck.cs

@@ -348,9 +348,10 @@ public class ShootCheck : MonoBehaviour
         //打印
         string logTxt = $"序号{id},时区1:{time1}毫秒,时区2:{time2}毫秒,校验:{sumCheckRes},弓轨速度:{speed}m/s,箭的速度:{shootSpeed}m/s";
         if (DebugForDevice.ins) DebugForDevice.ins.LogInfrared(logTxt);
+        Debug.Log(logTxt);
         //收到射箭数据,就回复硬件,否则n毫秒后硬件会认为丢包进行重传
         try {
-            if (sumCheckRes) BluetoothAim.ins.ReplyInfraredShoot(); //如果数据正确,则回复硬件
+           // if (sumCheckRes) BluetoothAim.ins.ReplyInfraredShoot(); //如果数据正确,则回复硬件
         } catch (Exception) { }
         //打印到nodejs
         try {

+ 1 - 1
Assets/SmartBow/SmartBowSDK/BleWinHelper.cs

@@ -27,7 +27,7 @@ namespace SmartBowSDK
             Debug.Log(LogTag + text);
         }
 
-        private string targetDeviceName = "Bbow_20210501 | Artemis Pro";
+        private string targetDeviceName = "Bbow_20210501 | ARTEMIS Pro";
         private string targetDeviceNameHOUYIPro = "HOUYI Pro";
         private string targetDeviceNameGun = "Pistol | Pistol M9 | Bbow_20210501";
         private string targetService = "{0000fff0-0000-1000-8000-00805f9b34fb}";