Browse Source

适配新接口2.1的进入场景

胡佳骏 1 year ago
parent
commit
e10fbe67e0

+ 12 - 4
Assets/COSScripts/COSDownLoad.cs

@@ -142,7 +142,9 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
 
     }
 
-
+    public static int showDownLoadCount;
+    public static int showDownEndLoadCount;
+    public static float showDownLoadPre;
     /// <summary>
     /// 高级接口下载对象
     /// </summary>
@@ -160,6 +162,8 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
         //transferConfig.SliceSizeForDownload = 10 * 1024 * 1024;
         TransferManager transferManager;  // 初始化 TransferManager
         String bucket; //存储桶,格式:BucketName-APPID
+
+        Debug.Log("Hjj   TransferDownloadObject===>"+ downloadMaterial.type);
         switch (downloadMaterial.type)
         {
             case "-1":
@@ -189,12 +193,12 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
         // 下载对象
         COSXMLDownloadTask downloadTask = new COSXMLDownloadTask(bucket, downloadMaterial.downLoadPath,
           localDir, localFileName);
-
         // 手动设置高级下载接口的并发数 (默认为5), 从5.4.26版本开始支持!
         //downloadTask.SetMaxTasks(10);
         downloadTask.progressCallback = delegate (long completed, long total)
         {
             Debug.Log(String.Format("Hjj    download"+downloadMaterial.downLoadPath+"progress = {0:##.##}%", completed * 100.0 / total));
+            showDownLoadPre = completed * 100.0f / total;
         };
         Debug.Log(downloadMaterial.downLoadPath);
         downloadTask.onState += OnState;
@@ -211,14 +215,16 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
             //请求失败
             Debug.LogError(downloadMaterial.downLoadPath + "   CosClientException: " + clientEx);
             DownloadResManager.Instance.DownLoadFaild(downloadTask.localFileName);
-            listDownLoadTask.RemoveAt(0);
+            listDownLoadTask.Remove(downloadTask);
+            showDownEndLoadCount++;
         }
         catch (COSXML.CosException.CosServerException serverEx)
         {
             //请求失败
             Debug.LogError(downloadMaterial.downLoadPath+ "    CosServerException: " + serverEx.GetInfo());
             DownloadResManager.Instance.DownLoadFaild(downloadTask.localFileName);
-            listDownLoadTask.RemoveAt(0);
+            listDownLoadTask.Remove(downloadTask);
+            showDownEndLoadCount++;
         }
        
     }
@@ -330,11 +336,13 @@ public class COSDownLoad:MonoSingleton<COSDownLoad>
 
                     if (listDownLoadTask[i].State() == TaskState.Completed)
                     {
+                        showDownEndLoadCount++;
                         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)
                     {
+                        showDownEndLoadCount++;
                         Debug.Log(listDownLoadTask.Count + "   " + listDownLoadTask[i].State() + "   " + listDownLoadTask[i].localFileName);
                         DownloadResManager.Instance.DownLoadFaild(listDownLoadTask[i].localFileName);
                         listDownLoadTask.RemoveAt(i);

+ 6 - 9
Assets/COSScripts/DownloadResManager.cs

@@ -11,19 +11,19 @@ public class DownloadResManager : MonoSingleton<DownloadResManager>
     /// <summary>
     ///  本地已下载素材列表
     /// </summary>
-    private List<DownLoadMaterial> listCompletedMaterial;
+    public List<DownLoadMaterial> listCompletedMaterial;
 
     /// <summary>
     ///  未下载素材列表
     /// </summary>
-    private List<DownLoadMaterial> listNotMaterial;
+    public List<DownLoadMaterial> listNotMaterial;
 
     /// <summary>
     ///  下载失败素材列表
     /// </summary>
-    private List<DownLoadMaterial> listFaildMaterial;
+    public List<DownLoadMaterial> listFaildMaterial;
 
-    private Queue<DownLoadMaterial> qDownload;
+    public Queue<DownLoadMaterial> qDownload;
     private int maxDownLoad = 1;
     private int nowDownLoad = 0;
     private string path;
@@ -132,6 +132,8 @@ public class DownloadResManager : MonoSingleton<DownloadResManager>
         if (!finish)
         {
             listNotMaterial.Add(downloadMaterial);
+
+            COSDownLoad.showDownLoadCount++;
             qDownload.Enqueue(downloadMaterial);
         }
           
@@ -152,13 +154,8 @@ public class DownloadResManager : MonoSingleton<DownloadResManager>
           
             if (Path.GetFileName( listNotMaterial[i].downLoadPath) == localFilePath)
             {
-                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;
             }

+ 2 - 2
Assets/COSScripts/LocalLoadManager.cs

@@ -18,7 +18,7 @@ public class LocalLoadManager : MonoSingleton<LocalLoadManager>
     public void LocalLoadMaterial(DownLoadMaterial downloadMaterial)
     {
 
-        Debug.Log("Hjj   LocalLoadMaterial :" + downloadMaterial.localLoadPath + "    ");
+        Debug.Log("Hjj   LocalLoadMaterial :" + downloadMaterial.localLoadPath + "    " + downloadMaterial.type);
         if (dicLoaclData.ContainsKey(downloadMaterial.downLoadPath))
         {
             Debug.Log("Hjj   LocalLoadMaterial 1 :" + downloadMaterial.localLoadPath + "    ");
@@ -35,7 +35,7 @@ public class LocalLoadManager : MonoSingleton<LocalLoadManager>
     {
         bool isDownLoad;
 
-        Debug.Log("Hjj   DownloadFile :" + downloadMaterial.localLoadPath + "    ");
+        Debug.Log("Hjj   DownloadFile :" + downloadMaterial.localLoadPath + "    " + downloadMaterial.type);
         using (UnityWebRequest webRequest = new UnityWebRequest(downloadMaterial.localLoadPath, UnityWebRequest.kHttpVerbGET))
         {
             webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();

+ 35 - 2
Assets/Scripts/UI/GameManager.cs

@@ -215,6 +215,7 @@ public class GameManager : MonoSingleton<GameManager>
        // Debug.unityLogger.logEnabled = false;
     }
 
+    public bool isShowDownTip;
     private void Start()
     {
         this.gameObject.AddComponent<TimerMgr>();
@@ -250,8 +251,36 @@ public class GameManager : MonoSingleton<GameManager>
         }
         m_MinMap.gameObject.SetActive(false);
         Map.SetActive(false);
-    }
 
+
+        TimerMgr.Instance.CreateTimer(()=> {
+            if(isShowDownTip)
+            {
+
+                if (COSDownLoad.showDownLoadCount > COSDownLoad.showDownEndLoadCount)
+                {
+                    if (downLoadCount == 0)
+                    {
+                        downLoadCount = COSDownLoad.showDownEndLoadCount;
+                    }
+
+                    string str = string.Format("{0}/{1}正在下载,{2}%", (COSDownLoad.showDownEndLoadCount - downLoadCount), COSDownLoad.showDownLoadCount - downLoadCount, COSDownLoad.showDownLoadPre);
+                    UIManager.Instance.ShowUI(UINameConfig.LoadingPanel, typeof(LoadingPanel), (int)ELoadState.download);
+                    ((LoadingPanel)UIManager.Instance.GetUI(UINameConfig.LoadingPanel)).TextStr = str;
+
+                }
+                else
+                {
+                    if (downLoadCount != 0)
+                    {
+                        UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
+                        downLoadCount = 0;
+                    }
+                }
+            }
+        },1,-1);
+    }
+    int downLoadCount = 0;
     private void LateUpdate()
     {
         // if (API_GSXR_Slam.GSXR_Get_Head() != null && m_IsRuning)
@@ -261,7 +290,8 @@ public class GameManager : MonoSingleton<GameManager>
             //m_SetBtn.transform.position = API_GSXR_Slam.GSXR_Get_Head().localPosition + Player.transform.forward * 1.3f+ new Vector3(0, 1f, 0);
             //m_SetBtn.transform.localPosition = API_GSXR_Slam.GSXR_Get_Head().localPosition + Player.transform.forward * 1.3f + new Vector3(0, 1f, 0);
             m_SetBtn.transform.position = OpenXRCamera.Instance.head.position + Player.transform.forward * 1.3f + new Vector3(-0.2f, 1f, 0);
-      //  }
+        //  }
+
     }
 
     public void Init()
@@ -798,6 +828,9 @@ public class GameManager : MonoSingleton<GameManager>
                 StartCreateScene(SceneValue);
             }
             GetMinMapBack?.Invoke(true);
+
+
+
         }else
         {
 

+ 3 - 0
Assets/Scripts/UI/LoginPanel.cs

@@ -441,6 +441,8 @@ public class LoginPanel : BaseUI
         Debug.LogError("获取场景列表失败");
     }
 
+
+
     /// <summary>
     /// 绑定设备
     /// </summary>
@@ -694,6 +696,7 @@ public class LoginPanel : BaseUI
             m_SN.text = SendSN.GetSN();
             //m_SN.text = API_GSXR_Slam.SlamManager.plugin.SN;
         }
+
     }
 
     protected override void OnHide()

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

@@ -69,6 +69,7 @@ public class SceneChoose : BaseUI
 
     private void OnClickOKBtn()
     {
+        m_OkBtn.interactable = false;
         if (m_CurrentData != null)
         {
             //根据场景数据,下载资源
@@ -97,12 +98,23 @@ public class SceneChoose : BaseUI
                     Debug.Log("scene.backgroundImages===>" + mes);
                     Debug.Log("scene.backgroundImages===>"+ scene.backgroundImages.Count);
                     GameManager.Instance.MapPicUrl = scene.backgroundImages[0].base64;
+                    GameManager.Instance.isShowDownTip = true;
                     GameManager.Instance.GetMinMap(scene, (bool back) =>
                     {
                         if (back)
                         {
                             GetSNInit();
                         }
+                        else
+                        {
+
+                            UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
+                            Module_Notice.getInstance.SetNoticeInfo("场景地图获取失败", "请至网页端检查场景数据", NoticeType.Normal, 1.7f);
+                            Module_Notice.getInstance._Follower.WindowAnchor = TextAnchor.UpperCenter;
+                            Module_Notice.getInstance.StartNotice(3f);
+                            UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
+                            m_OkBtn.interactable = true;
+                        }
 
                     } );
 
@@ -114,6 +126,7 @@ public class SceneChoose : BaseUI
                     Module_Notice.getInstance._Follower.WindowAnchor = TextAnchor.UpperCenter;
                     Module_Notice.getInstance.StartNotice(3f);
                     UIManager.Instance.HideUI(UINameConfig.LoadingPanel);
+                    m_OkBtn.interactable = true;
                 }
             });
         }