自己比着视频敲的 代码如下:



using System.Collections;

using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.Networking;


public class LoadFromFileExample : MonoBehaviour {

    IEnumerator   Start () {
        //AssetBundle ab = AssetBundle.LoadFromFile("AssetBundles/cubewall.unity3d");
        //AssetBundle ab2 = AssetBundle.LoadFromFile("AssetBundles/share.unity3d");
        //GameObject ob = ab.LoadAsset<GameObject>("cubewall");
        //Instantiate(ob);

        //第一种加载资源AB的方式、LoadFromMemoryAsyncy异步方式 先引入命名空间 using System.IO; 
        // AssetBundleCreateRequest request = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes("AssetBundles/cubeWall.unity3d"));
        //yield return request;
        //AssetBundle ab = request.assetBundle;
        //第一种 加载的方式 不用异步加载
        //AssetBundle ab=   AssetBundle.LoadFromMemory(File.ReadAllBytes("AssetBundles/cubeWall.unity3d"));

        //第二种加载AB的方式 LoadFromFile
        //AssetBundleCreateRequest request=   AssetBundle.LoadFromFileAsync("AssetBundles/cubeWall.unity3d");
        //   yield return request;

        // AssetBundle ab = request.assetBundle;
        //AssetBundle ab=   AssetBundle.LoadFromFile("AssetBundles/cubeWall.unity3d");
        //第三种加载AB的方式 WWW  LoadFromCacheOrDownload

        while (Caching.ready == false)
        {
            yield return null;
        }
        // WWW ww = WWW.LoadFromCacheOrDownload(@"file:///E:\U3DObject\AssetBundleProject\AssetBundles\cubeWall.unity3d", 1);
        //WWW ww = WWW.LoadFromCacheOrDownload(@"http://localhost/AssetBundles/cubeWall.unity3d", 1);
        //yield return ww;
        //if (string.IsNullOrEmpty(  ww.error)==false)
        //{
        //    Debug.Log(ww.error); yield  break;
        //}
        //AssetBundle ab=  ww.assetBundle;
        //第四种方法 使用unityWebRequest  先引入命名空间 using UnityEngine.Networking;
        // string url = @"file:///E:\U3DObject\AssetBundleProject\AssetBundles\cubeWall.unity3d";
        string url = @"http://localhost/AssetBundles/cubeWall.unity3d";
        UnityWebRequest request =   UnityWebRequest.GetAssetBundle(url);
        yield return request.Send();
        // AssetBundle ab=      DownloadHandlerAssetBundle.GetContent(request);  //第一种方法 或者,一下方法
        AssetBundle ab = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
        //使用里面的资源
        GameObject ob = ab.LoadAsset<GameObject>("cubewall");
        Instantiate(ob);
        得到 依赖包 
      AssetBundle minfestAB=   AssetBundle.LoadFromFile("AssetBundles/AssetBundles");
        AssetBundleManifest minfest = minfestAB.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
        //foreach (var name in minfest.GetAllAssetBundles())
        //{
        //    print(name);
        //}
        string[] strs = minfest.GetAllDependencies("CubeWall.unity3d");
        foreach (var item in strs)
        {
            print(item);
            AssetBundle.LoadFromFile("AssetBundles/" + item);
        }
        // 卸载 
        ab.Unload(true);
    }
    // Update is called once per frame
    void Update () {
   
}
}