Unity3D - AssetBundle 在Android機子上進行讀取

我看到官方文檔中說明:
Note that bundles are not fully compatible between platforms. A bundle built for any of the standalone platforms (including webplayer) can be loaded on any of those platforms but not on iOS or Android. Furthermore, a bundle built for iOS is not compatible with Android and vice versa.

但是我們看到,用以下步驟進行在Android機子上使用AssetBundle

重點有2點:

  1. Use the option "BuildTarget.Android".
  2. Describe the path with triple slash "file:///"

以下是步驟:

  1. Delete directories "Per Texture Materials", "assetbundles", and so on.  把已經導出過的包刪掉
  2. Use the option "BuildTarget.Android" to all "BuildPipeline.BuildAssetBundle".   要把BuildTarget爲Android平臺!!!
  3. Run these on Editor. Character Generator/Generate Materials Character Generator/Create Assetbundles Character Generator/Update Character Element Database  
  4. Copy Assetbundles database to Android device which like "/mnt/sdcard/assetbundles/"  把這些包放到Android的指定目錄下
  5. Modify AssetbundleBaseURL. (the point was "file:///") 修改獲取AssetbundleBaseURL基礎路徑的地址
public static string AssetbundleBaseURL
{
    get
    {
        if (Application.platform == RuntimePlatform.WindowsWebPlayer || Application.platform == RuntimePlatform.OSXWebPlayer)
        {
            return Application.dataPath + "/assetbundles/";
        }
        else if (Application.platform == RuntimePlatform.Android)
        {
            return "file:///mnt/sdcard/assetbundles/";
        }
        else
        {
            return "file://" + Application.dataPath + "/../assetbundles/";
        }
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章