public void LoadResReturnWWW(string name, Action <WWW> callback) { string path = MyUnityTools.AppContentPath() + name; Debug.Log("加载:" + path); StartCoroutine(LoaderRes(path, callback)); }
/// <summary> /// 释放资源,把streamasset下的资源拷贝到平台对应的沙盒目录 /// </summary> IEnumerator OnExtractResource() { string resPath = MyUnityTools.AppContentPath(); //游戏包资源目录 string dataPath = MyUnityTools.DataPath; //数据目录 if (Directory.Exists(dataPath)) { Directory.Delete(dataPath, true); } Directory.CreateDirectory(dataPath); string infile = resPath + m_versionTxtName; string outfile = dataPath + m_versionTxtName; if (File.Exists(outfile)) { File.Delete(outfile); } string message = "正在解包文件:>" + m_versionTxtName; Debug.Log("infile:" + infile); Debug.Log("outfile:" + outfile); Debug.Log(message); //dispatcher.Dispatch (NotiConst.UPDATE_MESSAGE, message); //只有Android平台要流方式www,其它平台都可以IO方式 if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(infile); yield return(www); if (www.isDone) { File.WriteAllBytes(outfile, www.bytes); } yield return(0); } else { File.Copy(infile, outfile, true); } yield return(new WaitForEndOfFrame()); //释放所有文件到数据目录 string[] files = File.ReadAllLines(outfile); for (int i = 0; i < files.Length; i++) { if (i == 0) //第一行不处理 { continue; } string file = files[i]; string[] fs = file.Split('|'); infile = resPath + fs[0]; outfile = dataPath + fs[0]; message = "正在解包文件:>" + fs[0]; Debug.Log("正在解包文件:>" + infile); //dispatcher.Dispatch (NotiConst.UPDATE_MESSAGE, message); string dir = Path.GetDirectoryName(outfile); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } if (Application.platform == RuntimePlatform.Android) { WWW www = new WWW(infile); yield return(www); if (www.isDone) { File.WriteAllBytes(outfile, www.bytes); } yield return(0); } else { if (File.Exists(outfile)) { File.Delete(outfile); } File.Copy(infile, outfile, true); } yield return(new WaitForEndOfFrame()); } message = "解包完成!!!"; Debug.Log(message); //dispatcher.Dispatch (NotiConst.UPDATE_MESSAGE,""); //dispatcher.Dispatch (NotiConst.UPDATE_STATE, message); //dispatcher.Dispatch (NotiConst.UPDATE_PROGRESS, 0.5f); yield return(new WaitForSeconds(0.1f)); message = string.Empty; //释放完成,开始启动更新资源 StartUpdateVersion(); }