lvjincheng 3 лет назад
Родитель
Сommit
c321ef97c1
1 измененных файлов с 8 добавлено и 6 удалено
  1. 8 6
      Assets/BowArrow/Scripts/Bluetooth/AimHandler.cs

+ 8 - 6
Assets/BowArrow/Scripts/Bluetooth/AimHandler.cs

@@ -101,6 +101,7 @@ public class AimHandler : MonoBehaviour
             try {
             try {
                 Json.FromJson<MagnetometerAutoCalibrater>(PlayerPrefs.GetString("new_mag_record"), ref MagCalibrater);
                 Json.FromJson<MagnetometerAutoCalibrater>(PlayerPrefs.GetString("new_mag_record"), ref MagCalibrater);
             } catch (System.Exception) {}
             } catch (System.Exception) {}
+            magComplete = MagCalibrater.Complete;
         }
         }
         if (MagCalibrationButton)
         if (MagCalibrationButton)
         {
         {
@@ -128,10 +129,6 @@ public class AimHandler : MonoBehaviour
         }
         }
     }
     }
 
 
-    void OnDestroy() {
-        if (MagCalibrater.Complete) PlayerPrefs.SetString("new_mag_record", MagCalibrater.ToJson());
-    }
-
     public void CalibrateGyr(bool calibration) {
     public void CalibrateGyr(bool calibration) {
         try {
         try {
             GyrCalibrater.Calibration = calibration;
             GyrCalibrater.Calibration = calibration;
@@ -149,6 +146,7 @@ public class AimHandler : MonoBehaviour
 
 
     [NonSerialized] public bool isCalibrateMagPerfect = false;
     [NonSerialized] public bool isCalibrateMagPerfect = false;
      public void CalibrateMag(bool calibration) {
      public void CalibrateMag(bool calibration) {
+        isCalibrateMagPerfect = MagCalibrater.Complete;
         // try {
         // try {
         //     if (calibration)
         //     if (calibration)
         //     {
         //     {
@@ -327,10 +325,8 @@ public class AimHandler : MonoBehaviour
             Mag = new Vector3(-z, y, x) / 32768 * 256; //旧版
             Mag = new Vector3(-z, y, x) / 32768 * 256; //旧版
             mag0o = UnityVectorTo0o(Mag);
             mag0o = UnityVectorTo0o(Mag);
             if (!MagCalibrater.Update(mag0o)) {
             if (!MagCalibrater.Update(mag0o)) {
-                isCalibrateMagPerfect = false;
                 return;
                 return;
             }
             }
-            isCalibrateMagPerfect = true;
             mag0o = MagCalibrater.EllipsoidFitting.Map(mag0o);
             mag0o = MagCalibrater.EllipsoidFitting.Map(mag0o);
             Mag = o0VectorToUnity(mag0o);
             Mag = o0VectorToUnity(mag0o);
         } else if (CommonConfig.devicePlan == 1) {
         } else if (CommonConfig.devicePlan == 1) {
@@ -447,8 +443,14 @@ public class AimHandler : MonoBehaviour
                 controlObj.localRotation = newRotation;
                 controlObj.localRotation = newRotation;
             }
             }
         }
         }
+        if (!magComplete && MagCalibrater.Complete) {
+            PlayerPrefs.SetString("new_mag_record", MagCalibrater.ToJson());
+        }
+        magComplete = MagCalibrater.Complete;
     }
     }
 
 
+    bool magComplete;
+
     private bool ban9AxisCalculate = false;
     private bool ban9AxisCalculate = false;
     private Queue<byte[]> cached9AxisFrames = new Queue<byte[]>();
     private Queue<byte[]> cached9AxisFrames = new Queue<byte[]>();
     public void Ban9AxisCalculate(bool ban) {
     public void Ban9AxisCalculate(bool ban) {