AssetBundle加载的四种方式(补充 三,四)

  #region 第三种类型 
    /// <summary>
    /// 路径有本地和远程,本地可以加file:// 或者file:/// 路径要完整的本地路径,这个位置卡了很久,经过多次尝试得到最终正确的路径
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    /// 
    //在Start方法中调用 参数为自己本地最终正确路径  
    //StartCoroutine(LoadFromCacheOrDownload(@"file://F:\PrivateForWCW\Unity\UGUI\AssetBudleProject\AssetBundle\scene\cubewall.unity3d"));

   /// 服务器上  StartCoroutine(LoadFromCacheOrDownload(@"http://localhost//AssetBundless/scene/cubewall.unity3d"));
    IEnumerator LoadFromCacheOrDownload(string path)
    {
        while (!Caching.ready)
            yield return null;
        WWW www = WWW.LoadFromCacheOrDownload(path, 1);
        yield return www;
        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.Log(www.error);
            yield break;
        }
        AssetBundle AB = www.assetBundle;
        GameObject obj=AB.LoadAsset<GameObject>("cube");
        Instantiate(obj);
    }
    #endregion

    #region 第四种 UnityWebRequst  //这个UnityWebRequst相当与取代了WWW这个类,还进一步优化了
    //使用  UnityWebRequest 需要引入UnityEngine.Networking;
    IEnumerator LoadFormWebRequst()
    {
        string uri = @"http://localhost//AssetBundless/scene/cubewall.unity3d";
        UnityWebRequest request = UnityWebRequest.GetAssetBundle(uri);
        yield return request.Send();
        //   AssetBundle AB = DownloadHandlerAssetBundle.GetContent(request); 第一种方式获取AssetBundle
        AssetBundle AB = (request.downloadHandler as DownloadHandlerAssetBundle).assetBundle;// 第二种方式获取AssetBundle
        GameObject obj = AB.LoadAsset<GameObject>("cube");
        Instantiate(obj);
    }


    #endregion

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值