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 =
#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;
        }
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值