Unity 從StreamingAssets文件夾和PersistentData文件夾 保存讀取AssetBundle資源 路徑詳解


項目中的資源一般我們打包成AssetBundle格式

方便我們加載熱更

 

AssetBundle文件 一般保存在StreamingAssets文件夾PersistentData文件夾

 

首先我們看這兩個文件夾有什么區別

StreamingAssets
可讀取、不可寫入

工程Assets根目錄下StreamingAssets文件夾
文件夾內容不壓縮打包到apk、ipa包內

 

PersistentData
可讀取、可寫入
沙盒目錄,應用程序安裝運行后才會出現

 

綜合上面的區別我們可以總結

*StreamingAssets   不能寫入  隨包發包   適合存放一些初始化的AssetBundle資源 如 登入頁 加載頁等

*PersistentData   適合存放 運行程序下載的AssetBundle資源

 

 

 

 

 

然后我們看下這兩個文件夾在 各平台 運行時 打印的 路徑地址

 

StreamingAssets  
WindowsEditor C:/Users/zq/Desktop/Test/Assets/StreamingAssets(工程目錄/Assets/StreamingAssets)
OSXEditor /Users/zouqiang/Desktop/Test/Assets/StreamingAssets(工程目錄/Assets/StreamingAssets)
Android jar:file:///data/app/com.Company.Test-1.apk!/assets(安裝目錄/assets)
IPhonePlayer /var/containers/Bundle/Application/5C9D81B5-2A21-45BC-B6DC-12B704976D22/Test.app/Data/Raw

 

PersistentData  
WindowsEditor C:/Users/zq/AppData/LocalLow/DefaultCompany/Test
OSXEditor /Users/zouqiang/Library/Application Support/DefaultCompany/Test
Android /storage/emulated/0/Android/data/com.Company.Test/files
IPhonePlayer /var/mobile/Containers/Data/Application/F96BACED-63D5-45AE-B2A7-738A87545A8F/Documents

 

 

 

 

StreamingAssets  各工程路徑(資源更新可直接替換對應的文件  實現快速打包或測試)

Unity C:\Users\zq\Desktop\Test\Assets\StreamingAssets
Eclipse C:\Users\zq\Desktop\eclipse\Test\assets
Xcode C:\Users\zq\Desktop\eclipse\Test\assets

 

 

 

 

 

 

在使用
AssetBundle.LoadFromFile  同步加載
AssetBundle.LoadFromFileAsync  異步加載
StreamingAssets文件夾里面的AssetBundle
要注意

Android  獲得去方式為  Application.dataPath + "!assets"

其他平台   獲取的方式為 Application.streamingAssetsPath

 

 

使用
WWW 異步加載
加載StreamingAssets文件夾里面的AssetBundle
要注意

Android  獲得去方式為  Application.streamingAssetsPath

其他平台   獲取的方式為 "file://" + Application.streamingAssetsPath

 

 

 

 

PersistentData文件夾 獲取的方式都為  Application.persistentDataPath


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM