項目中的資源通常咱們打包成AssetBundle格式app
方便咱們加載和熱更eclipse
而AssetBundle文件 通常保存在StreamingAssets文件夾或PersistentData文件夾異步
首先咱們看這兩個文件夾有什麼區別測試
StreamingAssets |
可讀取、不可寫入 |
工程Assets根目錄下StreamingAssets文件夾 |
PersistentData |
可讀取、可寫入 |
沙盒目錄,應用程序安裝運行後纔會出現 |
綜合上面的區別咱們能夠總結code
*StreamingAssets 不能寫入 隨包發包 適合存放一些初始化的AssetBundle資源 如 登入頁 加載頁等ip
*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 在各工程路徑(資源更新可直接替換對應的文件 實現快速打包或測試)it
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