Unity copied from Streamingassets to Persistentassets, then loaded into scene from persistentassets with www

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.