1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO;
- using AIPagedLod;
- using UnityEngine.Networking;
- using LitJson;
- public class DownloadFileManager : MonoBehaviour
- {
- public static DownloadFileManager mInstance;
- public List<UnityWebRequest> mDownloadWWWList = new List<UnityWebRequest>();
- public int mMaxCoroutineCount = 2;
- public int mCurrentCoroutineCount = 0;
- void Awake()
- {
- mInstance = this;
- }
- void Update()
- {
- mDownloadWWWList.RemoveAll(item => item.isDone);
- mCurrentCoroutineCount = mDownloadWWWList.Count;
- }
- public bool CanDownload()
- {
- return mDownloadWWWList.Count < mMaxCoroutineCount;
- }
- public void StartDownloadTileFile(PagedLod lod,string baseUrl)
- {
- StartCoroutine(DownloadTileFile(lod, baseUrl));
- }
- public IEnumerator DownloadTileFile(PagedLod pagedLod, string baseUrl)
- {
- string url = baseUrl + "/" + pagedLod.mTileDirPath +"/" +
- pagedLod.gameObject.name + PagedLodConfig.mInstance.GetFileSufix();
- UnityWebRequest www = UnityWebRequest.Get(url);
- www.timeout = 5;
- mDownloadWWWList.Add(www);
- yield return www.SendWebRequest();
- if (www.isHttpError || www.isNetworkError)
- {
- pagedLod.mIsRenderNodeLoaded = false;
- Debug.Log(www.error + " " + url);
- }
- else
- {
- B3dmFileLoader loader = new B3dmFileLoader();
- loader.LoadObjectMeshInfoFromData(www.downloadHandler.data);
- if(loader.mObjectInfoList.Count == 0)
- {
- pagedLod.mIsRenderNodeLoaded = false;
- }
- else
- {
- pagedLod.LoadRenderNode(loader);
- }
- loader.Dispose();
- }
- }
- }
|