123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- 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 = 3;
- int nowLoad = 0;
- public LoadManager()
- {
- TimerMgr.Instance.CreateTimer(() => {
- if (downloadQueueList.Count>0&& nowLoad< maxLoad)
- {
- int ct = downloadQueueList.Count;
-
- for (int i = 0; i < ct; i++)
- {
- DownLoadItem item = downloadQueueList.Dequeue();
- item.onProgress += (float f) => {
- Debug.Log("下载进度===>" + f);
- };
- item.callback += (bool b) => {
- Debug.Log("下载完成===>" + nowLoad);
- nowLoad--;
- };
-
- item.DownloadFileMsg();
- nowLoad++;
- if(nowLoad>= maxLoad)
- {
- break;
- }
- }
- }
-
-
- }, 1,-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);
- Debug.Log("dName ======> " + dName+ " model.url==>"+ model.url);
- if (!downList.ContainsKey(dName))
- {
- GameObject obj = new GameObject(dName);
- DownLoadItem dli = obj.AddComponent<DownLoadItem>();
- dli.Init(model.url, model.uid ,model.modelType,model.updateTime);
- downList.Add(dName, dli);
- }
-
- downList[dName].onProgress += (float f) => {
- onProgress.Invoke(f);
- };
- downList[dName].callback += (bool b) => {
- if(b)
- {
- if (!downList[dName].isAction)
- {
-
- switch (model.modelType)
- {
- case ModelType.Image:
- break;
- case ModelType.Video:
- break;
- case ModelType.ABModel:
- break;
- }
- if(downList[dName].downLoadData!=null)
- {
- Debug.Log(" LoadManager " + dName + " Length : " + downList[dName].downLoadData.Length);
- model.SetData(downList[dName].downLoadData);
- }else if(model.prefabModel==null)
- {
- model.prefabModel = new GameObject("空物体"+ downList[dName].id);
- }
- callback.Invoke(model.prefabModel);
- }
- }
- else
- {
-
- }
- };
- }
- public void loadVuforia(string xmlFile, string datFile, Action<bool> xmlcallback, Action<bool> datcallback)
- {
- if (!Directory.Exists(Application.persistentDataPath + "/StreamingAssets"))
- {
- Directory.CreateDirectory(Application.persistentDataPath + "/StreamingAssets");
- if(!Directory.Exists(Application.persistentDataPath + "/StreamingAssets/Vuforia"))
- {
- Directory.CreateDirectory(Application.persistentDataPath + "/StreamingAssets/Vuforia");
- }
- }
- GameObject xmlFileDownObj = new GameObject("VufroiaTriggerDownLoad_xmlFile");
- DownLoadItem xmlFileItem = xmlFileDownObj.AddComponent<DownLoadItem>();
- xmlFileItem.Init(xmlFile, "VufroiaTriggerDownLoad_xmlFile",ModelType.vuforial, long.Parse(GameManager.Instance.m_scene.updateTime));
- xmlFileItem.onProgress += (float f) => {
- };
- xmlFileItem.callback += (bool b) =>
- {
- Debug.Log("Vuforia 下载完成");
- if (b)
- {
- Debug.Log("Vuforia 下载完成 ===>" + VufroiaTrigger.LoacldatFile);
-
- }
- xmlcallback.Invoke(b);
- };
- GameObject datFileObj = new GameObject("VufroiaTriggerDownLoad_datFile");
- DownLoadItem datFileItem = datFileObj.AddComponent<DownLoadItem>();
- datFileItem.Init(datFile, "VufroiaTriggerDownLoad_xmlFile",ModelType.vuforial, long.Parse(GameManager.Instance.m_scene.updateTime));
- datFileItem.onProgress += (float f) => {
- };
- datFileItem.callback += (bool b) =>
- {
- Debug.Log("Vuforia 下载完成");
- if (b)
- {
- Debug.Log("Vuforia 下载完成 ===>"+ VufroiaTrigger.LoacldatFile);
-
- }
- datcallback.Invoke(b);
- };
- }
- public string getLoadName(string url, string version)
- {
- return url + "_" + version;
- }
- public Queue<DownLoadItem> downloadQueueList = new Queue<DownLoadItem>();
- }
|