Explorar o código

新手柄代码

yichael %!s(int64=4) %!d(string=hai) anos
pai
achega
4953293fa3

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

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

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

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