各个平台的路径

  1. 编辑器下运行的路径
  2. 编译成安装包之后运行的路径
  3. Android 真机读取
  4. iOS,MAC,Windows 平台读取

编辑器下运行的路径

Platform Method Path Relative,absolute
mac-UnityEditor Application.dataPath xxx/项目名字/Assets absolute(绝对路径)
mac-UnityEditor Application.streamingAssetsPath xxx/项目名字/Assets/StreamingAssets absolute(绝对路径)
mac-UnityEditor Application.persistentDataPath /Users/用户名字/Library/Application Support/打包的名字/AB absolute(绝对路径)
mac-UnityEditor Application.temporaryCachePath /var/folders/n0/xxx/T/打包的名字/AB absolute(绝对路径)
windows-UnityEditor Application.dataPath xxx/项目名字/Assets absolute(绝对路径)
windows-UnityEditor Application.streamingAssetsPath xxx/项目名字/Assets/StreamingAssets absolute(绝对路径)
windows-UnityEditor Application.persistentDataPath C:/Users/用户名字/AppData/LocalLow/打包的名字/项目名字 absolute(绝对路径)
windows-UnityEditor Application.temporaryCachePath C:/Users/ADMINI~1/AppData/Local/Temp/打包的名字/项目名字 absolute(绝对路径)

编译成安装包之后运行的路径

Platform Method Path Relative,absolute
mac.app Application.dataPath xxx/mac.app/Contents absolute(绝对路径)
mac.app Application.streamingAssetsPath xxx/mac.app/Contents/Resources/Data/StreamingAssets absolute(绝对路径)
mac.app Application.persistentDataPath /Users/用户名字/Library/Application Support/打包的名字/AB absolute(绝对路径)
mac.app Application.temporaryCachePath /var/folders/n0/xxx/T/打包的名字/AB absolute(绝对路径)
windows.exe Application.dataPath xxx/Assets absolute(绝对路径)
windows.exe Application.streamingAssetsPath xxx/Assets/StreamingAssets absolute(绝对路径)
windows.exe Application.persistentDataPath C:/Users/用户名字/AppData/LocalLow/打包的名字/项目名字 absolute(绝对路径)
windows.exe Application.temporaryCachePath C:/Users/ADMINI~1/AppData/Local/Temp/打包的名字/项目名字 absolute(绝对路径)
Android.apk Application.dataPath /data/app/(Package Name)-xxx/base.apk absolute(绝对路径)
Android.apk Application.streamingAssetsPath jar:file:///data/app/(Package Name)-xxx/base.apk!/assets absolute(绝对路径)
Android.apk Application.persistentDataPath /storage/emulated/0/Android/data/(Package Name)/files absolute(绝对路径)
Android.apk Application.temporaryCachePath /storage/emulated/0/Android/data/(Package Name)/cache absolute(绝对路径)
iOS.ipa Application.dataPath /private/var/containers/Bundle/Application/xxx/AB.app/Data absolute(绝对路径)
iOS.ipa Application.streamingAssetsPath /private/var/containers/Bundle/Application/xxx/AB.app/Data/Raw absolute(绝对路径)
iOS.ipa Application.persistentDataPath /var/mobile/Containers/Data/Application/xxx/Documents absolute(绝对路径)
iOS.ipa Application.temporaryCachePath /var/mobile/Containers/Data/Application/xxx/Library/Caches absolute(绝对路径)

Android 真机读取

    //Android 真机读取streamingAssetsPath文件夹下的东西,必须使用 WWW/UnityWebRequest 来进行读取,其他方式读取不了
    WWW www = new WWW(Application.streamingAssetsPath + "/" + "xxx.xxx");  
    yield return www;  
    //加载完成后处理,有点delay  
    ShowPath.text = www.text;

    UnityWebRequest uwr = UnityWebRequest.Get(Application.streamingAssetsPath + "/" + "xxx.xxx");  
    yield return uwr.SendWebRequest();  
    //加载完成后处理,有点delay  
    ShowPath.text = uwr.downloadHandler.text;

iOS,MAC,Windows 平台读取

    //Android 真机读取streamingAssetsPath文件夹下的东西,必须使用 WWW/UnityWebRequest 来进行读取,其他方式读取不了
    WWW www = new WWW("file://" +Application.streamingAssetsPath + "/" + "xxx.xxx");  
    yield return www;  
    //加载完成后处理,有点delay  
    ShowPath.text = www.text;

    UnityWebRequest uwr = UnityWebRequest.Get("file://" + Application.streamingAssetsPath + "/" + "xxx.xxx");  
    yield return uwr.SendWebRequest();  
    //加载完成后处理,有点delay  
    ShowPath.text = uwr.downloadHandler.text;

    string path = Application.streamingAssetsPath + "/" + "xxx.xxx";
    if (File.Exists(path)) //判断文件是否存在
    {
        StreamReader streamReader = File.OpenText(path);
        ShowPath.text = streamReader.ReadToEnd();
        streamReader.Close();
    }

转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 1487842110@qq.com

Love

Title:各个平台的路径

文章字数:708

Author:诸子百家-谁的天下?

Created At:2020-05-11, 11:41:32

Updated At:2021-03-28, 02:59:27

Url:http://yoursite.com/2020/05/11/Unity/Path/%E5%B9%B3%E5%8F%B0%E8%B7%AF%E5%BE%84/

Copyright: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

爱你,爱世人