Browse Source

校准结果保存服务器,根据mac

lvjincheng 3 năm trước cách đây
mục cha
commit
dcea98fc70

+ 39 - 45
Assets/BowArrow/Scripts/Bluetooth/AimHandler.cs

@@ -1,5 +1,6 @@
 using System;
 using System;
 using UnityEngine;
 using UnityEngine;
+using System.Collections;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using UnityEngine.UI;
 using UnityEngine.UI;
@@ -83,50 +84,42 @@ public class AimHandler : MonoBehaviour
         {
         {
             SetIdentityButton.onClick.AddListener(DoIdentity);
             SetIdentityButton.onClick.AddListener(DoIdentity);
         }
         }
-        
-        // try 
-        // {  
-        //     string magDataStr = PlayerPrefs.GetString("o0MagneticCalibrater");
-        //     MagCalibrater = JsonConvert.DeserializeObject<o0MagneticCalibraterEllipsoidFitting>(magDataStr);
-        // } 
-        // catch(Exception) 
-        // {
-        //     MagCalibrater = null;
-        // }
 
 
-        if (MagCalibrater == null) 
-        {
-            // MagCalibrater = new o0MagneticCalibraterEllipsoidFitting();
-            MagCalibrater = new MagnetometerAutoCalibrater();
-            try {
-                Json.FromJson<MagnetometerAutoCalibrater>(PlayerPrefs.GetString("new_mag_record"), ref MagCalibrater);
-            } catch (System.Exception) {}
-            magComplete = MagCalibrater.Complete;
-        }
-        if (MagCalibrationButton)
-        {
-            MagCalibrationButton.onClick.AddListener(delegate {
-                // CalibrateMag(!MagCalibrater.Calibration);
-            });
-        }
+        InitGyr(null);
+        InitMag(null);
+    }
 
 
+    public void InitGyr(string record) {
+        GyrCalibrater = new o0GyrCalibrater();
         try {
         try {
-            string gyrDataStr = PlayerPrefs.GetString("o0GyrCalibrater");
-            GyrCalibrater = JsonConvert.DeserializeObject<o0GyrCalibrater>(gyrDataStr);
-            if (GyrCalibrater._Average != Vector3.zero) GyrScaleText.text = "已校准";
-        } catch(Exception) {
-            GyrCalibrater = null;
-        }
-        if (GyrCalibrater == null) 
-        {
-            GyrCalibrater = new o0GyrCalibrater();
-        }
-        if (GyrCalibrationButton)
-        {
-            GyrCalibrationButton.onClick.AddListener(delegate() {
-                CalibrateGyr(!GyrCalibrater.Calibration);
-            });
-        }
+            if (record == null) record = PlayerPrefs.GetString("o0GyrCalibrater");
+            GyrCalibrater = JsonConvert.DeserializeObject<o0GyrCalibrater>(record);
+        } catch(Exception) {}
+    }
+
+    public void InitMag(string record) {
+        MagCalibrater = new MagnetometerAutoCalibrater();
+        try {
+            if (record == null) record = PlayerPrefs.GetString("new_mag_record");
+            Json.FromJson<MagnetometerAutoCalibrater>(record, ref MagCalibrater);
+        } catch (System.Exception) {}
+        magComplete = MagCalibrater.Complete;
+    }
+
+    public IEnumerator SaveGyr() {
+        yield return null;
+        string mac = LoginMgr.myUserInfo.mac;
+        string record = JsonConvert.SerializeObject(GyrCalibrater);
+        PlayerPrefs.SetString("o0GyrCalibrater", record); 
+        UserPlayer.ins.call("userComp.saveMacCalibrate", 0, mac, record);
+    }
+
+    public IEnumerator SaveMag() {
+        yield return null;
+        string mac = LoginMgr.myUserInfo.mac;
+        string record = MagCalibrater.ToJson();
+        PlayerPrefs.SetString("new_mag_record", record);
+        UserPlayer.ins.call("userComp.saveMacCalibrate", 1, mac, record);
     }
     }
 
 
     public void CalibrateGyr(bool calibration) {
     public void CalibrateGyr(bool calibration) {
@@ -139,7 +132,6 @@ public class AimHandler : MonoBehaviour
             else
             else
             {
             {
                 GyrCalibrationButton.GetComponentInChildren<Text>().text = "开始陀螺仪校准";
                 GyrCalibrationButton.GetComponentInChildren<Text>().text = "开始陀螺仪校准";
-                PlayerPrefs.SetString("o0GyrCalibrater", JsonConvert.SerializeObject(GyrCalibrater));            
             }
             }
         } catch (Exception e) { Debug.LogError(e.Message); }
         } catch (Exception e) { Debug.LogError(e.Message); }
     }
     }
@@ -445,13 +437,15 @@ public class AimHandler : MonoBehaviour
                 controlObj.localRotation = newRotation;
                 controlObj.localRotation = newRotation;
             }
             }
         }
         }
-        if (!magComplete && MagCalibrater.Complete) {
-            PlayerPrefs.SetString("new_mag_record", MagCalibrater.ToJson());
+        _magCompleteTemp = MagCalibrater.Complete;
+        if (!magComplete && _magCompleteTemp) {
+            StartCoroutine(SaveMag());
             PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("tip_mag-calibrate_success"));
             PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("tip_mag-calibrate_success"));
         }
         }
-        magComplete = MagCalibrater.Complete;
+        magComplete = _magCompleteTemp;
     }
     }
 
 
+    bool _magCompleteTemp;
     bool magComplete;
     bool magComplete;
 
 
     private bool ban9AxisCalculate = false;
     private bool ban9AxisCalculate = false;

+ 27 - 1
Assets/BowArrow/Scripts/Bluetooth/BluetoothAim.cs

@@ -526,7 +526,33 @@ public class BluetoothAim : MonoBehaviour
             if (!str.Equals(LoginMgr.myUserInfo.mac)) {
             if (!str.Equals(LoginMgr.myUserInfo.mac)) {
                 LoginMgr.myUserInfo.mac = str;
                 LoginMgr.myUserInfo.mac = str;
             }
             }
-            UserPlayer.ins.call("userComp.saveMac", str);       
+            SaveMac(str);
         }
         }
     }
     }
+
+    void SaveMac(string mac) {
+        Action<Newtonsoft.Json.Linq.JToken> cb = (Newtonsoft.Json.Linq.JToken o) => {
+            string gyrStr = o.Value<string>("gyr");
+            string magStr = o.Value<string>("mag");
+            AimHandler.ins.InitGyr(gyrStr);
+            AimHandler.ins.InitMag(magStr);
+        };
+        UserPlayer.ins.call("userComp.saveMac", new object[]{mac}, cb);
+    }
+
+    // #region 测试mac获取服务端校准记录
+    // void Awake()
+    // {
+    //     StartCoroutine(qqq());
+    // }
+
+    // System.Collections.IEnumerator qqq() {
+    //     while (LoginMgr.myUserInfo.id == 0) {
+    //         yield return null;
+    //     }
+    //     SaveMac("123");
+    //     StartCoroutine(AimHandler.ins.SaveGyr());
+    //     StartCoroutine(AimHandler.ins.SaveMag());
+    // }
+    // #endregion
 }
 }

+ 1 - 1
Assets/BowArrow/Scripts/View/DeviceCalibrateView.cs

@@ -173,7 +173,6 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
         if (calibrateMagDoing) {
         if (calibrateMagDoing) {
             calibrateMagStartTime = Time.realtimeSinceStartup;
             calibrateMagStartTime = Time.realtimeSinceStartup;
             AimHandler.ins.MagCalibrater = new o0._9Axis.MagnetometerAutoCalibrater();
             AimHandler.ins.MagCalibrater = new o0._9Axis.MagnetometerAutoCalibrater();
-            PlayerPrefs.DeleteKey("new_mag_record");
             flag_MagCalibarateOperateAndFinish = 0;
             flag_MagCalibarateOperateAndFinish = 0;
         }
         }
         interactableAllSkipBtns(!calibrateMagDoing);
         interactableAllSkipBtns(!calibrateMagDoing);
@@ -271,6 +270,7 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
         interactableAllSkipBtns(true);
         interactableAllSkipBtns(true);
         canUpdateGyrCalibrateProgress = false;
         canUpdateGyrCalibrateProgress = false;
         AimHandler.ins.CalibrateGyr(false);
         AimHandler.ins.CalibrateGyr(false);
+        StartCoroutine(AimHandler.ins.SaveGyr());
         //UI
         //UI
         Button btn = btnGyrCalibrate.GetComponent<Button>();
         Button btn = btnGyrCalibrate.GetComponent<Button>();
         if (guide) {
         if (guide) {