Răsfoiți Sursa

射箭识别修改

lvjincheng 4 ani în urmă
părinte
comite
f1327830e1

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

@@ -206,7 +206,7 @@ public class AimHandler : MonoBehaviour
                 DeviceBatteryView.ins.RenderBattery(1, bytes[0]);
                 return;
             }
-            if (bytes[3] == 125)
+            if (bytes.Length > 3 && bytes[3] == 125)
             {
                 DoIdentity();
             }

+ 33 - 36
Assets/BowArrow/Scripts/Bluetooth/ShootCheck.cs

@@ -25,11 +25,6 @@ public class ShootCheck : MonoBehaviour
     {
         ins = this;
         BluetoothDispatcher.shoot = OnDataReceived;   
-        //debug
-        if (Application.platform == RuntimePlatform.WindowsEditor)
-        {
-            transportMode = 1;
-        }
     } 
 
  //用户输入时的变化
@@ -125,7 +120,6 @@ public class ShootCheck : MonoBehaviour
         Sequence sequence = DOTween.Sequence();
         sequence.PrependInterval(1).AppendCallback(delegate() {
             canAdjustNormalOrHightMode = true;
-            transportMode = 0;
             AdjustNormalOrHightMode();
         });
         sequence.SetUpdate(true);
@@ -138,23 +132,19 @@ public class ShootCheck : MonoBehaviour
     {
         if (!canAdjustNormalOrHightMode) return;
         try {
-            string sceneName = SceneManager.GetActiveScene().name;
-            if (sceneName == "Game")
-            {
-                if (transportMode == 0) 
-                {
-                    transportMode = 1;
-                    BluetoothShoot.ins.WriteData("HA");
-                }
-            } 
-            else 
-            {
-                if (transportMode == 1)
-                {
-                    transportMode = 0;
-                    BluetoothShoot.ins.WriteData("NA");
-                }
-            }
+            // string sceneName = SceneManager.GetActiveScene().name;
+            // if (sceneName == "Game")
+            // {
+            //     transportMode = 1;
+            //     BluetoothShoot.ins.WriteData("HA");
+            // } 
+            // else 
+            // {
+            //     transportMode = 0;
+            //     BluetoothShoot.ins.WriteData("NA");
+            // }
+            transportMode = 0;
+            BluetoothShoot.ins.WriteData("NA");
         } catch (Exception) {}
     }
 
@@ -165,6 +155,7 @@ public class ShootCheck : MonoBehaviour
             DeviceBatteryView.ins.RenderBattery(2, bytes[0]);
             return;
         }   
+        
         string str1 = "byte=";
         if (webSocket != null)
         { 
@@ -178,7 +169,22 @@ public class ShootCheck : MonoBehaviour
 
         string str2 = "";
 
-        if (transportMode == 1)
+        if (transportMode == 0)
+        {
+            for (int i = 0; i < (bytes.Length -2 ) /6; i++)
+            {
+                float acc = ToAcceleratedSpeed(bytes[i * 6 + 5], bytes[i * 6 + 6]);
+
+                string t = "(采样时间:"+(int)bytes[i * 6 + 3] + "分"+ (int)bytes[i * 6 + 4]+"秒"+ TwoByteToInt(bytes[i * 6 + 1], bytes[i * 6 + 2])+"毫秒)" ;
+                str2 += "加速度:"+ acc + t + "\n";
+
+                if (ins.check(0, acc, 0, t) && ArmBow.ins) 
+                {
+                    ArmBow.ins.ADS_fire();  
+                }
+            }  
+        }
+        else if (transportMode == 1)
         {
             for (int i = 0; i < bytes.Length / 11; i++)
             {
@@ -186,7 +192,7 @@ public class ShootCheck : MonoBehaviour
                 float ay = ToAcceleratedSpeed(bytes[i * 11 + 7], bytes[i * 11 + 8]);
                 float az = ToAcceleratedSpeed(bytes[i * 11 + 9], bytes[i * 11 + 10]);
 
-                string t = "(采样时间:"+(int)bytes[i * 6 + 3] + "分"+ (int)bytes[i * 6 + 4]+"秒"+ TwoByteToInt(bytes[i * 6 + 1], bytes[i * 6 + 2])+"毫秒)" ;
+                string t = "(采样时间:"+(int)bytes[i * 11 + 3] + "分"+ (int)bytes[i * 11 + 4]+"秒"+ TwoByteToInt(bytes[i * 11 + 1], bytes[i * 11 + 2])+"毫秒)" ;
                 str2 += "加速度:"+ax+t+"\n";
                 
                 if (ins.check(ax, ay, az, t) && ArmBow.ins) 
@@ -206,7 +212,7 @@ public class ShootCheck : MonoBehaviour
     float ToAcceleratedSpeed(byte b1, byte b2)
     {
         int value = TwoByteToInt(b1, b2);
-        return (float)value / 32768 * LoginMgr.myUserInfo.deviceAccValue;
+        return (float)value / 32768 * LoginMgr.myUserInfo.arrowAccValue;
     }
     
     int TwoByteToInt(byte b1, byte b2)
@@ -230,12 +236,7 @@ public class ShootCheck : MonoBehaviour
             {
                 maxAcc = acc;
             }
-            // if (acc == 15.99951f) {
-            if (acc > 15.9f) {
-                // double p1 = -1.188748333;
-                // double p2 = 0.033890372;
-                // double p3 = 3.408473747;
-
+            if (acc > 15.9f && LoginMgr.myUserInfo.arrowAccValue == 16) {
                 double p1 = -1.56729339506415;
                 double p2 = 0.0397744840580165;
                 double p3 = 4.73453844008481;
@@ -258,7 +259,6 @@ public class ShootCheck : MonoBehaviour
             float totalAx = 0;
             float totalAy = 0;
             float totalAz = 0;
-            Debug.LogWarning("=============keyAcc===========");
             foreach (var keyAcc in keyAccList)
             {
                 totalAx += Mathf.Abs(keyAcc.x);
@@ -275,9 +275,7 @@ public class ShootCheck : MonoBehaviour
                 }
                 lasKeytAcc = keyAcc.y;
                 keyAccIndex++;
-                Debug.LogWarning(keyAcc);
             }
-            Debug.LogWarning("---------keyAcc---------");
 
             //是不是合法射出
             bool isLegalShoot = totalAy > totalAx && totalAy > totalAz;
@@ -289,7 +287,6 @@ public class ShootCheck : MonoBehaviour
                 //积分出来的值还是太小,需要一个倍率
                 shootSpeed *= 20;
                 string strShootSpeed = "初速度: " + shootSpeed + " 帧数: " + keyAccList.Count + "\n";
-                Debug.LogWarning(strShootSpeed);
                 
                 string str1 = strShootSpeed + "/////////检测到射出的数据////////////:\n";
                 for (int i=0;i<keyAccList.Count;i++)

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

@@ -253,7 +253,7 @@ public class UserInfo {
     public int diamond = 1000;
     public List<PropInfo> bagList = new List<PropInfo>();
     public List<DeviceInfo> deviceList = new List<DeviceInfo>();
-    public float deviceAccValue = 16;
+    public int arrowAccValue = 16;
     public int timeLimitGameHighestScore = 0;
     public bool deviceCalibrateGuideFinish = false;
     public bool gameRule1GuideFinish = false;

+ 3 - 3
Assets/BowArrow/Scripts/View/DeviceView.cs

@@ -75,17 +75,17 @@ public class DeviceView : MonoBehaviour
             arrowOptionBtns[i].onClick.AddListener(delegate() {
                 AudioMgr.ins.PlayBtn();
                 //select
-                float acc = 16;
+                int acc = 16;
                 if (optionID == 1) {
                     acc = 64;
                 }
                 SelectAccForArrow(acc);
                 //save
-                LoginMgr.myUserInfo.deviceAccValue = acc;
+                LoginMgr.myUserInfo.arrowAccValue = acc;
                 LoginMgr.myUserInfo.Save();
             });
         }
-        SelectAccForArrow(LoginMgr.myUserInfo.deviceAccValue);
+        SelectAccForArrow(LoginMgr.myUserInfo.arrowAccValue);
     }
 
     void FixedUpdate()