Просмотр исходного кода

无论是取消初始化或初始化不成功,都调用服务器上的初始化数据

lvjincheng 2 лет назад
Родитель
Сommit
c969cd7d15

+ 2 - 0
Assets/BowArrow/Prefabs/Views/MagInterferenceTip/MagInterferenceTipView.cs

@@ -15,6 +15,8 @@ public class MagInterferenceTipView : MonoBehaviour, MenuBackInterface
     void OnDestroy()
     {
         PersistenHandler.ins?.menuBackCtr.views.Remove(this);
+        Axis9CalibrateRecord.ResumeCalibrateRecord(LoginMgr.myUserInfo.mac);
+        Axis9CalibrateRecord.SetCalibrateOkRecord(LoginMgr.myUserInfo.mac, false);
     }
 
     public bool OnMenuBack() {

+ 100 - 3
Assets/BowArrow/Resources/Prefabs/Views/DeviceCalibrateView.prefab

@@ -531,7 +531,7 @@ RectTransform:
   m_LocalScale: {x: 1, y: 1, z: 1}
   m_Children: []
   m_Father: {fileID: 6984168368599178995}
-  m_RootOrder: 3
+  m_RootOrder: 4
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0.5, y: 0}
   m_AnchorMax: {x: 0.5, y: 0}
@@ -701,6 +701,101 @@ MonoBehaviour:
   m_OnClick:
     m_PersistentCalls:
       m_Calls: []
+--- !u!1 &5228330536299257671
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 1537717837814931749}
+  - component: {fileID: 5880161371322048783}
+  - component: {fileID: 8247469842479891965}
+  - component: {fileID: 8494099089780513332}
+  m_Layer: 5
+  m_Name: TipMagOK2
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 0
+--- !u!224 &1537717837814931749
+RectTransform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 5228330536299257671}
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_Children: []
+  m_Father: {fileID: 6984168368599178995}
+  m_RootOrder: 3
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+  m_AnchorMin: {x: 0.5, y: 0}
+  m_AnchorMax: {x: 0.5, y: 0}
+  m_AnchoredPosition: {x: 0, y: 156}
+  m_SizeDelta: {x: 660, y: 60}
+  m_Pivot: {x: 0.5, y: 0}
+--- !u!222 &5880161371322048783
+CanvasRenderer:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 5228330536299257671}
+  m_CullTransparentMesh: 1
+--- !u!114 &8247469842479891965
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 5228330536299257671}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  m_Material: {fileID: 0}
+  m_Color: {r: 1, g: 0.85057294, b: 0, a: 1}
+  m_RaycastTarget: 1
+  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
+  m_Maskable: 1
+  m_OnCullStateChanged:
+    m_PersistentCalls:
+      m_Calls: []
+  m_FontData:
+    m_Font: {fileID: 12800000, guid: 1ad2cf6c2f09744489d8c60b3fe3bab2, type: 3}
+    m_FontSize: 30
+    m_FontStyle: 0
+    m_BestFit: 0
+    m_MinSize: 2
+    m_MaxSize: 40
+    m_Alignment: 4
+    m_AlignByGeometry: 0
+    m_RichText: 1
+    m_HorizontalOverflow: 1
+    m_VerticalOverflow: 0
+    m_LineSpacing: 1
+  m_Text: "\u5730\u78C1\u8BA1\u6821\u51C6\u5DF2\u5B8C\u6210"
+--- !u!114 &8494099089780513332
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 5228330536299257671}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 11500000, guid: 0f4efe98aab6c6b41a7ee1f4c49df27b, type: 3}
+  m_Name: 
+  m_EditorClassIdentifier: 
+  textKey: device-calibrate_mag-ok2
+  layoutRebuildObject: {fileID: 0}
+  languageFontSizes: []
 --- !u!1 &6984168368074953870
 GameObject:
   m_ObjectHideFlags: 0
@@ -1017,6 +1112,7 @@ MonoBehaviour:
   prefab_MagInterferenceTipView: {fileID: 6172428592328166794, guid: ec43c0c7af8cd9b42a2a6fa569f73b52, type: 3}
   magReset: {fileID: 4295382300116116190}
   magTipOk: {fileID: 401150513353468415}
+  magTipOk2: {fileID: 5228330536299257671}
   btnBack: {fileID: 6984168369405797681}
   btnNext: {fileID: 6984168369023981447}
   btnFinish: {fileID: 6984168369596222398}
@@ -1173,6 +1269,7 @@ RectTransform:
   - {fileID: 6984168369480428192}
   - {fileID: 422015738313018617}
   - {fileID: 8268822316374091919}
+  - {fileID: 1537717837814931749}
   - {fileID: 3958012737719958775}
   m_Father: {fileID: 6984168368486957087}
   m_RootOrder: 2
@@ -2179,8 +2276,8 @@ RectTransform:
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
   m_AnchorMin: {x: 0, y: 1}
   m_AnchorMax: {x: 0, y: 1}
-  m_AnchoredPosition: {x: 430, y: -120}
-  m_SizeDelta: {x: 660, y: 200}
+  m_AnchoredPosition: {x: 530, y: -120}
+  m_SizeDelta: {x: 860, y: 200}
   m_Pivot: {x: 0.5, y: 0.5}
 --- !u!222 &6984168369721823361
 CanvasRenderer:

+ 32 - 0
Assets/BowArrow/Scripts/Bluetooth/New/Axis9CalibrateRecord.cs

@@ -0,0 +1,32 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Axis9CalibrateRecord
+{
+    //设置-mac对应的模块是否在本机初始化完成过
+    public static void SetCalibrateOkRecord(string mac, bool ok)
+    {
+        PlayerPrefs.SetInt("CalibrateOkRecord" + mac, ok ? 1 : 0);    
+    }
+    //判断-mac对应的模块是否在本机初始化完成过
+    public static bool HasCalibrateOkRecord(string mac)
+    {
+        return PlayerPrefs.GetInt("CalibrateOkRecord" + mac, 0) == 1 ? true : false;
+    }
+
+    static Dictionary<string, string> cacheCalibrateRecords = new Dictionary<string, string>();
+    //缓存校准记录
+    public static void CacheCalibrateRecord(string mac, string record)
+    {
+        if (string.IsNullOrWhiteSpace(mac) || string.IsNullOrWhiteSpace(record)) return;
+        cacheCalibrateRecords[mac] = record;
+    }
+    //恢复校准记录
+    public static void ResumeCalibrateRecord(string mac)
+    {
+        if (string.IsNullOrWhiteSpace(mac)) return;
+        if (cacheCalibrateRecords.ContainsKey(mac))
+            AimHandler.ins.ResumeCalibrateRecord(cacheCalibrateRecords[mac]);
+    }
+}

+ 11 - 0
Assets/BowArrow/Scripts/Bluetooth/New/Axis9CalibrateRecord.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b331c0982b696ba4eab181e8c420d028
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 2
Assets/BowArrow/Scripts/Bluetooth/New/Axis9Handler.cs

@@ -85,8 +85,8 @@ public class Axis9Handler : AxisBaseHandler
     }
 
     
-    private string _oldEllipsoidFitting = "{\"Center\":[-3.0443925790756605,-3.6882526269162423,-0.9424965068421579],\"CorrectMatrixArray\":[[0.2584454016577151,0.00410177628600846,0.005727574526798527],[0.00410177628600846,0.2639115667519193,-0.03866026824619133],[0.005727574526798523,-0.03866026824619133,0.23912157876854007]],\"Radius\":[4.764270274783962,3.854047926765827,3.4233050788114037]}";
-    private double _oldVariance = 0.000362;
+    // private string _oldEllipsoidFitting = "{\"Center\":[-3.0443925790756605,-3.6882526269162423,-0.9424965068421579],\"CorrectMatrixArray\":[[0.2584454016577151,0.00410177628600846,0.005727574526798527],[0.00410177628600846,0.2639115667519193,-0.03866026824619133],[0.005727574526798523,-0.03866026824619133,0.23912157876854007]],\"Radius\":[4.764270274783962,3.854047926765827,3.4233050788114037]}";
+    // private double _oldVariance = 0.000362;
     private void _SaveOldMag()
     {
         // if (!_9Axis.Attitude.MagCalibrater.Complete) return;

+ 1 - 0
Assets/BowArrow/Scripts/Components/TextAutoLanguage2/Resources/TextAutoLanguage2/cn.json

@@ -61,6 +61,7 @@
     "device-calibrate_gyr-tip": "将瞄准模块从智能弓箭上拆下,将其静置在一个平面上,再点击陀螺仪初始化。",
     "device-calibrate_mag-tip": "将单独的瞄准模块沿着不同方向持续翻转,直到提示初始化完成为止。\n<color=#FFA500>注意:为了避免电子产品(手机等)对地磁计初始化的干扰,请在开始地磁计初始化前,将瞄准模块与手机等保持0.5米(半米)以上的距离。</color>",
     "device-calibrate_mag-ok": "地磁计初始化已完成",
+    "device-calibrate_mag-ok2": "地磁计初始化未完成,将使用原始数据",
     "device-calibrate_n-connect": "请先连接模块",
 
     "new-user-guider_btn_skip": "跳过教程",

+ 1 - 0
Assets/BowArrow/Scripts/Components/TextAutoLanguage2/Resources/TextAutoLanguage2/en.json

@@ -61,6 +61,7 @@
     "device-calibrate_gyr-tip": "Remove the aiming module from the smart bow and place it on a plane, and then click Gyr Init.",
     "device-calibrate_mag-tip": "Turn the individual aiming module continuously in different directions until it prompts that the initialization is completed.\n<color=#FFA500>Note: In order to avoid the interference of electronic products (mobile phones, etc.) on the initialization of the magnetometer, please keep the aiming module at a distance of more than 0.5 meters (half meters) from the mobile phone, etc. before starting the initialization of the magnetometer.</color>",
     "device-calibrate_mag-ok": "Mag init completed",
+    "device-calibrate_mag-ok2": "Mag init not complete, the original data will be used",
     "device-calibrate_n-connect": "Please connect the module first",
     
     "new-user-guider_btn_skip": "Skip Tutorial",

+ 5 - 0
Assets/BowArrow/Scripts/Network/SocketComp/UserComp.cs

@@ -11,6 +11,7 @@ public class UserComp : JCUnityLib.Singleton<UserComp>
         UserPlayer.ins.call("userComp.saveUserInfo", userInfo);
     }
 
+    private string _lastSaveMac;
     public void saveMac()
     {
         string mac = LoginMgr.myUserInfo.mac;
@@ -25,6 +26,7 @@ public class UserComp : JCUnityLib.Singleton<UserComp>
                 AimHandler.ins.InitGyr(gyrStr);
                 AimHandler.ins.InitMag(magStr);
             };
+            _lastSaveMac = mac;
             UserPlayer.ins.call("userComp.saveMac", new object[]{mac}, cb);
         }
     } 
@@ -37,6 +39,8 @@ public class UserComp : JCUnityLib.Singleton<UserComp>
         }
         int type = AimHandler.ins.DeviceType;
         if (type > 0) {
+            Axis9CalibrateRecord.CacheCalibrateRecord(mac, record);
+            Axis9CalibrateRecord.SetCalibrateOkRecord(mac, true);
             UserPlayer.ins.call("userComp.saveCalibrateRecord2", type, record, mac);
         }
     }
@@ -56,6 +60,7 @@ public class UserComp : JCUnityLib.Singleton<UserComp>
 
     #region 被服务端调用的函数
     public void onResumeCalibrateRecord(string record) {
+        Axis9CalibrateRecord.CacheCalibrateRecord(_lastSaveMac, record);
         AimHandler.ins.ResumeCalibrateRecord(record);
     }
     #endregion

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

@@ -12,6 +12,7 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
     [SerializeField] GameObject prefab_MagInterferenceTipView;
     [SerializeField] GameObject magReset; //地磁校准按钮
     [SerializeField] GameObject magTipOk;
+    [SerializeField] GameObject magTipOk2;
     [SerializeField] Button btnBack;
     [SerializeField] Button btnNext;
     [SerializeField] Button btnFinish;
@@ -189,10 +190,14 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
             calibrateMagStartTime = Time.realtimeSinceStartup;
             AimHandler.ins.ResetMag();
             flag_MagCalibarateOperateAndFinish = 0;
+        } else {
+            Axis9CalibrateRecord.ResumeCalibrateRecord(LoginMgr.myUserInfo.mac);
+            Axis9CalibrateRecord.SetCalibrateOkRecord(LoginMgr.myUserInfo.mac, false);
         }
         interactableAllSkipBtns(!calibrateMagDoing);
         RefreshResetMagBtn();
     }
+    //取消地磁计校准(仅用在UpdateForMag中)
     void CancelResetMag() {
         calibrateMagDoing = false;
         interactableAllSkipBtns(!calibrateMagDoing);
@@ -203,6 +208,7 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
             if (!AimHandler.ins.IsMagCompleted()) {
                 progressMagCalibrate.gameObject.SetActive(true);
                 magTipOk.SetActive(false);
+                magTipOk2.SetActive(false);
                 //地磁校准超时提示
                 if (calibrateMagDoing) {
                     float doingTime = Time.realtimeSinceStartup - calibrateMagStartTime;
@@ -227,7 +233,9 @@ public class DeviceCalibrateView : MonoBehaviour, MenuBackInterface
                 }
             } else {
                 progressMagCalibrate.gameObject.SetActive(false);
-                magTipOk.SetActive(true);
+                bool hasOkRecord = Axis9CalibrateRecord.HasCalibrateOkRecord(LoginMgr.myUserInfo.mac);
+                magTipOk.SetActive(hasOkRecord);
+                magTipOk2.SetActive(!hasOkRecord);
                 if (calibrateMagDoing) {
                     CancelResetMag();
                 }