1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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;
-
- 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++)
- {
- 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();
- }
- }
|