using GLTFast; using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Text; using UnityEngine; using UnityEngine.Networking; public class HttpManager : Singleton { #region Path /// /// 截屏目录 /// private string m_ScreenshotPath = $"{Application.streamingAssetsPath}/Screenshots/"; public string ScreenshotPath { get { if (!Directory.Exists(m_ScreenshotPath)) { Directory.CreateDirectory(m_ScreenshotPath); } return m_ScreenshotPath; } } /// /// 模型旋转角度 /// public string GetInitialAnge { get { return $"{Application.streamingAssetsPath}/Data/InitialAngle.json"; } } /// /// 设备列表 /// public string GetDeiveceList { get { return $"{Application.streamingAssetsPath}/Data/DevicesList.json"; } } /// /// 楼层按钮 /// public string GetFloorButtons { get { return $"{Application.streamingAssetsPath}/Data/Floors.json"; } } /// /// 单位基本信息 /// public string GetBuildingBasicInfos { get { return $"{Config.ServerAddress}/api/BuildingBasicInfos?name={Config.CompanyName}"; } } public string PostBuildingBasicInfos { get { return $"{Config.ServerAddress}/api/BuildingBasicInfos?name={Config.CompanyName}"; } } /// /// 高度相机位置 /// public string GetHeightLocation { get { return $"{Application.streamingAssetsPath}/Data/HeightLocation.json"; } } /// /// 毗邻相机位置 /// public string GetAdjacentLocation { get { return $"{Application.streamingAssetsPath}/Data/AdjacentLocation.json"; } } /// /// 建筑特点 /// public string GetBuildingFeatures { get { return $"{Config.ServerAddress}/api/BuildingFeatures?name={Config.CompanyName}"; } } public string PostBuildingFeatures { get { return $"{Config.ServerAddress}/api/BuildingFeatures?name={Config.CompanyName}"; } } /// /// 毗邻信息 /// public string GetAllBuildingAdjoins { get { return $"{Config.ServerAddress}/api/BuildingAdjoins?name={Config.CompanyName}"; } } public string GetBuildingAdjoinsById { get { return $"{Config.ServerAddress}/api/BuildingAdjoins/{{0}}?name={Config.CompanyName}"; } } public string PostBuildingAdjoinsById { get { return $"{Config.ServerAddress}/api/BuildingAdjoins/{{0}}?name={Config.CompanyName}"; } } /// /// 登高作业面 /// public string GetAllFireClimbingSites { get { return $"{Config.ServerAddress}/api/ClimbingSurfaces?name={Config.CompanyName}"; } } public string PostAllFireClimbingSites { get { return $"{Config.ServerAddress}/api/ClimbingSurfaces?name={Config.CompanyName}"; } } public string GetFireClimbingSitesById { get { return $"{Config.ServerAddress}/api/ClimbingSurfaces/{{0}}?name={Config.CompanyName}"; } } public string PostFireClimbingSitesById { get { return $"{Config.ServerAddress}/api/ClimbingSurfaces/{{0}}?name={Config.CompanyName}"; } } /// /// 危险源 /// public string GetAllHazardSources { get { return $"{Config.ServerAddress}/api/Hazards?name={Config.CompanyName}"; } } public string PostAllHazardSources { get { return $"{Config.ServerAddress}/api/Hazards?name={Config.CompanyName}"; } } public string GetHazardSourcesById { get { return $"{Config.ServerAddress}/api/Hazards/{{0}}?name={Config.CompanyName}"; } } public string PostHazardSourcesById { get { return $"{Config.ServerAddress}/api/Hazards/{{0}}?name={Config.CompanyName}"; } } /// /// 禁停区 /// public string GetAllNoParkingAreas { get { return $"{Config.ServerAddress}/api/NoParkingAreas?name={Config.CompanyName}"; } } public string PostAllNoParkingAreas { get { return $"{Config.ServerAddress}/api/NoParkingAreas?name={Config.CompanyName}"; } } public string GetNoParkingAreasById { get { return $"{Config.ServerAddress}/api/NoParkingAreas/{{0}}?name={Config.CompanyName}"; } } public string PostNoParkingAreasById { get { return $"{Config.ServerAddress}/api/NoParkingAreas/{{0}}?name={Config.CompanyName}"; } } /// /// 重点区域 /// public string GetAllImportantLocations { get { return $"{Config.ServerAddress}/api/ImportantLocations?name={Config.CompanyName}"; } } public string PostAllImportantLocations { get { return $"{Config.ServerAddress}/api/ImportantLocations?name={Config.CompanyName}"; } } public string GetImportantLocationsById { get { return $"{Config.ServerAddress}/api/ImportantLocations/{{0}}?name={Config.CompanyName}"; } } public string PostImportantLocationsById { get { return $"{Config.ServerAddress}/api/ImportantLocations/{{0}}?name={Config.CompanyName}"; } } /// /// 图片标记信息 /// public string GetAllImageMarkers { get { return $"{Config.ServerAddress}/api/ImageMarkers?name={Config.CompanyName}"; } } public string PostAllImageMarkers { get { return $"{Config.ServerAddress}/api/ImageMarkers?name={Config.CompanyName}"; } } public string GetImageMarkersById { get { return $"{Config.ServerAddress}/api/ImageMarkers/{{0}}?name={Config.CompanyName}"; } } public string PostImageMarkersById { get { return $"{Config.ServerAddress}/api/ImageMarkers/{{0}}?name={Config.CompanyName}"; } } /// /// 逃生窗 /// public string GetAllEscapeWins { get { return $"{Config.ServerAddress}/api/EscapeWindows?name={Config.CompanyName}"; } } public string PostAllEscapeWins { get { return $"{Config.ServerAddress}/api/EscapeWindows?name={Config.CompanyName}"; } } public string GetEscapeWinsById { get { return $"{Config.ServerAddress}/api/EscapeWindows/{{0}}?name={Config.CompanyName}"; } } public string PostEscapeWinsById { get { return $"{Config.ServerAddress}/api/EscapeWindows/{{0}}?name={Config.CompanyName}"; } } /// /// 破拆点 /// public string GetAllBreakPoints { get { return $"{Config.ServerAddress}/api/BreakPoints?name={Config.CompanyName}"; } } public string PostAllBreakPoints { get { return $"{Config.ServerAddress}/api/BreakPoints?name={Config.CompanyName}"; } } public string GetBreakPointsById { get { return $"{Config.ServerAddress}/api/BreakPoints/{{0}}?name={Config.CompanyName}"; } } public string PostBreakPointsById { get { return $"{Config.ServerAddress}/api/BreakPoints/{{0}}?name={Config.CompanyName}"; } } /// /// 微型消防站 /// public string GetMiniFireStations { get { return $"{Config.ServerAddress}/api/MiniFireStations?name={Config.CompanyName}"; } } public string PostMiniFireStations { get { return $"{Config.ServerAddress}/api/MiniFireStations?name={Config.CompanyName}"; } } /// /// 消防控制室 /// public string GetAllFireControlRooms { get { return $"{Config.ServerAddress}/api/FireControlRooms?name={Config.CompanyName}"; } } public string PostAllFireControlRooms { get { return $"{Config.ServerAddress}/api/FireControlRooms?name={Config.CompanyName}"; } } public string GetFireControlRoomsById { get { return $"{Config.ServerAddress}/api/FireControlRooms/{{0}}?name={Config.CompanyName}"; } } public string PostFireControlRoomsById { get { return $"{Config.ServerAddress}/api/FireControlRooms/{{0}}?name={Config.CompanyName}"; } } /// /// 送风机 /// public string GetAllForcedDraftFans { get { return $"{Config.ServerAddress}/api/Blowers?name={Config.CompanyName}"; } } public string PostAllForcedDraftFans { get { return $"{Config.ServerAddress}/api/Blowers?name={Config.CompanyName}"; } } public string GetForcedDraftFansById { get { return $"{Config.ServerAddress}/api/Blowers/{{0}}?name={Config.CompanyName}"; } } public string PostForcedDraftFansById { get { return $"{Config.ServerAddress}/api/Blowers/{{0}}?name={Config.CompanyName}"; } } /// /// 送风口 /// public string GetAllAirVents { get { return $"{Config.ServerAddress}/api/Outlets?name={Config.CompanyName}"; } } public string PostAllAirVents { get { return $"{Config.ServerAddress}/api/Outlets?name={Config.CompanyName}"; } } public string GetAirVentsById { get { return $"{Config.ServerAddress}/api/Outlets/{{0}}?name={Config.CompanyName}"; } } public string PostAirVentsById { get { return $"{Config.ServerAddress}/api/Outlets/{{0}}?name={Config.CompanyName}"; } } /// /// 排烟风机 /// public string GetAllSmokeExtractionFans { get { return $"{Config.ServerAddress}/api/ExhasustingVentilators?name={Config.CompanyName}"; } } public string PostAllSmokeExtractionFans { get { return $"{Config.ServerAddress}/api/ExhasustingVentilators?name={Config.CompanyName}"; } } public string GetSmokeExtractionFansById { get { return $"{Config.ServerAddress}/api/ExhasustingVentilators/{{0}}?name={Config.CompanyName}"; } } public string PostSmokeExtractionFansById { get { return $"{Config.ServerAddress}/api/ExhasustingVentilators/{{0}}?name={Config.CompanyName}"; } } /// /// 排烟口 /// public string GetAllSmokeVents { get { return $"{Config.ServerAddress}/api/SmokeOutlets?name={Config.CompanyName}"; } } public string PostAllSmokeVents { get { return $"{Config.ServerAddress}/api/SmokeOutlets?name={Config.CompanyName}"; } } public string GetSmokeVentsById { get { return $"{Config.ServerAddress}/api/SmokeOutlets/{{0}}?name={Config.CompanyName}"; } } public string PostSmokeVentsById { get { return $"{Config.ServerAddress}/api/SmokeOutlets/{{0}}?name={Config.CompanyName}"; } } /// /// 泵房水箱 /// public string GetPumpRooms { get { return $"{Config.ServerAddress}/api/PumpRooms?name={Config.CompanyName}"; } } public string PostPumpRooms { get { return $"{Config.ServerAddress}/api/PumpRooms?name={Config.CompanyName}"; } } public string GetPumpRoomsById { get { return $"{Config.ServerAddress}/api/PumpRooms/{{0}}?name={Config.CompanyName}"; } } public string PostPumpRoomsById { get { return $"{Config.ServerAddress}/api/PumpRooms/{{0}}?name={Config.CompanyName}"; } } /// /// 室外消火栓 /// public string GetAllOutdoorFireHydrants { get { return $"{Config.ServerAddress}/api/OutdoorFireHydrants?name={Config.CompanyName}"; } } public string PostAllOutdoorFireHydrants { get { return $"{Config.ServerAddress}/api/OutdoorFireHydrants?name={Config.CompanyName}"; } } public string GetOutdoorFireHydrantsById { get { return $"{Config.ServerAddress}/api/OutdoorFireHydrants/{{0}}?name={Config.CompanyName}"; } } public string PostOutdoorFireHydrantsById { get { return $"{Config.ServerAddress}/api/OutdoorFireHydrants/{{0}}?name={Config.CompanyName}"; } } /// /// 水泵接合器 /// public string GetAllSiameseConnections { get { return $"{Config.ServerAddress}/api/SiameseConnections?name={Config.CompanyName}"; } } public string PostAllSiameseConnections { get { return $"{Config.ServerAddress}/api/SiameseConnections?name={Config.CompanyName}"; } } public string GetSiameseConnectionsById { get { return $"{Config.ServerAddress}/api/SiameseConnections/{{0}}?name={Config.CompanyName}"; } } public string PostSiameseConnectionsById { get { return $"{Config.ServerAddress}/api/SiameseConnections/{{0}}?name={Config.CompanyName}"; } } /// /// 供水关系图 /// public string GetWaterSupplyDiagrams { get { return $"{Config.ServerAddress}/api/WaterSupplyDiagrams?name={Config.CompanyName}"; } } public string PostWaterSupplyDiagrams { get { return $"{Config.ServerAddress}/api/WaterSupplyDiagrams?name={Config.CompanyName}"; } } /// /// 消防泵 /// public string GetPumpById { get { return $"{Config.ServerAddress}/api/Pumps/{{0}}?name={Config.CompanyName}"; } } public string PostPumpById { get { return $"{Config.ServerAddress}/api/Pumps/{{0}}?name={Config.CompanyName}"; } } /// /// 安全出口 /// public string GetAllFireEscapes { get { return $"{Config.ServerAddress}/api/Exits?name={Config.CompanyName}"; } } public string PostAllFireEscapes { get { return $"{Config.ServerAddress}/api/Exits?name={Config.CompanyName}"; } } public string GetFireEscapesById { get { return $"{Config.ServerAddress}/api/Exits/{{0}}?name={Config.CompanyName}"; } } public string PostFireEscapesById { get { return $"{Config.ServerAddress}/api/Exits/{{0}}?name={Config.CompanyName}"; } } /// /// 疏散楼梯 /// public string GetAllEscapeStairs { get { return $"{Config.ServerAddress}/api/ProtectedStairways?name={Config.CompanyName}"; } } public string PostAllEscapeStairs { get { return $"{Config.ServerAddress}/api/ProtectedStairways?name={Config.CompanyName}"; } } public string GetEscapeStairsById { get { return $"{Config.ServerAddress}/api/ProtectedStairways/{{0}}?name={Config.CompanyName}"; } } public string PostEscapeStairsById { get { return $"{Config.ServerAddress}/api/ProtectedStairways/{{0}}?name={Config.CompanyName}"; } } /// /// 消防电梯 /// public string GetAllFireLifts { get { return $"{Config.ServerAddress}/api/FireLifts?name={Config.CompanyName}"; } } public string PostAllFireLifts { get { return $"{Config.ServerAddress}/api/FireLifts?name={Config.CompanyName}"; } } public string GetFireLiftsById { get { return $"{Config.ServerAddress}/api/FireLifts/{{0}}?name={Config.CompanyName}"; } } public string PostFireLiftsById { get { return $"{Config.ServerAddress}/api/FireLifts/{{0}}?name={Config.CompanyName}"; } } /// /// 周边水源 /// public string GetWaterSources { get { return $"{Config.ServerAddress}/api/PeripheralWaterSources?name={Config.CompanyName}"; } } public string PostWaterSources { get { return $"{Config.ServerAddress}/api/PeripheralWaterSources?name={Config.CompanyName}"; } } /// /// 行车路线 /// public string GetDriveRoutes { get { return $"{Config.ServerAddress}/api/DriveRoutes?name={Config.CompanyName}"; } } public string PostDriveRoutes { get { return $"{Config.ServerAddress}/api/DriveRoutes?name={Config.CompanyName}"; } } /// /// 态势标会 /// public string GetDisposalPlanList { get { return $"{Config.ServerAddress}/api/SituationPlotting?name={Config.CompanyName}"; } } public string PostDisposalPlanList { get { return $"{Config.ServerAddress}/api/SituationPlotting?name={Config.CompanyName}"; } } /// /// 态势标绘力量 /// public string GetPowerButtons { get { return $"{Application.streamingAssetsPath}/Data/PowerButtons.json"; } } /// /// 任务列表 /// public string GetPowerTasks { get { return $"{Application.streamingAssetsPath}/Data/TaskList.json"; } } /// /// 单位组织指挥 /// public string GetOrgCmds { get { return $"{Config.ServerAddress}/api/OrgCmds?name={Config.CompanyName}"; } } public string PostOrgCmds { get { return $"{Config.ServerAddress}/api/OrgCmds?name={Config.CompanyName}"; } } /// /// 社会联动 /// public string GetSocialLinkages { get { return $"{Config.ServerAddress}/api/SocialLinkages?name={Config.CompanyName}"; } } public string PostSocialLinkages { get { return $"{Config.ServerAddress}/api/SocialLinkages?name={Config.CompanyName}"; } } /// /// 社会联勤 /// public string GetSocialJointServices { get { return $"{Config.ServerAddress}/api/SocialJointServices?name={Config.CompanyName}"; } } public string PostSocialJointServices { get { return $"{Config.ServerAddress}/api/SocialJointServices?name={Config.CompanyName}"; } } /// /// 战勤保障 /// public string GetCombatSupport { get { return $"{Config.ServerAddress}/api/CombatSupport?name={Config.CompanyName}"; } } public string PostCombatSupport { get { return $"{Config.ServerAddress}/api/CombatSupport?name={Config.CompanyName}"; } } /// /// 通信保障 /// public string GetCommunicationSupport { get { return $"{Config.ServerAddress}/api/CommunicationSupport?name={Config.CompanyName}"; } } public string PostCommunicationSupport { get { return $"{Config.ServerAddress}/api/CommunicationSupport?name={Config.CompanyName}"; } } /// /// 人员定位历史轨迹 /// public string GetPersonnelHistoryData { get { return $"{Config.ServerAddress}/api/AutomaticSprinklers?name={Config.CompanyName}"; } } public string PostPersonnelHistoryData { get { return $"{Config.ServerAddress}/api/AutomaticSprinklers?name={Config.CompanyName}"; } } /// /// 点位绑定 /// public string GetAllIOilTank { get { return $"{Config.ServerAddress}/api/OilTank?name={Config.CompanyName}"; } } public string PostAllIOilTank { get { return $"{Config.ServerAddress}/api/OilTank?name={Config.CompanyName}"; } } public string GetOilTankById { get { return $"{Config.ServerAddress}/api/OilTank/{{0}}?name={Config.CompanyName}"; } } public string PostIOilTankById { get { return $"{Config.ServerAddress}/api/OilTank/{{0}}?name={Config.CompanyName}"; } } /// /// 获取设备模型 /// public string GetEquipmentModel { get { return $"{Config.ServerAddress}/ModelBase/Equipments/{{0}}/{{1}}.gltf"; } } /// /// 获取态势标绘模型 /// public string GetPowerModel { get { return $"{Config.ServerAddress}/ModelBase/Powers/{{0}}/{{1}}.gltf"; } } /// /// 获取周边水源行车路线标绘模型 /// public string GetAnnotatioModel { get { return $"{Config.ServerAddress}/ModelBase/Annotatios/{{0}}/{{1}}.gltf"; } } /// /// 城市代码 /// public string GetCityCode { get { return $"{Application.streamingAssetsPath}/Data/CityCode.json"; } } /// /// 系统设置 /// public string GetGameSetting { get { return $"{Application.streamingAssetsPath}/Data/GameSettings.json"; } } /// /// 分辨率 /// public string GetResolution { get { return $"{Application.streamingAssetsPath}/Data/Resolution.json"; } } #endregion /// /// 文件、图片 /// public string GetVerifyObject { get { return $"{Config.ServerAddress}/api/Objects/VerifyObject?md5={{0}}"; } } /// /// /api/Objects/{bucketName}/{directoryName} /// public string PostObjects { get { return $"{Config.ServerAddress}/api/Objects/{{0}}/{Config.AreaName}/{Config.CompanyName}"; } } /// /// todo 桶名/{区域名}/{Config.CompanyName}/文件 /// public string GetObjects { get { return $"{Config.ServerAddress}/api/Objects/{{0}}/{{1}}"; } } public string DeleteImageByName { get { return $"{Config.ServerAddress}/api/Objects/{{0}}?x-image-process={{1}}"; } } public string ProcessImage = "?x-image-process=image/resize,m_lfit,h_200,w_300"; [DllImport("__Internal")] private static extern string StringReturnValueFunction(); public override void Awake() { base.Awake(); Debug.Log("ServerAddress" + Config.ServerAddress); } public void Get(string url, Action action) { Debug.Log(Config.ServerAddress); StartCoroutine(GetCoroutine(url, action)); } private IEnumerator GetCoroutine(string url, Action action) { UnityWebRequest uwr = UnityWebRequest.Get(url); yield return uwr.SendWebRequest(); if (uwr.isNetworkError || uwr.isHttpError) { Debug.Log(uwr.error); } else { //Debug.Log(uwr.downloadHandler.text); string json = uwr.downloadHandler.text; T obj = JsonConvert.DeserializeObject(json); if (obj != null) { action?.Invoke(obj); Debug.Log(obj?.ToString() + "加载完成"); } } } public void PostLocal(string url, T obj) { var jsonParam = JsonConvert.SerializeObject(obj, Formatting.Indented); File.WriteAllText(url, jsonParam); } public void PostData(string url, T obj) { var jsonParam = JsonConvert.SerializeObject(obj, Formatting.Indented); File.WriteAllText(url, jsonParam); Debug.Log($"数据保存完成"); } public void Post(string url, T obj, Action action = null) { StartCoroutine(PostCoroutine(url, obj, action)); } private IEnumerator PostCoroutine(string url, T obj, Action action = null) { string jsonParam = JsonConvert.SerializeObject(obj); byte[] body = Encoding.UTF8.GetBytes(jsonParam); UnityWebRequest uwr = new UnityWebRequest(url, "POST"); uwr.uploadHandler = new UploadHandlerRaw(body); uwr.SetRequestHeader("Content-Type", "application/json;charset=utf-8"); yield return uwr.SendWebRequest(); if (uwr.isHttpError || uwr.isNetworkError) { Debug.Log(uwr.error); Debug.Log(jsonParam); } else { action?.Invoke(); Debug.Log($"数据上传完成"); Debug.Log(jsonParam); } } public void Post(string url, Action action) { StartCoroutine(PostCoroutine(url, action)); } private IEnumerator PostCoroutine(string url, Action action) { using (UnityWebRequest uwr = UnityWebRequest.Post(url, "")) { yield return uwr.SendWebRequest(); if (uwr.isHttpError || uwr.isNetworkError) { Debug.Log(uwr.error); } else { string json = uwr.downloadHandler.text; T obj = JsonConvert.DeserializeObject(json); action?.Invoke(obj); } } } //删除 public void Delete(string url, Action action = null) { StartCoroutine(DeleteCoroutine(url, action)); } private IEnumerator DeleteCoroutine(string url, Action action = null) { UnityWebRequest uwr = UnityWebRequest.Delete(url); yield return uwr.SendWebRequest(); if (uwr.isHttpError || uwr.isNetworkError) { Debug.Log(uwr.error); } else { action?.Invoke(); Debug.Log($"数据上传完成"); } } //上传文件 public void PostFile(string fileName, T obj, Action actionResult) { StartCoroutine(PostFileCoroutine(fileName, obj, actionResult)); } IEnumerator PostFileCoroutine(string fileName, T obj, Action actionResult) { JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; string json = JsonConvert.SerializeObject(obj, settings); //序列化 byte[] bArray = Encoding.UTF8.GetBytes(json); List formData = new List(); formData.Add(new MultipartFormFileSection("file", bArray, fileName, "application/octet-stream")); //formData.Add(new MultipartFormFileSection(fileName,bArray)); //请求服务器 using (UnityWebRequest http = UnityWebRequest.Post(string.Format(PostObjects, "WebPlan"), formData)) { yield return http.SendWebRequest(); if (http.isHttpError || http.isNetworkError) { Debug.Log(http.error); } else { Debug.Log(http.downloadHandler.text); var temp = JsonConvert.DeserializeObject(http.downloadHandler.text); actionResult(temp); } } } //上传文件 public void GetFile(string fileName, Action actionResult) where T : class { StartCoroutine(GetFileCoroutine(fileName, actionResult)); } IEnumerator GetFileCoroutine(string fileName, Action actionResult) where T : class { Debug.Log(string.Format(GetObjects, "WebPlan", fileName)); //请求服务器 using (UnityWebRequest http = UnityWebRequest.Get(string.Format(GetObjects, "WebPlan", fileName))) { yield return http.SendWebRequest(); if (http.isHttpError || http.isNetworkError) { Debug.Log(http.error); } else { string json = Encoding.UTF8.GetString(http.downloadHandler.data); Debug.Log(json); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; T t = JsonConvert.DeserializeObject(json, settings); actionResult?.Invoke(t); } } } //上传图片 public void PostImage(string fileName, Texture2D texture2d, Action actionResult) { if (!texture2d.name.Equals("DefualtSprite")) { StartCoroutine(PostImageCoroutine(fileName, texture2d, actionResult)); } else { actionResult(null); } } IEnumerator PostImageCoroutine(string fileName, Texture2D texture2d, Action actionResult) { //序列化 byte[] bArray = texture2d.EncodeToJPG(); //设置表单数据 WWWForm form = new WWWForm(); form.AddBinaryData("file", bArray, fileName); Debug.Log(string.Format(PostObjects, "WebPlan")); //请求服务器 using (UnityWebRequest http = UnityWebRequest.Post(string.Format(PostObjects, "WebPlan"), form)) { yield return http.SendWebRequest(); if (http.isHttpError || http.isNetworkError) { Debug.Log($"访问失败:{http.error}\r\n地址:{http.uri}"); } else { Debug.Log(http.downloadHandler.text); var temp = JsonConvert.DeserializeObject(http.downloadHandler.text); actionResult(temp); } } } public void PostScreenshot(string fileName, Texture2D texture2d) { byte[] bytes; bytes = texture2d.EncodeToPNG(); File.WriteAllBytes($"{ScreenshotPath}{fileName}.png", bytes); } //下载图片 public void GetImage(string fileName, Action actionResult) { StartCoroutine(GetImageCoroutine(fileName, actionResult)); } IEnumerator GetImageCoroutine(string fileName, Action actionResult) { Debug.Log($"图片下载地址:{string.Format(GetObjects, "WebPlan", fileName)}"); //请求服务器 using (UnityWebRequest http = UnityWebRequestTexture.GetTexture(string.Format(GetObjects, "WebPlan", fileName))) { yield return http.SendWebRequest(); if (http.isHttpError || http.isNetworkError) { Debug.Log($"访问失败:{http.error}\r\n地址:{http.uri}"); } else { Texture2D texture = ((DownloadHandlerTexture)http.downloadHandler).texture; //Debug.Log(texture); actionResult?.Invoke(texture); } } } /// /// 加载GLTF模型 /// /// /// public async void LoadGltf(string path, Action action = null) { var gltf = new GLTFast.GltfImport(); var success = await gltf.Load(path, new ImportSettings()); if (success) { var root = new GameObject("Root"); gltf.InstantiateMainScene(root.transform); action?.Invoke(root); } else { Debug.LogError("Loading glTF failed!"); } } }