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));
            }
    
    

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

     
  • 相关阅读:
    oracle用户和权限
    oracle中的索引
    oracle中的序列
    oracle中的视图
    oracle PL/SQL块
    oracle创建表案列
    半导体随机存储器
    IEEE754标准
    定点数的移位操作
    真值,原码,反码以及补码和移码总结
  • 原文地址:https://www.cnblogs.com/blackteeth/p/10152121.html
Copyright © 2011-2022 走看看