Browse Source

用户小地图开关

蓝色星空 1 year ago
parent
commit
4efa0041b2

+ 24 - 0
Assets/Scripts/Blue/Command/MinMapGetSetCommand.cs

@@ -0,0 +1,24 @@
+using Blue;
+
+/// <summary>
+/// 小地图开关设置命令
+/// </summary>
+public class MinMapGetSetCommand : ICommand
+{
+    private int minMap =2;
+    public MinMapGetSetCommand()
+    {
+
+    }
+    public MinMapGetSetCommand(int minMap)
+    {
+        this.minMap = minMap;
+    }
+    public void OnExcute()
+    {
+        if(minMap == 2)
+            this.GetService<IMinMapService>().Get();
+        else
+            this.GetService<IMinMapService>().setMinMap.Value =minMap;
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/Command/MinMapGetSetCommand.cs.meta

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

+ 45 - 1
Assets/Scripts/Blue/Controller/SetPos/MinMapPos.cs

@@ -1,13 +1,57 @@
+using Blue;
 using UnityEngine;
 
-public class MinMapPos : MonoBehaviour
+public class MinMapPos : AbstractController
 {
     [SerializeField] private GameObject MinMapCanvas;
+    private bool first = true;
+    private IMinMapService minMapService;
+    private int value;
     void Start()
     {
+        minMapService = this.GetService<IMinMapService>();
         if (MinMapCanvas != null)
         {
+            minMapService.setMinMap.Register(
+                newValue =>
+                {
+                    //Debug.LogError("新的值:" + newValue);
+                    value = newValue;
+                    if (newValue == 0)
+                        MinMapCanvas.SetActive(false);
+                    else
+                        MinMapCanvas.SetActive(true);
+                    if (first)
+                    {
+                        first = false;
+                        return;
+                    }
+                    minMapService.Set();
+                }
+            ).UnRegisterWhenGameObjectDestroyed(gameObject);
             MinMapCanvas.transform.parent = OpenXRCamera.Instance.head;
         }
     }
+    private bool patch = true;
+    private void Update()
+    {
+        if (value == 0 && patch)
+        {
+            if (MinMapCanvas.activeSelf == true)
+            {
+                MinMapCanvas.SetActive(false);
+                patch = false;
+            }
+        }
+        /*
+        else if (value == 1 && patch)
+        {
+            if (MinMapCanvas.activeSelf == false)
+            {
+                MinMapCanvas.SetActive(true);
+                patch = false;
+            }
+        }
+        */
+    }
 }

+ 1 - 0
Assets/Scripts/Blue/MRNavigatorPro.cs

@@ -20,6 +20,7 @@ public class MRNavigatorPro : AbstractArchitecture<MRNavigatorPro>
         this.RegisterService<IUpOrDownloadService>(new UpOrDownloadService());
         this.RegisterService<IPointService>(new PointService());
         this.RegisterService<IMQTTService>(new MQTTService());
+        this.RegisterService<IMinMapService>(new MinMapService());
     }
 
     private void RegisterUtility()

+ 4 - 0
Assets/Scripts/Blue/Other/GetUserInfo.cs

@@ -0,0 +1,4 @@
+public class GetUserInfo
+{
+    public int minMap { get; set; }
+}

+ 11 - 0
Assets/Scripts/Blue/Other/GetUserInfo.cs.meta

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

+ 106 - 0
Assets/Scripts/Blue/Service/IMinMapService.cs

@@ -0,0 +1,106 @@
+using System.Collections;
+using System.Text;
+using Blue;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using UnityEngine;
+using UnityEngine.Networking;
+
+public interface IMinMapService : IService
+{
+    void Get();
+    void Set();
+    /// <summary>
+    /// 设置是否显示 0 = 不显示; 1 = 显示
+    /// </summary>
+    BindableProperty<int> setMinMap{ get; set; }
+}
+
+public class MinMapService : IMinMapService
+{
+    private string userInfoGetUrl;
+    private string userInfoSetUrl;
+    private string message;
+
+    public BindableProperty<int> setMinMap { get; set; } = new BindableProperty<int>(2);
+
+    public void OnInit()
+    {
+        userInfoGetUrl = "https://api-fat3.ghz-tech.com/mr-navigator/v1/user/getUserInfo";
+        userInfoSetUrl = "https://api-fat3.ghz-tech.com/mr-navigator/v1/user/settings";
+    }
+    public void Get()
+    {
+        CoroutineSystem.Instance.StartCoroutine(GetRequest());
+    }
+
+    public void Set()
+    {
+        CoroutineSystem.Instance.StartCoroutine(SetRequest(setMinMap.Value));
+    }
+
+    private IEnumerator GetRequest()
+    {
+        using (UnityWebRequest webRequest = new UnityWebRequest(userInfoGetUrl))
+        {
+            webRequest.downloadHandler = new DownloadHandlerBuffer();
+            webRequest.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
+            webRequest.SetRequestHeader("authorization", HttpTool.Instance.Token);
+
+            yield return webRequest.SendWebRequest();
+
+            if (webRequest.result== UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError)
+            {
+                //Debug.LogError(webRequest.error);
+                //Debug.LogError("UnityWebRequest Error:"+webRequest.downloadHandler.text);
+            }
+            else
+            {
+                Debug.LogError(webRequest.downloadHandler.text);
+                if (!string.IsNullOrWhiteSpace(webRequest.downloadHandler.text))
+                {
+                    message = webRequest.downloadHandler.text;
+                    JObject jobject = JObject.Parse(message);
+                    if (jobject["code"].ToString() == "200")
+                    {
+                        message = jobject["data"].ToString();
+                        Debug.LogError(message);
+                        if (!string.IsNullOrWhiteSpace(message))
+                        {
+                            GetUserInfo getUserInfo =  JsonConvert.DeserializeObject<GetUserInfo>(message);
+                            //Debug.LogError("值:"+getUserInfo.minMap);
+                            setMinMap.Value = getUserInfo.minMap;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    private IEnumerator SetRequest(int isOpen)
+    {
+        using (UnityWebRequest webRequest = new UnityWebRequest(userInfoSetUrl, "POST"))
+        {
+            GetUserInfo getUserInfo = new GetUserInfo();
+            getUserInfo.minMap = isOpen;
+            string jsonData = JsonConvert.SerializeObject(getUserInfo);
+            Debug.LogError("JsonData"+jsonData);
+            byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonData);
+
+            webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
+            webRequest.downloadHandler = new DownloadHandlerBuffer();
+
+            webRequest.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
+            webRequest.SetRequestHeader("authorization", HttpTool.Instance.Token);
+
+            yield return webRequest.SendWebRequest();
+
+            if (webRequest.result== UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError)
+                Debug.LogError("UnityWebRequest Error:"+webRequest.downloadHandler.text);
+            else
+            {
+                //Debug.LogError("上传:"+webRequest.downloadHandler.text);
+            }
+        }
+    }
+}

+ 11 - 0
Assets/Scripts/Blue/Service/IMinMapService.cs.meta

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

+ 3 - 1
Assets/Scripts/SettingPanel.cs

@@ -4,8 +4,9 @@ using UnityEngine;
 using UnityEngine.UI;
 using System;
 using SC.XR.Unity;
+using Blue;
 
-public class SettingPanel : MonoBehaviour
+public class SettingPanel : AbstractController
 {
     public Toggle MinMap;
     public Toggle LuJIng;
@@ -80,6 +81,7 @@ public class SettingPanel : MonoBehaviour
 
     private void OnClickSaveData()
     {
+        this.SendCommand(new MinMapGetSetCommand(m_MinMap.gameObject.activeSelf ? 1 : 0));
         DataManager.Instance.SaveSpoits();
         DataManager.Instance.IsSavedData = true;
     }

+ 1 - 0
Assets/Scripts/UI/SceneChoose.cs

@@ -83,6 +83,7 @@ public class SceneChoose : BaseUI
             this.SendCommand(new PointFileGetUrlCommand(detail.id, PointFileType.bytes));
             this.SendCommand(new PointPosRotDownloadCommand(detail.id));
             this.SendCommand(new GetReferencePosCommand(detail.id));
+            this.SendCommand(new MinMapGetSetCommand());
 
             HttpTool.Instance.PostTest("/project/detail", str, (mes) =>
             {