lvjincheng 3 éve
szülő
commit
92164252d8

+ 11 - 3
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -7,6 +7,7 @@ using DG.Tweening;
 /* 蓝牙瞄准模块 */
 public class BluetoothAim : MonoBehaviour
 {
+    SBLogger logger = new SBLogger(typeof(BluetoothAim).Name);
     readonly string targetDeviceName = "Bbow_20210501";
 
     string targetDeviceService {
@@ -161,25 +162,29 @@ public class BluetoothAim : MonoBehaviour
                 Log("连接成功\n" + helper.getDeviceName());
                 SetStatus(BluetoothStatusEnum.ConnectSuccess);
                 BowCamera.isTouchMode = false;
+                logger.Log("连接成功");
                 foreach (BluetoothHelperService service in helper.getGattServices())
                 {
-
+                    logger.Log("待检测的服务名:" + service.getName());
                     if (service.getName().ToLower().StartsWith(targetDeviceService))
                     {
                         bluetoothService = service;
-
+                        logger.Warn("匹配的服务名:" + service.getName());
                         foreach (BluetoothHelperCharacteristic characteristic in service.getCharacteristics())
                         {
+                            logger.Log("待检测的特征:" + characteristic.getName());
                             if (characteristic.getName().ToLower().StartsWith(targetDeviceCharacteristicWrite))
                             {
                                 characteristicWrite = characteristic;
+                                logger.Warn("匹配的写入特征:" + characteristic.getName());
                             }
                             else if (characteristic.getName().ToLower().StartsWith(targetDeviceCharacteristicNotify))
                             {
-
+                                logger.Warn("匹配的订阅特征(准备):" + characteristic.getName());
                                 BluetoothHelperCharacteristic ch = new BluetoothHelperCharacteristic(characteristic.getName());
                                 ch.setService(bluetoothService.getName());
                                 bluetoothHelper.Subscribe(ch);
+                                logger.Warn("匹配的订阅特征(完成):" + characteristic.getName());
                             }
                         }
                     }
@@ -200,6 +205,7 @@ public class BluetoothAim : MonoBehaviour
             };
             bluetoothHelper.OnCharacteristicChanged += (helper, value, characteristic) =>
             {
+                logger.Log(String.Join(",", value));
                 if (!hasData) {
                     hasDataTime = JC.CS.Utility.GetTimestamp();
                     UploadMacAddress(value);
@@ -499,6 +505,7 @@ public class BluetoothAim : MonoBehaviour
 
     public void WriteData(string data)
     {
+        logger.Log("发送CMD(准备):" + data);
         #if UNITY_STANDALONE_WIN || UNITY_EDITOR
         BleUDP.ins.SendMsg(data);
         #else
@@ -507,6 +514,7 @@ public class BluetoothAim : MonoBehaviour
         ch.setService(bluetoothService.getName());
         bluetoothHelper.WriteCharacteristic(ch, data);
         #endif
+        logger.Log("发送CMD(完成):" + data);
     }
 
     void Log(string text)

+ 47 - 0
Assets/BowArrow/Scripts/Debug/SBLogger.cs

@@ -0,0 +1,47 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class SBLogger
+{
+    private static bool debug = true;
+    private string tag;
+
+    public SBLogger(string tag) 
+    {
+        this.tag = "[" + tag + "]";
+    }
+
+    public void Log(object info) 
+    {
+        if (!debug) return;
+        JC.Unity.CoroutineStarter.Start(SendToServer(0, info));
+    }
+
+    public void Warn(object info) 
+    {
+        if (!debug) return;
+        JC.Unity.CoroutineStarter.Start(SendToServer(1, info));
+    }
+
+    public void Error(object info)
+    {
+        if (!debug) return;
+        JC.Unity.CoroutineStarter.Start(SendToServer(2, info));
+    }
+
+    IEnumerator SendToServer(int level, object info)
+    {
+        long time = JC.CS.Utility.GetTimestamp();
+        string txt = this.tag + " " + info;
+        yield return null;
+        if (level == 0) Debug.Log(txt);
+        else if (level == 1) Debug.LogWarning(txt);
+        else if (level == 2) Debug.LogError(txt);
+        int uid = LoginMgr.myUserInfo.id;
+        if (uid > 0) {
+            UserPlayer.ins?.call("sbLog", uid, time, tag, info.ToString());
+        }
+    }
+}

+ 11 - 0
Assets/BowArrow/Scripts/Debug/SBLogger.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 744b7c3d035c8dd47a0fe8a295890915
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: