Unity copies streamingassets to persistentassets, and then loads them from persistentassets into the scenario using www. streamingassets
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;
}