• 【Unity】persistentDataPath、streamingAssetsPath和dataPath


    介绍

    我们在用Unity进行开发时,资源路径是我们最常用到的,下面我就来简单介绍一下几种常用的路径。

    1.dataPath

    dataPath是包含游戏数据文件夹的路径,是app程序包安装路径

    Windows: xxx /Assets (如下图)
    Mac: xxx /Assets

    在这里插入图片描述

    Android: /data/app/xxx.xxx.xxx.apk
    注意:此路径指向.apk文件,.apk是一个文件,不是目录,故不能读写

    IOS: Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data

    总结:dataPath最常用的是在编辑器下,是自定义工具开发必用的路径

    2.StreamingAssetsPath

    StreamingAssetsPath用于返回数据流的缓存目录,返回路径为相对路径 (只读),如下图。
    在这里插入图片描述
    Windows: /Assets/StreamingAssets
    Mac: /Assets/StreamingAssets
    Android: jar:file:///data/app/xxx.xxx.xxx.apk/!/assets
    IOS: Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data/Raw

    程序读取

    //ios平台
    string strStreamResPath = "file://"+  Application.streamingAssetsPath;
    //其他平台
    string strStreamResPath = Application.streamingAssetsPath;
    
    • 1
    • 2
    • 3
    • 4

    总结:strStreamResPath 常用于放打包后可以修改替换的文件,比如SDK渠道信息,AB资源,CG视频等

    3.PersistentDataPath

    PersistentDataPath是一个持久化数据存储目录的路径 ,可以在此路径下存储一些持久化的数据文件。

    Windows: C:/Users/xxxx/AppData/LocalLow/CompanyName/ProductName
    Mac: /Users/xxxx/Library/Caches/CompanyName/ProductName
    Android: /data/data/xxx.xxx.xxx/files
    IOS: Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents

    总结:①用户生成的数据、配置文件等保存在这里,确保这些数据在应用程序关闭后依然存在。②从远端下载的AB等资源也保持于此目录。

    4.temporaryCachePath

    temporaryCachePath用于返回一个临时数据的缓冲目录 。

    UnityEditor: C:/Users/xxxx/AppData/Local/Temp/CompanyName/ProductName
    Android: /data/data/xxx.xxx.xxx/cache
    IOS: Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches

    总结:temporaryCachePath这个路径不常用,至少我认为是不常用的,因为我做游戏十年多了,从来没有用过这个路径。

  • 相关阅读:
    网格切割算法
    游戏合作伙伴专题:BreederDAO 与《王国联盟》结成联盟
    jsscript
    Nginx搭建视频流媒体服务(Win)
    行内元素有哪些,块级元素呢? 空元素有哪些呢?
    Django 模型层的操作(Django-05 )
    树莓派4B开发之五安装yoloV5
    一文解决Cellphonedb单细胞互作分析及可视化作图(2)
    Springboot使用Aop保存接口请求日志到mysql(及解决Interceptor拦截器中引用mapper和service为null)
    Python遍历文件及子文件下的指定文件
  • 原文地址:https://blog.csdn.net/qq_30144243/article/details/136671518