123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- using Blue;
- using LitJson;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- using XRTool.Util;
- public interface IUpOrDownloadService : IService
- {
- List<ScenePosRotInfo> PosRot { get; }
- void GetScenePosRot(int projectID);
- void UploadScenePosRot(string Url, string JsonString);
- }
- public class UpOrDownloadService : IUpOrDownloadService
- {
- public List<ScenePosRotInfo> PosRot { get; private set; }
- public int ProjectID { get; private set; }
- public void OnInit()
- {
- }
- void IUpOrDownloadService.GetScenePosRot(int projectID)
- {
- TimerMgr.Instance.CreateTimer(()=> {
- Debug.Log("HJJ.GetScenePosRot " + projectID);
- CoroutineSystem.Instance.StartCoroutine(GetScenePosRotRequest(projectID));
- },1,1);
- }
- void IUpOrDownloadService.UploadScenePosRot(string Url, string JsonString)
- {
- CoroutineSystem.Instance.StartCoroutine(RequestUpload(Url,JsonString));
- }
- private IEnumerator GetScenePosRotRequest(int projectID)
- {
- Debug.Log("HJJ.GetScenePosRot " + HttpSDKAction.Instance.loginUrl + "/project/position");
- using (UnityWebRequest webRequest = new UnityWebRequest(HttpSDKAction.Instance.loginUrl+ "/project/position", "POST"))
- {
- ProjectID = projectID;
- ScenePointBodyInfo TestGet = new ScenePointBodyInfo();
- TestGet.id = projectID;
- TestGet.unity = false;
- string jsonData = JsonConvert.SerializeObject(TestGet);
- 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", UserInfo.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
- {
- if (!string.IsNullOrWhiteSpace(webRequest.downloadHandler.text))
- {
- string message = webRequest.downloadHandler.text;
- JObject jobject = JObject.Parse(message);
- if (jobject["code"].ToString() == "200")
- {
- message = jobject["data"]["position"].ToString();
- Debug.Log("Hjj message===>"+ message);
- if (!string.IsNullOrWhiteSpace(message))
- {
- // TimerMgr.Instance.CreateTimer(() => {
- List<ScenePosRotInfo> ScenePosRotInfoList = JsonConvert.DeserializeObject<List<ScenePosRotInfo>>(message);
- // GongShi2.F2Dto3D(ScenePosRotInfoList[0].x, ScenePosRotInfoList[0].y, 643f, 1920f, ScenePosRotInfoList[1].x, ScenePosRotInfoList[1].y, 51f, 17.1f);
- if(ScenePosRotInfoList[0].x==0 && ScenePosRotInfoList[0].y == 0 && ScenePosRotInfoList[0].z == 0&& ScenePosRotInfoList[1].x == 0 && ScenePosRotInfoList[1].y == 0 && ScenePosRotInfoList[1].z == 0)
- {
- CommandSystem.Instance.Send(new InitSuccessCommand());
- }
- else
- {
- while(DataManager.Instance.CurrentScene == null)
- {
- yield return null;
- }
- Debug.Log("Hjj message=1==>" + ScenePosRotInfoList[0].x);
- Debug.Log("Hjj message=2==>" + DataManager.Instance.CurrentScene.width);
- Debug.Log("Hjj message=3==>" + GameManager.Instance.WebMapSize.x);
- GongShi2.F2Dto3D(ScenePosRotInfoList[0].x, ScenePosRotInfoList[0].y, GameManager.Instance.WebMapSize.y, GameManager.Instance.WebMapSize.x, ScenePosRotInfoList[1].x, ScenePosRotInfoList[1].y, DataManager.Instance.CurrentScene.length, DataManager.Instance.CurrentScene.width);
- }
- // },0.03f,-1);
- }
- }
- }
- }
- }
- }
- public IEnumerator RequestUpload(string Url, string jsonString)
- {
- Debug.Log("HJJSAVE Url ====>" + Url);
- Debug.Log("HJJSAVE jsonString ====>" + jsonString);
- using (UnityWebRequest webRequest = new UnityWebRequest(Url, "POST"))
- {
- JsonData data = JsonMapper.ToObject(jsonString);
- JsonData d2 = new JsonData();
- d2["position"] = data;
- d2["id"] = ProjectID;
- d2["unity"] = false;
- byte[] bodyRaw = Encoding.UTF8.GetBytes(d2.ToJson());
- webRequest.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
- webRequest.downloadHandler = new DownloadHandlerBuffer();
- webRequest.SetRequestHeader("Content-Type", "application/json;charset=utf-8");
- webRequest.SetRequestHeader("authorization", UserInfo.Instance.Token);
- foreach (var v in HttpTool.Instance.RequestHeader)
- {
- webRequest.SetRequestHeader(v.Key, v.Value);
- }
- yield return webRequest.SendWebRequest();
- if (webRequest.result == UnityWebRequest.Result.ProtocolError || webRequest.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.LogError(webRequest.downloadHandler.error);
- Debug.LogError(webRequest.downloadHandler.text);
- /*
- InstantiateCommand Command = new InstantiateCommand(
- InstantiateSystem.Instance.BlueObject.WarningPopUp,
- InstantiateSystem.Instance.BlueObject.NetErrorText);
- CommandSystem.Instance.Send(Command);*/
- ShowTipTime.Instance.gameObject.SetActive(true);
- ShowTipTime.Instance.GetComponent<ShowTipTime>().TimeFloat = 3;
- ShowTipTime.Instance.GetComponent<ShowTipTime>().t = 0;
- ShowTipTime.Instance.GetComponentInChildren<Text>().text = "保存失败";
- }
- else
- {
- if (!string.IsNullOrWhiteSpace(webRequest.downloadHandler.text))
- {
- string message = webRequest.downloadHandler.text;
- JObject jobject = JObject.Parse(message);
- if (jobject["code"].ToString() == "200")
- {
- message = jobject["data"].ToString();
- if (!string.IsNullOrWhiteSpace(message))
- {
- Debug.Log("HJJSave "+ message);
- JsonData data2 = JsonMapper.ToObject(message);
- List<ScenePosRotInfo> ScenePosRotInfoList = JsonConvert.DeserializeObject<List<ScenePosRotInfo>>(data2["position"].ToJson());
- PosRot = ScenePosRotInfoList;
- }
- }
- }
- ShowTipTime.Instance.gameObject.SetActive(true);
- ShowTipTime.Instance.GetComponent<ShowTipTime>().TimeFloat = 3;
- ShowTipTime.Instance.GetComponent<ShowTipTime>().t = 0;
- ShowTipTime.Instance.GetComponentInChildren<Text>().text = "保存成功";
- /*
- InstantiateCommand Command = new InstantiateCommand(
- InstantiateSystem.Instance.BlueObject.WarningPopUp,
- InstantiateSystem.Instance.BlueObject.SuccessText);
- CommandSystem.Instance.Send(Command);*/
- }
- }
- }
- }
|