天天看點

03.AB包補

03.AB包補
03.AB包補
03.AB包補

01.生成AB包

03.AB包補
03.AB包補
03.AB包補
03.AB包補
03.AB包補
03.AB包補
03.AB包補

02.使用資源檔案

03.AB包補
//加載AB包
        AssetBundle asset= AssetBundle.LoadFromFile(Application.streamingAssetsPath+ "/model");
        //加載資源  
        Instantiate(asset.LoadAsset<GameObject>("Cube"));      
03.AB包補
public Image image;
    IEnumerator Load(string abName,string iconName)
    {
        AssetBundleCreateRequest request=AssetBundle.LoadFromFileAsync(Application.streamingAssetsPath + "/" + abName);
        yield return request;
       AssetBundleRequest sprite=request.assetBundle.LoadAssetAsync<Sprite>(iconName);
       yield return sprite;
       image.sprite = sprite.asset as Sprite;

    }      

03.資源依賴

03.AB包補
AssetBundle asset= AssetBundle.LoadFromFile(Application.streamingAssetsPath+ "/model");
        AssetBundle assetMain=AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/PC");
        AssetBundleManifest abMainfest=assetMain.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
        string[] str=abMainfest.GetAllDependencies("model");
        for (int i = 0; i < str.Length; i++)
        {
            AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + str[i]);
        }