首页 > 代码库 > unity从streamingassets拷贝到persistentassets,再从persistentassets用www加载进入场景
unity从streamingassets拷贝到persistentassets,再从persistentassets用www加载进入场景
void OnClick()
{
//StartCoroutine(LoadLevel());
StartCoroutine(LoadFrompersister());
}
IEnumerator LoadLevel()
{
string url = "file://" + Application.dataPath + "/2.Android.unity3d";
Debug.Log(url);
WWW www = WWW.LoadFromCacheOrDownload(url, 3);
yield return www;
if (www.error != null) yield return null;
AssetBundle b = www.assetBundle;
Application.LoadLevel("2");
}
IEnumerator LoadFrompersister()
{
try
{
FileStream fs = File.Create(Application.persistentDataPath + "/1.txt");
fs.Close();
fs = File.Create(Application.persistentDataPath + "/1.txt");
fs.Close();
lab.text = Application.persistentDataPath;
}
catch (System.Exception ex)
{
lab.text = ex.Message;
}
string des = Application.persistentDataPath + "/2.Android.unity";
string src =http://www.mamicode.com/
#if UNITY_EDITOR
"file:///"+Application.streamingAssetsPath + "/2.Android.unity3d";
des = des.Replace(‘/‘, ‘\\‘);
#elif UNITY_ANDROID
"jar:file://" + Application.dataPath + "!/assets/2.Android.unity3d";
#endif
Debug.Log("des:"+des);
Debug.Log("src:"+src);
//lab.text = Directory.GetFiles(Application.streamingAssetsPath)[0];
//string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "1.txt");
using (WWW w = new WWW(src))
{
yield return w;
if (string.IsNullOrEmpty(w.error))
{
while (w.isDone == false) yield return null;
if (File.Exists(des))
File.Delete(des);
FileStream fs1 = File.Create(des);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs1, w.bytes);
fs1.Close();
}
else
{
Debug.LogError(w.error);
}
}
string downpath = "file:///" + Application.persistentDataPath + "/2.Android.unity";
Debug.Log("down path:" + downpath);
using (WWW www = WWW.LoadFromCacheOrDownload(downpath, 7))
{
yield return www;
AssetBundle b = www.assetBundle;
Application.LoadLevel("2");
//lab.text = downpath;
}
{
//StartCoroutine(LoadLevel());
StartCoroutine(LoadFrompersister());
}
IEnumerator LoadLevel()
{
string url = "file://" + Application.dataPath + "/2.Android.unity3d";
Debug.Log(url);
WWW www = WWW.LoadFromCacheOrDownload(url, 3);
yield return www;
if (www.error != null) yield return null;
AssetBundle b = www.assetBundle;
Application.LoadLevel("2");
}
IEnumerator LoadFrompersister()
{
try
{
FileStream fs = File.Create(Application.persistentDataPath + "/1.txt");
fs.Close();
fs = File.Create(Application.persistentDataPath + "/1.txt");
fs.Close();
lab.text = Application.persistentDataPath;
}
catch (System.Exception ex)
{
lab.text = ex.Message;
}
string des = Application.persistentDataPath + "/2.Android.unity";
string src =http://www.mamicode.com/
#if UNITY_EDITOR
"file:///"+Application.streamingAssetsPath + "/2.Android.unity3d";
des = des.Replace(‘/‘, ‘\\‘);
#elif UNITY_ANDROID
"jar:file://" + Application.dataPath + "!/assets/2.Android.unity3d";
#endif
Debug.Log("des:"+des);
Debug.Log("src:"+src);
//lab.text = Directory.GetFiles(Application.streamingAssetsPath)[0];
//string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "1.txt");
using (WWW w = new WWW(src))
{
yield return w;
if (string.IsNullOrEmpty(w.error))
{
while (w.isDone == false) yield return null;
if (File.Exists(des))
File.Delete(des);
FileStream fs1 = File.Create(des);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(fs1, w.bytes);
fs1.Close();
}
else
{
Debug.LogError(w.error);
}
}
string downpath = "file:///" + Application.persistentDataPath + "/2.Android.unity";
Debug.Log("down path:" + downpath);
using (WWW www = WWW.LoadFromCacheOrDownload(downpath, 7))
{
yield return www;
AssetBundle b = www.assetBundle;
Application.LoadLevel("2");
//lab.text = downpath;
}
unity从streamingassets拷贝到persistentassets,再从persistentassets用www加载进入场景
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。