Browse Source

下载逻辑修改

胡佳骏 1 year ago
parent
commit
b2eaa6262e

+ 24 - 18
Assets/COSScripts/COSDownLoad.cs

@@ -311,33 +311,39 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
 
 
     }
-
+    public Queue<TaskState> taskQueue = new Queue<TaskState>();
     private void OnState(TaskState state)
     {
-        Debug.Log(state);
-
-        if (state == TaskState.Completed || state == TaskState.Failed)
+        taskQueue.Enqueue(state);
+    }
+    private void Update()
+    {
+        if(taskQueue.Count>0)
         {
-            int ct = listDownLoadTask.Count - 1;
-            for (int i = ct; i >= 0; i--)
+            var state = taskQueue.Dequeue();
+
+            if (state == TaskState.Completed || state == TaskState.Failed)
             {
-                
-                if (listDownLoadTask[i].State() == TaskState.Completed)
+                int ct = listDownLoadTask.Count - 1;
+                for (int i = ct; i >= 0; i--)
                 {
-                    Debug.Log(listDownLoadTask.Count + "   " + listDownLoadTask[i].State() + "   " + listDownLoadTask[i].localFileName);
-                    DownloadResManager.Instance.DownLoadCompleted(listDownLoadTask[i].localFileName);
-                    listDownLoadTask.RemoveAt(i);
-                }
-                if (listDownLoadTask[i].State() == TaskState.Failed)
-                {
-                    Debug.Log(listDownLoadTask.Count + "   " + listDownLoadTask[i].State() + "   " + listDownLoadTask[i].localFileName);
-                    DownloadResManager.Instance.DownLoadFaild(listDownLoadTask[i].localFileName);
-                    listDownLoadTask.RemoveAt(i);
+
+                    if (listDownLoadTask[i].State() == TaskState.Completed)
+                    {
+                        Debug.Log(listDownLoadTask.Count + "   " + listDownLoadTask[i].State() + "   " + listDownLoadTask[i].localFileName);
+                        DownloadResManager.Instance.DownLoadCompleted(listDownLoadTask[i].localFileName);
+                        listDownLoadTask.RemoveAt(i);
+                    }else if (listDownLoadTask[i].State() == TaskState.Failed)
+                    {
+                        Debug.Log(listDownLoadTask.Count + "   " + listDownLoadTask[i].State() + "   " + listDownLoadTask[i].localFileName);
+                        DownloadResManager.Instance.DownLoadFaild(listDownLoadTask[i].localFileName);
+                        listDownLoadTask.RemoveAt(i);
+                    }
                 }
             }
+
         }
     }
-
 }
 
 public class Credential

+ 7 - 2
Assets/COSScripts/DownloadResManager.cs

@@ -149,11 +149,16 @@ public class DownloadResManager : MonoSingleton<DownloadResManager>
         nowDownLoad--;
         for (int i = 0; i < listNotMaterial.Count; i++)
         {
-            Debug.Log("Hjj   DownLoadCompleted :" + listNotMaterial[i].downLoadPath + "——" + localFilePath);
+          
             if (Path.GetFileName( listNotMaterial[i].downLoadPath) == localFilePath)
             {
-                listCompletedMaterial.Add(listNotMaterial[i]);              
+                Debug.Log("Hjj   DownLoadCompleted 1:" + listNotMaterial[i].downLoadPath + "——" + localFilePath);
+                listCompletedMaterial.Add(listNotMaterial[i]);
+                Debug.Log("Hjj   DownLoadCompleted 2:" + listNotMaterial[i].downLoadPath + "——" + localFilePath);
+                LocalLoadManager.Instance.test();
+                Debug.Log("Hjj   DownLoadCompleted 43:" + listNotMaterial[i].downLoadPath + "——" + localFilePath);
                 LocalLoadManager.Instance.LocalLoadMaterial(listNotMaterial[i]);
+                Debug.Log("Hjj   DownLoadCompleted 3:" + listNotMaterial[i].downLoadPath + "——" + localFilePath);
                 listNotMaterial.RemoveAt(i);
                 break;
             }

+ 21 - 6
Assets/COSScripts/LocalLoadManager.cs

@@ -10,19 +10,32 @@ public class LocalLoadManager : MonoSingleton<LocalLoadManager>
     /// </summary>
   private  Dictionary<string, byte[]> dicLoaclData = new Dictionary<string, byte[]>();
 
+    public void test()
+    {
+        Debug.Log("Hjj   test");
+    }
+
     public void LocalLoadMaterial(DownLoadMaterial downloadMaterial)
     {
-        if (dicLoaclData.ContainsKey(downloadMaterial.localLoadPath))
+
+        Debug.Log("Hjj   LocalLoadMaterial :" + downloadMaterial.localLoadPath + "    ");
+        if (dicLoaclData.ContainsKey(downloadMaterial.downLoadPath))
         {
-            MsgHandler.SendMsg(downloadMaterial.localLoadPath, new Msg(downloadMaterial.localLoadPath, dicLoaclData[downloadMaterial.localLoadPath]));
+            Debug.Log("Hjj   LocalLoadMaterial 1 :" + downloadMaterial.localLoadPath + "    ");
+            MsgHandler.SendMsg(downloadMaterial.downLoadPath, new Msg(downloadMaterial.downLoadPath, dicLoaclData[downloadMaterial.downLoadPath]));
         }
         else
+        {
+            Debug.Log("Hjj   LocalLoadMaterial 2 :" + downloadMaterial.localLoadPath + "    ");
             StartCoroutine(DownloadFile(downloadMaterial));
+        }
     }
 
     private System.Collections.IEnumerator DownloadFile(DownLoadMaterial downloadMaterial)
     {
         bool isDownLoad;
+
+        Debug.Log("Hjj   DownloadFile :" + downloadMaterial.localLoadPath + "    ");
         using (UnityWebRequest webRequest = new UnityWebRequest(downloadMaterial.localLoadPath, UnityWebRequest.kHttpVerbGET))
         {
             webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
@@ -30,8 +43,10 @@ public class LocalLoadManager : MonoSingleton<LocalLoadManager>
             webRequest.SetRequestHeader("authorization", UserInfo.Instance.Token);
             webRequest.SetRequestHeader("Content-Type", "application/json");
 
+            Debug.Log("Hjj   DownloadFile start:" + downloadMaterial.localLoadPath + "    ");
             yield return webRequest.SendWebRequest();
 
+            Debug.Log("Hjj   DownloadFile end:" + downloadMaterial.localLoadPath + "    ");
             while (!webRequest.isDone)
             {
                 // 此处可以显示下载进度条等UI操作
@@ -47,16 +62,16 @@ public class LocalLoadManager : MonoSingleton<LocalLoadManager>
                 // 下载失败 
                 //downLoadState = webRequest.error;
                 isDownLoad = false;
-                MsgHandler.SendMsg(downloadMaterial.localLoadPath, new Msg(downloadMaterial.localLoadPath,null));
+                MsgHandler.SendMsg(downloadMaterial.downLoadPath, new Msg(downloadMaterial.downLoadPath, null));
             }
             else
             {
-                Debug.Log(webRequest.isDone + "    " + webRequest.downloadHandler.data.Length);
+                Debug.Log("Hjj   DownloadFile isDone:"+webRequest.isDone + "    " + webRequest.downloadHandler.data.Length);
                 // Debug.LogError("Download Failed: " + webRequest.error);
 
-                dicLoaclData.Add(downloadMaterial.localLoadPath, webRequest.downloadHandler.data);
+                dicLoaclData.Add(downloadMaterial.downLoadPath, webRequest.downloadHandler.data);
                 isDownLoad = true;
-                MsgHandler.SendMsg(downloadMaterial.localLoadPath, new Msg(downloadMaterial.localLoadPath, webRequest.downloadHandler.data));
+                MsgHandler.SendMsg(downloadMaterial.downLoadPath, new Msg(downloadMaterial.downLoadPath, webRequest.downloadHandler.data));
             }
            
         }

+ 1 - 1
Assets/Scripts/UI/GameManager.cs

@@ -692,7 +692,6 @@ public class GameManager : MonoSingleton<GameManager>
     public void GetMinMap( SceneValue scene ,Action<bool> getBack)
     {
         GetMinMapBack = getBack;
-        Debug.Log("Hjj 开始获取地图大小==》");
         DownloadData data1 = new DownloadData();
         string filename = Path.GetFileName(MapPicUrl);
         data1.name = filename;
@@ -721,6 +720,7 @@ public class GameManager : MonoSingleton<GameManager>
         downLoadMaterial.updataTime = scene.updateTime;
         downLoadMaterial.type = "-1";
 
+        Debug.Log("Hjj 开始获取地图大小==》");
         MsgHandler.AddListener(downLoadMaterial.downLoadPath, HandleMsg);
 
         DownloadResManager.Instance.DownLoad(downLoadMaterial);