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 ignoreObjs = new List(); 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(); 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().material = defulMat; } yield return wait; } } else { Debug.LogError($"{ab_name}下载失败:{www.error}"); } www.Dispose(); } }