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 =
#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 copied from Streamingassets to Persistentassets, then loaded into scene from persistentassets with www