|
@@ -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;
|