|
|
@@ -8,8 +8,8 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
|
|
|
{
|
|
|
[SerializeField] Button btnGyrCalibrate;
|
|
|
[SerializeField] Text progressGyrCalibrate;
|
|
|
- [SerializeField] Button btnMagCalibrate;
|
|
|
- [SerializeField] Button btnIdentityCalibrate;
|
|
|
+ [SerializeField] GameObject magReset; //地磁校准按钮
|
|
|
+ [SerializeField] GameObject magTipOk;
|
|
|
[SerializeField] Button btnBack;
|
|
|
[SerializeField] Button btnNext;
|
|
|
[SerializeField] Button btnFinish;
|
|
|
@@ -39,12 +39,8 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
|
|
|
|
|
|
void Start()
|
|
|
{
|
|
|
- BluetoothHolder.ins.ShowMagEllipse(this);
|
|
|
btnGyrCalibrate.GetComponent<Button>().onClick.AddListener(ClickGyrCalibrate);
|
|
|
- btnMagCalibrate.GetComponent<Button>().onClick.AddListener(ClickMagCalibrate);
|
|
|
- btnIdentityCalibrate.GetComponent<Button>().onClick.AddListener(ClickIdentityCalibrate);
|
|
|
magReset.GetComponent<Button>().onClick.AddListener(ClickResetMag);
|
|
|
- RefreshResetMagBtn();
|
|
|
btnBack.GetComponent<Button>().onClick.AddListener(delegate() {
|
|
|
guideIndex--;
|
|
|
RefreshPage();
|
|
|
@@ -87,13 +83,6 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
|
|
|
try {
|
|
|
GlobalEventCenter.ins.onDeviceCalibrateViewAwakeChanged?.Invoke(false);
|
|
|
} catch (System.Exception e) { Debug.LogError(e.Message); }
|
|
|
- BluetoothHolder.ins.HideMagEllipse(this);
|
|
|
- // if (gyrCalibrating) {
|
|
|
- // AimHandler.ins.CalibrateGyr(false);
|
|
|
- // }
|
|
|
- // if (magCalibrating) {
|
|
|
- // AimHandler.ins.CalibrateMag(false);
|
|
|
- // }
|
|
|
action_OnDestroy?.Invoke();
|
|
|
}
|
|
|
|
|
|
@@ -103,24 +92,16 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
|
|
|
return is_interactable;
|
|
|
}
|
|
|
|
|
|
- bool canUpdateGyrCalibrateProgress = false;
|
|
|
+
|
|
|
|
|
|
- float calibrateMagStartTime = 0; //地磁校准开始时刻
|
|
|
+
|
|
|
|
|
|
void Update()
|
|
|
{
|
|
|
- if (canUpdateGyrCalibrateProgress) {
|
|
|
- int progress = AimHandler.ins.gyrCalibrateCompleteCount * 100 / AimHandler.ins.gyrCalibrateTotalCount;
|
|
|
- progressGyrCalibrate.text = progress + "%";
|
|
|
- if (progress >= 100) {
|
|
|
- FinishGyrCalibrate();
|
|
|
- }
|
|
|
- }
|
|
|
+ UpdateForGyr();
|
|
|
UpdateForMag();
|
|
|
}
|
|
|
- [SerializeField] GameObject tipMag1;
|
|
|
- [SerializeField] GameObject tipMag2;
|
|
|
- [SerializeField] GameObject magReset;
|
|
|
+
|
|
|
|
|
|
void RefreshPage() {
|
|
|
if (guide) {
|
|
|
@@ -151,11 +132,12 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
|
|
|
}
|
|
|
this.transform.Find("Gyr").gameObject.SetActive(deviceCalibrateItem == DeviceCalibrateItem.Gyr);
|
|
|
this.transform.Find("Mag").gameObject.SetActive(deviceCalibrateItem == DeviceCalibrateItem.Mag);
|
|
|
- this.transform.Find("Identity").gameObject.SetActive(deviceCalibrateItem == DeviceCalibrateItem.Identity);
|
|
|
+ RefreshResetMagBtn();
|
|
|
}
|
|
|
|
|
|
/* ------ 新地磁计校准(2022-10-3) ------ */
|
|
|
bool calibrateMagDoing = false;
|
|
|
+ float calibrateMagStartTime = 0; //地磁校准开始时刻
|
|
|
void RefreshResetMagBtn()
|
|
|
{
|
|
|
if (calibrateMagDoing) {
|
|
|
@@ -172,13 +154,21 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
|
|
|
magReset.GetComponentInChildren<TextAutoLanguage>().SetText(85);
|
|
|
}
|
|
|
}
|
|
|
+ //在当前页面中,用户是否点击了开始校准并校准成功;有则flag=1
|
|
|
+ [NonSerialized] public int flag_MagCalibarateOperateAndFinish = -1;
|
|
|
+ public Action action_MagCalibarateOperateAndFinish;
|
|
|
+ public Func<bool> action_OnClickMagCalibrateInterceptor;
|
|
|
void ClickResetMag()
|
|
|
{
|
|
|
+ if (action_OnClickMagCalibrateInterceptor != null) {
|
|
|
+ if (action_OnClickMagCalibrateInterceptor.Invoke()) return;
|
|
|
+ }
|
|
|
calibrateMagDoing = !calibrateMagDoing;
|
|
|
if (calibrateMagDoing) {
|
|
|
calibrateMagStartTime = Time.realtimeSinceStartup;
|
|
|
AimHandler.ins.MagCalibrater = new o0._9Axis.MagnetometerAutoCalibrater();
|
|
|
PlayerPrefs.DeleteKey("new_mag_record");
|
|
|
+ flag_MagCalibarateOperateAndFinish = 0;
|
|
|
}
|
|
|
interactableAllSkipBtns(!calibrateMagDoing);
|
|
|
RefreshResetMagBtn();
|
|
|
@@ -191,39 +181,43 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
|
|
|
void UpdateForMag() {
|
|
|
if (deviceCalibrateItem == DeviceCalibrateItem.Mag) {
|
|
|
if (!AimHandler.ins.MagCalibrater.Complete) {
|
|
|
- tipMag1.SetActive(true);
|
|
|
- tipMag2.SetActive(false);
|
|
|
- magReset.SetActive(true);
|
|
|
+ magTipOk.SetActive(false);
|
|
|
//地磁校准超时提示
|
|
|
if (calibrateMagDoing && Time.realtimeSinceStartup - calibrateMagStartTime > 20) {
|
|
|
CancelResetMag();
|
|
|
PopupMgr.ins.ShowTipTop(TextAutoLanguage2.GetTextByKey("tip_mag-calibrate_please-leave-interfere"));
|
|
|
}
|
|
|
} else {
|
|
|
- tipMag1.SetActive(false);
|
|
|
- tipMag2.SetActive(true);
|
|
|
- magReset.SetActive(true);
|
|
|
+ magTipOk.SetActive(true);
|
|
|
if (calibrateMagDoing) {
|
|
|
CancelResetMag();
|
|
|
}
|
|
|
+ if (flag_MagCalibarateOperateAndFinish == 0) {
|
|
|
+ flag_MagCalibarateOperateAndFinish = 1;
|
|
|
+ action_MagCalibarateOperateAndFinish?.Invoke();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- //重置地磁校准超时检测
|
|
|
- public void ResetCalibrateMagTimeout() {
|
|
|
- calibrateMagStartTime = Time.realtimeSinceStartup;
|
|
|
- }
|
|
|
|
|
|
// ------ 陀螺仪校准 ------
|
|
|
+ //在当前页面中,用户是否点击了开始校准并校准成功;有则flag=1
|
|
|
+ [NonSerialized] public int flag_GyrCalibarateOperateAndFinish = -1;
|
|
|
+ public Action action_GyrCalibarateOperateAndFinish;
|
|
|
+ public Func<bool> action_OnClickGyrCalibrateInterceptor;
|
|
|
bool gyrCalibrating = false;
|
|
|
void ClickGyrCalibrate()
|
|
|
{
|
|
|
+ if (action_OnClickGyrCalibrateInterceptor != null) {
|
|
|
+ if (action_OnClickGyrCalibrateInterceptor.Invoke()) return;
|
|
|
+ }
|
|
|
//Logic
|
|
|
gyrCalibrating = !gyrCalibrating;
|
|
|
interactableAllSkipBtns(!gyrCalibrating);
|
|
|
if (gyrCalibrating) {
|
|
|
AimHandler.ins.gyrCalibrateCompleteCount = 0;
|
|
|
canUpdateGyrCalibrateProgress = true;
|
|
|
+ flag_GyrCalibarateOperateAndFinish = 0;
|
|
|
} else {
|
|
|
canUpdateGyrCalibrateProgress = false;
|
|
|
}
|
|
|
@@ -262,71 +256,22 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // ------ 地磁计校准 ------
|
|
|
- bool magCalibrating = false;
|
|
|
- void ClickMagCalibrate()
|
|
|
+ bool canUpdateGyrCalibrateProgress = false;
|
|
|
+ void UpdateForGyr()
|
|
|
{
|
|
|
- Button btn = btnMagCalibrate.GetComponent<Button>();
|
|
|
- magCalibrating = !magCalibrating;
|
|
|
- interactableAllSkipBtns(!magCalibrating);
|
|
|
- if (magCalibrating) {
|
|
|
- activeMagTipFail(false);
|
|
|
- btn.GetComponentInChildren<TextAutoLanguage>().SetText(83);
|
|
|
- btn.GetComponentInChildren<Text>().color = Color.red;
|
|
|
- AimHandler.ins.CalibrateMag(true);
|
|
|
- } else {
|
|
|
- AimHandler.ins.CalibrateMag(false);
|
|
|
- //检测校准完成时的圆是否理想
|
|
|
- bool circleIsOk = AimHandler.ins.isCalibrateMagPerfect;
|
|
|
- //bool circleIsOk = true;
|
|
|
- // if (AimHandler.ins) {
|
|
|
- // Vector3 radius = AimHandler.ins.MagCalibrater._Radius;
|
|
|
- // if (radius.Equals(Vector3.zero)) {
|
|
|
- // circleIsOk = false;
|
|
|
- // } else if (radius.x == 0 || radius.y == 0 || radius.z == 0) {
|
|
|
- // circleIsOk = false;
|
|
|
- // } else if (
|
|
|
- // Mathf.Abs(1f - radius.x / radius.y) > 0.2f ||
|
|
|
- // Mathf.Abs(1f - radius.x / radius.z) > 0.2f ||
|
|
|
- // Mathf.Abs(1f - radius.y / radius.z) > 0.2f
|
|
|
- // ) {
|
|
|
- // circleIsOk = false;
|
|
|
- // }
|
|
|
- // }
|
|
|
- //提示校准效果不理想
|
|
|
- if (!circleIsOk) activeMagTipFail(true);
|
|
|
- //调整校准按钮
|
|
|
- if (guide && circleIsOk) {
|
|
|
- //关闭按钮
|
|
|
- btn.enabled = false;
|
|
|
- btn.GetComponentInChildren<TextAutoLanguage>().SetText(82);
|
|
|
- btn.GetComponent<Image>().sprite = Resources.Load<Sprite>("Textures/Common/ButtonGray");
|
|
|
- btn.GetComponentInChildren<Text>().color = Color.gray;
|
|
|
- } else {
|
|
|
- btn.GetComponentInChildren<TextAutoLanguage>().SetText(116);
|
|
|
- Color outColor;
|
|
|
- ColorUtility.TryParseHtmlString("#005AB6", out outColor);
|
|
|
- btn.GetComponentInChildren<Text>().color = outColor;
|
|
|
+ if (canUpdateGyrCalibrateProgress) {
|
|
|
+ int progress = AimHandler.ins.gyrCalibrateCompleteCount * 100 / AimHandler.ins.gyrCalibrateTotalCount;
|
|
|
+ progressGyrCalibrate.text = progress + "%";
|
|
|
+ if (progress >= 100) {
|
|
|
+ FinishGyrCalibrate();
|
|
|
+ if (flag_GyrCalibarateOperateAndFinish == 0) {
|
|
|
+ flag_GyrCalibarateOperateAndFinish = 1;
|
|
|
+ action_GyrCalibarateOperateAndFinish?.Invoke();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void activeMagTipFail(bool value) {
|
|
|
- Transform tipFail_T = this.transform.Find("Mag/TipFail");
|
|
|
- if (tipFail_T.gameObject) {
|
|
|
- tipFail_T.gameObject.SetActive(value);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // ------ 视角归位 ------
|
|
|
- void ClickIdentityCalibrate() {
|
|
|
- AimHandler.ins.DoIdentity();
|
|
|
- Button btn = btnIdentityCalibrate.GetComponent<Button>();
|
|
|
- btn.GetComponent<Image>().sprite = Resources.Load<Sprite>("Textures/Common/ButtonGray");
|
|
|
- btn.GetComponentInChildren<Text>().color = Color.gray;
|
|
|
- btn.enabled = false;
|
|
|
- }
|
|
|
-
|
|
|
//设置所有跳转按钮是否可交互
|
|
|
private void interactableAllSkipBtns(bool value) {
|
|
|
this.btnBack.interactable = value;
|
|
|
@@ -336,5 +281,5 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
|
|
|
}
|
|
|
public enum DeviceCalibrateItem
|
|
|
{
|
|
|
- Guide, Gyr, Mag, Identity
|
|
|
+ Guide, Gyr, Mag
|
|
|
}
|