| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 | using System.Collections;using System.Collections.Generic;using UnityEngine;public class AssetLoadHelper_AB : MonoBehaviour{    public string ab_name = "";    //public string[] assestName;    public Transform insRoot;    public bool addMat = false;    public Material defulMat;    public List<string> ignoreObjs = new List<string>();    void Start()    {        if (insRoot == null)        {            insRoot = this.transform;        }        TextureLoadHelp._Instance.StartCoroutine(Load());    }    IEnumerator Load()    {        WaitForEndOfFrame wait = new WaitForEndOfFrame();        WWW www = WWW.LoadFromCacheOrDownload($"{Application.streamingAssetsPath}/{ab_name}", 0);        yield return www;        if (www.isDone)        {            var tempAb = www.assetBundle;            GameObject[] objs = tempAb.LoadAllAssets<GameObject>();            for (int i = 0; i < objs.Length; i++)            {                if (ignoreObjs.Contains(objs[i].name)) {                    continue;                }                GameObject insObj=Instantiate(objs[i], insRoot);                if (addMat)                {                    insObj.GetComponent<MeshRenderer>().material = defulMat;                }                yield return wait;            }        }        else        {            Debug.LogError($"{ab_name}下载失败:{www.error}");        }        www.Dispose();    }}
 |