Kaynağa Gözat

红外线射箭注释

lvjincheng 4 yıl önce
ebeveyn
işleme
51430a7e50
1 değiştirilmiş dosya ile 14 ekleme ve 4 silme
  1. 14 4
      Assets/BowArrow/Scripts/Bluetooth/ShootCheck.cs

+ 14 - 4
Assets/BowArrow/Scripts/Bluetooth/ShootCheck.cs

@@ -324,24 +324,34 @@ public class ShootCheck : MonoBehaviour
         return false;
     }
 
+    /**通过红外线数据进行射击 */
     public string ShootByInfrared(byte[] bytes) {
-        int id = bytes[1];
-        float time1 = bytes[2] * 0.1f;
-        float time2 = bytes[3] * 0.1f;
-        int sumCheck = bytes[0] + bytes[1] + bytes[2] + bytes[3];
+        int id = bytes[1]; //序号
+        float time1 = bytes[2] * 0.1f; //时区1耗时
+        float time2 = bytes[3] * 0.1f; //时区2耗时
+        //校验和
+        int sumCheck = bytes[0] + bytes[1] + bytes[2] + bytes[3]; 
         sumCheck &= 0xff;
+        //校验和比较结果
         bool sumCheckRes = sumCheck == bytes[4];
+        //弓轨速度
         float speed = 0.05f / (time1 / 1000 + time2 / 1000);
+        //通过动能定理求箭的速度(实体箭质量*实体箭速度^2=游戏中箭的质量*游戏中箭的速度^2)
         shootSpeed = Mathf.Sqrt(speed * speed * arrowWeight / LoginMgr.myUserInfo.actualArrowWeight);  
+        //打印
         string logTxt = $"序号{id},时长1:{time1}毫秒,时长2:{time2}毫秒,和校验结果:{sumCheckRes},弓轨速度:{speed}m/s,箭的速度:{shootSpeed}m/s";
         Debug.LogWarning(logTxt);
+        //收到射箭数据,就回复硬件,否则n毫秒后硬件会认为丢包进行重传
         try {
             if (sumCheckRes) BluetoothAim.ins.WriteData("I"); //如果数据正确,则回复硬件
         } catch (Exception) {}
+        //打印到nodejs
         try {
             ShootCheck.ins.webSocket.Send(logTxt);
         } catch (Exception) {}
+        //调用游戏中的射箭接口
         if (ArmBow.ins) ArmBow.ins.ADS_fire();
+        //返回日志信息
         return logTxt;
     }