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 mDownloadWWWList = new List(); 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(); } } }