您当前的位置: 首页 >  unity

程序员正茂

暂无认证

  • 1浏览

    0关注

    283博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity安卓Android平台StreamingAssets下文件的读取

程序员正茂 发布时间:2021-04-30 10:25:30 ,浏览量:1

在Unity的StreamingAssets下放了一个shootRecord.txt文件

在安卓平台下变成了jar:file:///data/app/com.enjoy2.EnjoyReplay2-vjTe-kN-zK-elcFb7aPwJw==/base.apk!/assets/shootRecord.txt

由于安卓平台jar变成了压缩包,所以无法直接使用File.ReadAllLines来读取,而要使用www。

string dataFile = Path.Combine(Application.streamingAssetsPath, "shootRecord.txt");
if (Application.platform == RuntimePlatform.Android)
        {
            WWW reader = new WWW(dataFile);
            while (!reader.isDone) { }

            string textString = reader.text;
            Debug.Log(textString.Length);
            List striparr = textString.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();
            List lines = striparr.Where(s => !string.IsNullOrEmpty(s)).ToList();
        }
        else
        {
            string textString = File.ReadAllText(dataFile);
            Debug.Log(textString.Length);

            List striparr = textString.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();
            List lines = striparr.Where(s => !string.IsNullOrEmpty(s)).ToList();
        }

 

关注
打赏
1660743125
查看更多评论
立即登录/注册

微信扫码登录

0.0410s