AssetBundle for unity

AssetBundle for Unity

首先推薦讀取官方doc:https://docs.unity3d.com/Manual/AssetBundlesIntro.html

基礎:打包&加載

打包

使用自編譯打包工具

    [MenuItem("AssetBundles/BunildBundles")]
    static void BulidAssetBundles()
    {
        //Assets/AssetBundles 將bundle打包到Asset文件下的AssetBundles內
        BuildPipeline.BuildAssetBundles("Assets/AssetBundles", BuildAssetBundleOptions.None, BuildTarget.StandaloneOSXUniversal);
    }
打包之後


加載

資源打包好之後我們存放在server,如何從server下載這些資源?

    public  string loadUrl;//serve address..
    public string assetname;//prefab name
	// Use this for initialization
	IEnumerator Start () {
	    using (WWW www = new WWW(loadUrl))
	    {
            yield return www;//wait load completed..

            if (www.error != null)
            {
                Debug.Log("網絡連接錯誤");
            }
            else
            {
                AssetBundle asset = www.assetBundle;
                Object obj = asset.LoadAsset(assetname);

                Instantiate(obj); //Init prefabs
                asset.Unload(false); //false==unload only load complete
            }
        }
	}
測試:

路徑:file://F:/My Pro/AssetBundle Pro/Assets/AssetBundles/cylinder.assetbundle



以上就是最最基礎的最入門的東西了。

(未完待續。。。。。。

打包中遇到的問題

1.平臺不支持,如果你的unity打包出現如圖問題


請修改打包代碼如下:

		BuildPipeline.BuildAssetBundles ("Assets/AllResources/AssetBundles", BuildAssetBundleOptions.None);

工程下載地址

鏈接:http://pan.baidu.com/s/1kVG9W8n 密碼:0836

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