zoukankan      html  css  js  c++  java
  • AssetBoundle加载非预设资源

    1.定义一个协程LoadNonObjFromAB
    IEnumerator LoadNonObjFromAB(string ABURL, GameObject go, string assetName)

    参数含义:ABURL:要下载的AB包地址  go:用于测试,显示加载贴图  assetName:要加载的资源名称

    IEnumerator LoadNonObjFromAB(string ABURL, GameObject go, string assetName)
            {
                //参数检查
                if(string.IsNullOrEmpty(ABURL) || go == null)
                {
                    Debug.LogError("参数错误!");
                }
                using (WWW www = new WWW(ABURL))
                {
                    yield return www;
                    AssetBundle ab = www.assetBundle;    //获取AB包
                    if(ab != null)
                    {
                        if(assetName == "")
                        {
                            go.GetComponent<Renderer>().material.mainTexture = ab.mainAsset as Texture;
                        }
                        else
                        {
    
                            go.GetComponent<Renderer>().material.mainTexture = (Texture)ab.LoadAsset(assetName);  //替换贴图为下载的贴图
                            print(assetName);
    
                        }
                        //卸载AB包
                        ab.Unload(false);
                    }
                    else
                    {
                        Debug.LogError("下载错误:"+www.error);
                    }
                }
    }

    2.调用协程
     private void Start()
            {
                StartCoroutine(LoadNonObjFromAB(URL1, testGo, assetName1));
            }
    
    

    (在调用之前要对参数初始化)

     
  • 相关阅读:
    防止重复点击
    刷新当前页面的几种方法
    PHP删除数组中空值
    json转化数组
    两个不能同时共存的条件orWhere查询
    SQLSTATE[42000]
    laravel一个页面两个表格分页处理
    Hash::make与Hash::check
    unbind()清除指定元素绑定效果
    二级联动
  • 原文地址:https://www.cnblogs.com/blackteeth/p/10152121.html
Copyright © 2011-2022 走看看