Browse Source

点击保存后上传所有景点数据

蓝色星空 1 year ago
parent
commit
e7755d2c31
2 changed files with 93 additions and 3 deletions
  1. 2 1
      Assets/Scripts/Net/HttpTool.cs
  2. 91 2
      Assets/Scripts/UI/EdirPanel/UIEditorPanel.cs

+ 2 - 1
Assets/Scripts/Net/HttpTool.cs

@@ -16,7 +16,8 @@ public class HttpTool : MonoSingleton<HttpTool>
 {
 
   //  private string baseUrl = "http://office.ghz-tech.com:3425/guideSystem";
-    private string baseUrl = "http://office.ghz-tech.com:9904/api";
+    //private string baseUrl = "http://office.ghz-tech.com:9904/api";
+    private string baseUrl = "https://nav21.ghz-tech.com:8843/api/";
     private string UrlPointCloud = "https://pro.qulivr.com/mr-navigator/v1";
     private string token = "";
     Dictionary<string, string> requestHeader = new Dictionary<string, string>();  //  header

+ 91 - 2
Assets/Scripts/UI/EdirPanel/UIEditorPanel.cs

@@ -2,9 +2,11 @@
 using System.Collections;
 using System.Collections.Generic;
 using Blue;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
 using UnityEngine;
+using UnityEngine.Assertions.Must;
 using UnityEngine.UI;
-
 public class UIEditorPanel : AbstractController, EventObserver
 {
 
@@ -228,6 +230,7 @@ public class UIEditorPanel : AbstractController, EventObserver
 
         SaveBtn.onClick.AddListener(() =>
         {
+            /*
             if (MaterialObj == null)
             {
                 InstantiateCommand Command = new InstantiateCommand(
@@ -238,10 +241,95 @@ public class UIEditorPanel : AbstractController, EventObserver
                 return;
             }
             GameManager.Instance.SaveSpoitObjs();
-
+            */
+            SetSpoitInfo();
         });
     }
 
+    public void SetSpoitInfo()
+    {
+        countCo =0;
+        int count = GameManager.Instance.ObjsParent.childCount;
+        for (int i = 1; i <= count-1;i++) // 第一个LocalNULLShowObj是无用的
+        {
+            var spoit = GameManager.Instance.SpoitValues[i-1]; // 某个景点
+
+            for (int j = 0; j < spoit.material.Count; j++) // 更新 ObjectTransform
+            {
+                for (int k = 0;k< spoit.material[j].materialList.Count; k++)
+                {
+                    spoit.material[j].select = true;
+                    spoit.material[j].materialList[k].ObjectTransform.nowPos = GameManager.Instance.ObjsParent.GetChild(i).GetChild(0).GetChild(k).localPosition;
+                    spoit.material[j].materialList[k].ObjectTransform.nowRot = GameManager.Instance.ObjsParent.GetChild(i).GetChild(0).GetChild(k).localEulerAngles;
+                    spoit.material[j].materialList[k].ObjectTransform.nowScale = GameManager.Instance.ObjsParent.GetChild(i).GetChild(0).GetChild(k).localScale;
+                }
+            }
+            StartCoroutine(SelectTrans(spoit));
+        }
+    }
+    private int countCo =0;
+    private IEnumerator SelectTrans(SpoitValue spoit)
+    {
+        yield return null;
+        List<SendSaveData> saveData = new List<SendSaveData>();
+        SendSaveData data = new SendSaveData();
+        data.id = spoit.id;
+        data.name = spoit.name;
+        data.projectId = DataManager.Instance.ProjectID;
+        data.material = spoit.material;
+        data.spoittf = spoit.spoitTf;
+        saveData.Add(data);
+
+        string sendData = JsonConvert.SerializeObject(saveData);
+        HttpTool.Instance.PostTest("/viewpoint/update", sendData, SaveCallBack);
+    }
+    private void SaveCallBack(string message)
+    {
+        countCo++;
+        if (message == "UnityWebRequest Error")
+        {
+            InstantiateCommand ErrorCommand = new InstantiateCommand(
+                InstantiateSystem.Instance.BlueObject.WarningPopUp,
+                InstantiateSystem.Instance.BlueObject.NetErrorText);
+            CommandSystem.Instance.Send(ErrorCommand);
+            Debug.LogError("执行协程数:" + countCo);
+            StopAllCoroutines();
+            //this.GetService<ISendLogService>().SendLog("Blue","UnityWebRequest Error");
+            return;
+        }
+
+        //Debug.LogError("SaveCallBack:  " + message);
+        JObject jObject = JObject.Parse(message);
+        string str = jObject["message"].ToString();
+        if (str != "更新成功")
+        {
+            InstantiateCommand ErrorCommand = new InstantiateCommand(
+                InstantiateSystem.Instance.BlueObject.WarningPopUp,
+                InstantiateSystem.Instance.BlueObject.NetErrorText);
+            CommandSystem.Instance.Send(ErrorCommand);
+            Debug.LogError("执行协程数:" + countCo);
+            StopAllCoroutines();
+            //this.GetService<ISendLogService>().SendLog("Blue","更新成功出现问题");
+            return;
+        }
+        else
+        {
+            Debug.Log("更新成功");
+        }
+        if (countCo != GameManager.Instance.ObjsParent.childCount-1)
+        {
+            Debug.Log("执行协程数:" + countCo);
+            return;
+        }
+        Debug.Log("执行协程数:" + countCo);
+        UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.SaveSpoitDataEnd);
+        ((LoadingPanel)UIManager.Instance.GetUI(UINameConfig.LoadingPanel)).TextStr = str;
+
+        InstantiateCommand Command = new InstantiateCommand(
+                InstantiateSystem.Instance.BlueObject.WarningPopUp,
+                InstantiateSystem.Instance.BlueObject.SuccessText);
+        CommandSystem.Instance.Send(Command);
+    }
 
     /// <summary>
     ///  选择素材
@@ -249,6 +337,7 @@ public class UIEditorPanel : AbstractController, EventObserver
     /// <param name="MaterialObj"></param>
     public void SelectMaterial(Transform MaterialObj)
     {
+        Debug.LogError("MaterialObjName:"+MaterialObj.name);
         this.MaterialObj = MaterialObj;
         listAlter.Clear();
         listAlter = new List<objectData>();