1. 程式人生 > >unity使用AssetBundle使用記錄四--載入與解除安裝(1)

unity使用AssetBundle使用記錄四--載入與解除安裝(1)

IEnumerator LoadAssetBundle()
    {
        //測試正確載入
        WWW www = new WWW(GetPath() + "obj1.ab"); //本地工程中的路徑資源

        if (!www.isDone)
            yield return 0;
        yield return www;

        AssetBundle ab = www.assetBundle;
        GameObject g = ab.LoadAsset("cubeasset") as GameObject;
        Instantiate(g);

        //AssetBundle ab1 = AssetBundle.CreateFromFile(""); //過時,不能用

        //GetPath() + "obj1.ab"  測試不能載入(完整路徑file://E:/unity project/AssetBundle_Test/Assets/StreamingAssets/obj1.ab)為什麼這種路徑是錯的?
        //"Assets/StreamingAssets/obj2.ab"  測試能載入
        //"E:/unity project/AssetBundle_Test/Assets/StreamingAssets/obj2.ab"  測試能載入
        AssetBundle ab2 = AssetBundle.LoadFromFile("Assets/StreamingAssets/obj2.ab");
        
        GameObject g2 = ab2.LoadAsset("Quad") as GameObject;
        Instantiate(g2);
    }