lvjincheng 3 лет назад
Родитель
Сommit
0a0c8cdd41

+ 21 - 2
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -193,7 +193,10 @@ public class BluetoothAim : MonoBehaviour
             };
             bluetoothHelper.OnCharacteristicChanged += (helper, value, characteristic) =>
             {
-                if (!hasData) hasDataTime = JC.CS.Utility.GetTimestamp();
+                if (!hasData) {
+                    hasDataTime = JC.CS.Utility.GetTimestamp();
+                    UploadMacAddress(value);
+                }
                 hasData = true;
                 byte[] bytes = value;
                 // Log(String.Join(",", bytes));
@@ -264,7 +267,10 @@ public class BluetoothAim : MonoBehaviour
             };
             BleUDP.ins.OnCharacteristicChanged = (byte[] value) =>
             {
-                if (!hasData) hasDataTime = JC.CS.Utility.GetTimestamp();
+                if (!hasData) {
+                    hasDataTime = JC.CS.Utility.GetTimestamp();
+                    UploadMacAddress(value);
+                }
                 hasData = true;
                 byte[] bytes = value;
                 // Log(String.Join(",", bytes));
@@ -350,6 +356,7 @@ public class BluetoothAim : MonoBehaviour
     {
         canAutoDormancy = true;
         List<string> cmds = new List<string>();
+        cmds.Add("M"); //获取Mac地址
         cmds.Add("b"); //确保开启stm32
         cmds.Add("b"); //获取初始电量
         cmds.Add("1"); //开启发送逻辑
@@ -501,4 +508,16 @@ public class BluetoothAim : MonoBehaviour
             textUI.text = text;
         }
     }
+
+    void UploadMacAddress(byte[] bytes) {
+        if (hasData) return;
+        string str = System.Text.Encoding.ASCII.GetString (bytes);
+        if (str == null) return;
+        if (str.Contains(":")) {
+            if (!str.Equals(LoginMgr.myUserInfo.mac)) {
+                LoginMgr.myUserInfo.mac = str;
+            }
+            UserPlayer.ins.call("userComp.saveMac", str);       
+        }
+    }
 }

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

@@ -54,6 +54,7 @@ public class UserInfo {
     public int integral = 0;
     public int coin = 0;
     public int diamond = 1000;
+    public string mac = "";
     public List<PropInfo> bagList = new List<PropInfo>();
     public List<DeviceInfo> deviceList = new List<DeviceInfo>();
     //显示游戏最高分(不同距离分数独立)