Jelajahi Sumber

新手柄代码

yichael 4 tahun lalu
induk
melakukan
4953293fa3

+ 11 - 1
Assets/BowArrow/Scripts/Bluetooth/BluetoothShoot.cs

@@ -4,6 +4,7 @@ using UnityEngine;
 using UnityEngine.UI;
 using ArduinoBluetoothAPI;
 using DG.Tweening;
+using System.Text;
 
 public class BluetoothShoot : MonoBehaviour
 {
@@ -12,7 +13,7 @@ public class BluetoothShoot : MonoBehaviour
     BluetoothHelperService bluetoothService;
     string deviceName = "";
     bool canConnect = true;
-
+    bool bFirstIn = true;
     // string targetDeviceName = "BGBox_202012";
     string targetDeviceName = "BArrow_202105";
     [SerializeField] Text textUI;
@@ -85,6 +86,15 @@ public class BluetoothShoot : MonoBehaviour
             bluetoothHelper.OnCharacteristicChanged += (helper, value, characteristic) =>
             {
                 byte[] bytes = value;
+
+                if(bFirstIn)
+                {
+                    bFirstIn = false;
+                    string s = Encoding.ASCII.GetString(bytes);
+                    Debug.Log("value======="+s);
+                    return;
+                }
+
                 // Log(String.Join(",", bytes));
                 BluetoothClient.UploadData(1, bytes);
                 if (ShootCheck.ins != null)

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

@@ -131,7 +131,10 @@ public class ShootCheck : MonoBehaviour
                 if (ArmBow.ins != null)
                 {
                     ArmBow.ins.ADS_fire();   
-                    // webSocket.Send(str);    
+                   if (webSocket != null)
+                    { 
+                        webSocket.Send(str);    
+                    }   
                 }
             }
         }   
@@ -197,7 +200,7 @@ public class ShootCheck : MonoBehaviour
 [Serializable]
 class CMD {
     public string ax = "y";
-    public int a = 1000;
+    public int a = 6000;
     public int r = 2;
 
     public float getAcc() {