Unity存储路径具体位置整理(Win+Android+ios)

本文详细介绍了Unity在Windows、Android和iOS平台上的Application.dataPath、persistentDataPath、streamingAssetsPath、Resources和temporaryCachePath等存储路径的具体位置和使用注意事项,包括各路径的读写权限及实际应用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Unity存储路径具体位置整理

一:Application.dataPath:

这个路径在Unity打包工程目录下。通过这个路径可以访问项目中任何文件夹中的资源,
只能在PC端使用。

二:persistentDataPath:(推荐使用)可读、可写

一个持久化数据存储目录的路径,可以在此路径下存储一些持久化的数据文件。 这个路
径可读、可写,一般网络下载的资源都存在这个路径。

三:streamingAssetsPath:

放在这个文件夹中的资源在打包时会原封不动的打包进去,不会压缩。这个路径在PC端是
可读、可写,在移动端是只读路径。在Android设备上这个路径中的资源不能进行iO操作。

四:Resources:

放在这里文件夹中的资源在打包的时候会压缩后全部打包。这个路径是个只读路径,一般
用于存放一下固定不更改的资源。可以通过Resources.Load(“path”);进行动态加载

五:.Application.temporaryCachePath:
此属性返回一个临时数据的缓存目录,跟Application.persistentDataPath类似,但是在
IOS上不能被自动备份。一般情况下不会使用此路径。

Windows:
Application.dataPath
路径一直到工程目录下Assets文件夹
举例:F:/UnityWork/TestAssetBundle/Assets

Application.streamingAssetsPath
路径一直到工程目录下Assets文件夹中的StreamingAssets文件夹
举例:F:/UnityWork/TestAssetBundle/Assets/StreamingAssets

Application.persistentDataPath
持久数据文件夹
举例:C:/Users/dell/AppData/LocalLow/DefaultCompany/TestAssetBundle

Application.temporaryCachePath
临时缓存文件夹
举例:C:/Users/dell/AppData/Local/Temp/DefaultCompany/TestAssetBundle

Android:
Application.dataPath
路径:/data/app/package name-1/base.apk
apk程序包目录:apk的安装路径,/data/app/package name-n/base.apk,
dataPath就是返回此目录。

Application.streamingAssetsPath
路径: jar:file:///data/app/package name-1/base.apk!/assets
内部存储目录: /data/data/package name-n/,用户自己或其它app都不能访问该目录。

打开会发现里面有4个目录(需要root)
Cache:缓存目录,类似于iOS的Cache目录 ,热更新临时文件在此目录
Databases:数据库文件目录
Files:类似于iOS的Documents目录 ,热更新在此目录
shared_prefs:类似于iOS的Preferences目录,用于存放常用设置,比如Unity3D的Player
Prefs就存放于此

Application.persistentDataPath
路径:/storage/emulated/0/Android/data/package name/files
类似于iOS的Documents目录

Application.temporaryCachePath
路径:/storage/emulated/0/Android/data/package name/cache
缓存目录,类似于iOS的Cache目录 ,热更新临时文件在此目录

IOS:
iOS和Mac OS X不同于Windows,app都是在一个沙盒空间中运行,每个app也有一个独立的
数据存储空间,各app彼此不能互相访问、打扰。
app的独立数据存储目录下有三个文件夹:Documents,Library和tmp。

Application.dataPath
路径:/var/containers/Bundle/Application/app sandbox/xxx.app/Data
dataPath是app程序包安装路径,app本身就在这里,此目录是只读的

Application.streamingAssetsPath
路径:/var/containers/Bundle/Application/app sandbox/test.app/Data/Raw
streamingAssetsPath是dataPath下的Raw目录。

Application.persistentDataPath
路径:/var/mobile/Containers/Data/Application/app sandbox/Library/Caches
Documents目录,这个目录用于存储需要长期保存的数据,比如我们的热更新内容就写在这里。
需要注意的是,iCloud会自动备份此目录,如果此目录下写入的内容较多,审核的可能会被苹果拒掉。

Application.temporaryCachePath
路径:/var/mobile/Containers/Data/Application/app sandbox/Documents
Library目录,这个目录下有两个子目录,Caches和Preferences。
Caches:是一个相对临时的目录,适合存放下载缓存的临时文件,空间不足时可能会被系统
清除,Application.temporaryCachePath返回的就是此路径。我把热更新的临时文件写在
这里,等一个版本的所有内容更新完全后,再把内容转移到Documents目录。
Preferences:用于应用存储偏好设置,用NSUserDefaults读取或设置。

注意
tmp目录,临时目录,存放应用运行时临时使用的数据。
需要注意的是,以上无论临时、缓存或者普通目录,如果不需要的数据,都请删除。不要占用用
户的存储空间,像微信就是坏榜样。

下面是各路径对应的OC访问方法
app安装路径:
[[NSBundle mainBundle] resourcePath]

app数据沙盒存储根目录:
NSHomeDirectory()

Documents:
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)

Library:
NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)

Caches:
NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)
Tmp:
NSTemporaryDirectory()

### 回答1: 在 TURBO C 2.0 中,您可以使用 biosdisk() 函数来格式化软盘。 下面是一段代码示例: ``` #include <stdio.h> #include <dos.h> int main() { // 定义扇区的大小 unsigned int sector_size[3] = {512, 512, 1024}; // 定义填充字节 unsigned char fill_char[3] = {0xF6, 0xF6, 0x48}; // 格式化磁道 70 面 0 的前三个扇区 for (int i = 0; i < 3; i++) { int result = biosdisk(2, 0, 70, 0, i + 1, 1, sector_size[i], fill_char[i]); if (result != 0) { printf("格式化扇区 %d 失败,返回码: %d\n", i + 1, result); } } return 0; } ``` 请注意,在使用 biosdisk() 函数之前,需要包含 dos.h 头文件。 希望这能帮到您! ### 回答2: 使用TURBO C 2.0语言,可以通过以下代码格式化软盘的70磁道0面,并分别格式化3个扇区,大小分别为512字节、512字节和1024字节。其中,前两个扇区使用F6填充,第三个扇区使用48填充。 ```c #include<stdlib.h> #include<stdio.h> #include<dos.h> void formatFloppyDisk(){ union REGS regs; regs.h.ah = 0x0;// To format a floppy disk, we set AH=0 regs.h.dl = 0;// Drive number (0=A, 1=B, etc.) regs.x.cx = 0;// Track number to format regs.h.dh = 0;// Head number regs.h.al = 0;// Sector size (0=default, 1=512 bytes, 2=1024 bytes, 3=2048 bytes etc.) int FILL_BYTE = 0;// The byte value to fill the sectors with during formatting int NUM_SECTORS = 3;// Number of sectors to format // To format 70th track 0th head regs.x.ax = 0x1301; // 0x13 = Reset disk system, 01H = Reset only specified drive int86(0x13, &regs, &regs); // BIOS interrupt to reset disk system for (int i=0; i<NUM_SECTORS; i++){ regs.x.ax = 0x3101; // 0x31 = Write Format, 01H = Format only current track regs.x.bx = 0x0001; // 0x00 = Drive A:, 01H = Head 1, 0 = Generate ID Field depending on the disk in the drive 1 = Keep the ID Field all zeros regs.x.cx = 0x0170; // Track number=70(0-79 range) regs.h.dh = 0x00; // Head number=0 or 1 regs.h.al = 0x02; // Control byte=always zero regs.x.dx = i+1; // Sector number starting from 1 regs.x.si = 0x0000; // segment and offset of read/write buffer regs.x.di = 0x0000; // segment and offset of result if(i == 2){ FILL_BYTE = 0x48; // Fill the third sector with 48 regs.x.ax = 0x3102; // 0x31 = Write Format, 02H = Format sequential tracks immediately following the one being formatted }else{ FILL_BYTE = 0xF6; // Fill the first two sectors with F6 } regs.h.ah = FILL_BYTE; // Fill the sector with specified byte int86(0x13, &regs, &regs); // BIOS interrupt to format the specified sector } } int main(){ formatFloppyDisk(); return 0; } ``` 上述代码使用了INT 0x13,即BIOS中断服务例程,来执行软盘格式化操作。通过设置寄存器的不同参数,可以指定要格式化的磁道、面、扇区大小和填充字节。在这个例子中,我们格式化了软盘70磁道0面的3个扇区,前两个扇区使用F6填充,第三个扇区使用48填充。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值