public IEnumerator Download(string name) { string url = System.IO.Path.Combine(FloorTextureManager.downloadNewUrl, FloorTextureManager.GetFileName(name)); // Debug.Log(" down load == " + name ); WWW www = new WWW(url); //Debug.Log(url); //定义www为WWW类型并且等于所下载下来的WWW中内容。 while (!www.isDone) { Progress(www); yield return(1); } //返回所下载的www的值 if (string.IsNullOrEmpty(www.error)) { FloorTextureManager.SaveTexture(name, www.texture.EncodeToPNG()); if (EndDownload != null) { EndDownload(www.texture, name); } } else { Debug.Log("DownloadError=>" + www.error + " name == " + name); if (DownloadError != null) { DownloadError(name); } } }
public void ShowTex(string _name) { _name = FloorTextureManager.GetFileName(_name); if (string.IsNullOrEmpty(_name) || textureName == _name || wantTexName == _name) { return; } wantTexName = _name; UIDownloadTexture dt = new UIDownloadTexture(); //检查本地是存否在 if (FloorTextureManager.CheckExist(wantTexName)) { cityFloor.RunProgress(); dt.EndLoadLocal = EndLoad; StartCoroutine(dt.LoadLocal(wantTexName)); } else { //从网络下载 if (Core.Data.usrManager.UserConfig.cartoon == 1) { cityFloor.RunProgress(); dt.EndDownload = EndDownload; dt.DownloadError = DownloadError; StartCoroutine(dt.Download(wantTexName)); } else { EndDownload(null, ""); // cityFloor.SetTexture(null); } } }
// 预下载 public IEnumerator PreDownload(string nextName) { if (Core.Data.usrManager.UserConfig.cartoon == 1) //自动下载 { if (!FloorTextureManager.CheckExist(nextName)) { // Debug.Log(" in preDownload ====== " + nextName); string url = System.IO.Path.Combine(FloorTextureManager.downloadNewUrl, FloorTextureManager.GetFileName(nextName)); WWW www = new WWW(url); yield return(www); if (string.IsNullOrEmpty(www.error)) { FloorTextureManager.SaveTexture(nextName, www.texture.EncodeToPNG()); } else { Debug.LogError(" DownloadError => " + nextName); } } } }
public IEnumerator LoadLocal(string name) { bool isGo = false; if (FloorTextureManager.CheckIsExist(name)) { string strName = (FloorTextureManager.localPath + name).Replace(".jpg", ""); Texture2D nTexture = Resources.Load(strName, typeof(Texture2D)) as Texture2D; // Debug.Log(" load texture " + strName); if (nTexture != null) { if (EndLoadLocal != null) { EndLoadLocal(nTexture); } isGo = true; // Debug.Log(" load is done "); } } if (!isGo) { string url = "file:///" + System.IO.Path.Combine(FloorTextureManager.localUrl, FloorTextureManager.GetFileName(name)); Debug.Log(" Load local =============== " + name); WWW www = new WWW(url); //定义www为WWW类型并且等于所下载下来的WWW中内容。 yield return(www); //返回所下载的www的值 if (string.IsNullOrEmpty(www.error)) { if (EndLoadLocal != null) { Debug.Log("local load is OK"); EndLoadLocal(www.texture); } } } }
// type = 1 L type =2 R public void ShowTex(int type, string _name) { _name = FloorTextureManager.GetFileName(_name); if (type == 1) { if (string.IsNullOrEmpty(_name) || wantTexName_L == _name) { TweenAlpha.Begin(L_texture.gameObject, switchTexTime, 1f); return; } wantTexName_L = _name; } else { if (string.IsNullOrEmpty(_name) || wantTexName_R == _name) { TweenAlpha.Begin(R_texture.gameObject, switchTexTime, 1f); return; } wantTexName_R = _name; } UIDownloadTexture dt = new UIDownloadTexture(); //检查本地是存否在 if (FloorTextureManager.CheckExist(_name)) { this.RunProgress(); if (type == 1) { dt.EndLoadLocal = EndLoadLeft; } else { dt.EndLoadLocal = EndLoadRight; } StartCoroutine(dt.LoadLocal(_name)); } else { //从网络下载 // if (Core.Data.usrManager.UserConfig.cartoon == 1) // { this.RunProgress(); if (type == 1) { dt.EndDownload = EndDownloadLeft; dt.DownloadError = DownloadError_L; } else { dt.EndDownload = EndDownloadRight; dt.DownloadError = DownloadError_R; } StartCoroutine(dt.Download(_name)); // } // else // { // if (type == 1) // EndDownloadLeft(null, ""); // else // EndDownloadRight(null, ""); // } } Resources.UnloadUnusedAssets(); }