• 【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这个路径不常用,至少我认为是不常用的,因为我做游戏十年多了,从来没有用过这个路径。

  • 相关阅读:
    【计算机网络笔记】分组交换中的报文交付时间计算例题
    JAVA小游戏 “拼图”
    V神说以太坊的Token系统
    【MapGIS精品教程】001:MapGIS K9完整图文安装教程
    【数组】数组序号转换
    贪心——122. 买卖股票的最佳时机 II
    信息学奥赛一本通:1171:大整数的因子
    Android自定义注解
    Go 语言中的日期与时间
    亚马逊测评关于IP和DNS的问题
  • 原文地址:https://blog.csdn.net/qq_30144243/article/details/136671518