首先,講一講unity3d中的一些目錄,不是Assets下的Resources等特殊文件夾,而是系統讀寫目錄:
IOS:
Application.dataPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data
Application.streamingAssetsPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/Data/Raw
Application.persistentDataPath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Documents
Application.temporaryCachePath : Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Library/Caches
Android:
Application.dataPath : /data/app/xxx.xxx.xxx.apk
Application.streamingAssetsPath : jar:file:///data/app/xxx.xxx.xxx.apk/!/assets
Application.persistentDataPath : /data/data/xxx.xxx.xxx/files
Application.temporaryCachePath : /data/data/xxx.xxx.xxx/cache
Windows:
Application.dataPath : /Assets
Application.streamingAssetsPath : /Assets/streamingAssetsPath
Application.persistentDataPath : /xxx/xxx/xxx
Application.temporaryCachePath : /xx/xx/xx
dataPath:程序安裝目錄,或者說程序根目錄,只讀
streamingAssetsPath:未被壓縮的資源存儲目錄,只讀
persistentDataPath:持久化數據目錄,沙盒目錄,通常作爲存盤目錄,讀寫
temporaryCachePath:臨時緩存目錄,會被系統回收,可存放下載的臨時文件,讀寫
在Windows下,Resources下面的資源不壓縮,所以可以使用datapath/Resouces獲取,而在IOS和Android下面,Resources目錄資源被壓縮,此方法無法獲取Resouces目錄下的資源,必須使用Resources.Load或者別的系統方法才能獲取Resources目錄下的資源。streamingAssetsPath下的資源可WWW類獲取。所以,通常情況下真機運行時dataPath不會使用到。