ios中while()和 android中的不同之处
?
ios中while()不能www方式讀取文件
void FDJson() {using(WWW _load = new WWW("file://"+FileFunc.GetStreamPathRW("FontPreferenceC.json"))) // {while(!_load.isDone){}}
}
安卓卻可以這樣讀取
?
經過修改
IEnumerator FDJson() {using(WWW _load = new WWW("file://"+FileFunc.GetStreamPathRW("FontPreferenceC.json"))) // {while(!_load.isDone){yield return null;} } }?
可以在ios下正常讀取了
?
?
但是這個要用到IEnumerator 枚舉器,很不方便,所以讀取文件最好用system.io接口讀取
public static string ReadTextFromFile (string path){if (System.IO.File.Exists (path)){return System.IO.File.ReadAllText (path, System.Text.Encoding.UTF8);}else return null;}?
但io在安卓中不適用,因為安卓的文件都是jar壓縮格式,所以在安卓中要用www讀取文件,
http://answers.unity3d.com/questions/210909/android-streamingassets-file-access.html
So I was never able to figure out if it is possible to use the System.IO.FileInfo class to check the existence of a file that is added to your Android .APK file through the?StreamingAssets?directory. At this point I really doubt it's possible at all. The reason for this is that the .APK file is an archive, as you may know you can open a .APK file using any archiving utility (WinRAR for example) to inspect it's contents as I touched on above. So the FileInfo class apparently does not support archives like this.
Fortunately the WWW class does support a URI in the style of a?JAR URL. So instead I am just pointing my WWW object at the location where the file might be (using the correct JAR URL syntax) and seeing if I come back with an error.
This forums post?was extremely insightful in showing how exactly to open a file from the?StreamingAssets?folder. I'm kind of surprised that this issue isn't better documented, but hopefully in the future this post will save someone a lot of time.
In review:
?
?
轉載于:https://www.cnblogs.com/pengyingh/archive/2013/04/18/3029727.html
總結
以上是生活随笔為你收集整理的ios中while()和 android中的不同之处的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Exchange server 2013
- 下一篇: [WorldWind学习]12.Wavi