123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using XRTool.Util;
- public class LoadManager : Singleton<LoadManager>
- {
- const int maxLoad = 5;
- int nowLoad = 0;
- public LoadManager()
- {
- TimerMgr.Instance.CreateTimer(() => {
- if(downloadQueueList.Count>0&& nowLoad< maxLoad)
- {
- for (int i = 0; i < downloadQueueList.Count; i++)
- {
- DownLoadItem item = downloadQueueList.Dequeue();
- Debug.Log("正在下载===>"+ item.name);
- item.onProgress += (float f) => {
- Debug.Log("下载进度===>" + f);
- };
- item.callback += (bool b) => {
- Debug.Log("下载完成===>" );
- nowLoad--;
- };
- GameScene.Instance.StartCoroutine( item.DownloadFile());
- nowLoad++;
- if(nowLoad>= maxLoad)
- {
- break;
- }
- }
- }
-
-
- }, -1);
- }
- public Dictionary<string, DownLoadItem> downList = new Dictionary<string, DownLoadItem>();
- public void load(ModelItem model, Action<float> onProgress, Action<GameObject> callback)
- {
- string dName = getLoadName(model.url, model.Version);
- if (!downList.ContainsKey(dName))
- {
- GameObject obj = new GameObject(dName);
- DownLoadItem dli = obj.AddComponent<DownLoadItem>();
- dli.Init(model.url, model.id);
- }
- downList[dName].onProgress += (float f) => {
- onProgress.Invoke(f);
- };
- downList[dName].callback += (bool b) => {
- if(b)
- {
- if (!downList[dName].isAction)
- {
-
- switch (model.type)
- {
- case ModelItem.ModelType.Image:
- break;
- case ModelItem.ModelType.Video:
- break;
- case ModelItem.ModelType.ABModel:
- break;
- }
- }
- }
- else
- {
-
- }
- };
- }
- public void loadVuforia(string xmlFile, string datFile, Action<bool> xmlcallback, Action<bool> datcallback)
- {
- GameObject xmlFileDownObj = new GameObject("VufroiaTriggerDownLoad_xmlFile");
- DownLoadItem xmlFileItem = xmlFileDownObj.AddComponent<DownLoadItem>();
- xmlFileItem.Init(xmlFile, "VufroiaTriggerDownLoad_xmlFile");
- xmlFileItem.onProgress += (float f) => {
- };
- xmlFileItem.callback += (bool b) =>
- {
- if (b)
- {
- File.WriteAllBytes(VufroiaTrigger.LoaclxmlFile, xmlFileItem.downLoadData);
- }
- xmlcallback.Invoke(b);
- };
- GameObject datFileObj = new GameObject("VufroiaTriggerDownLoad_datFile");
- DownLoadItem datFileItem = datFileObj.AddComponent<DownLoadItem>();
- datFileItem.Init(datFile, "VufroiaTriggerDownLoad_xmlFile");
- datFileItem.onProgress += (float f) => {
- };
- datFileItem.callback += (bool b) =>
- {
- if (b)
- {
- File.WriteAllBytes(VufroiaTrigger.LoacldatFile, datFileItem.downLoadData);
- }
- datcallback.Invoke(b);
- };
- }
- public string getLoadName(string url, string version)
- {
- return url + "_" + version;
- }
- public Queue<DownLoadItem> downloadQueueList = new Queue<DownLoadItem>();
- }
|