using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; public class LoadAssetBundle : MonoSingleton { private AssetBundleCreateRequest acr; // Start is called before the first frame update void Start() { StartCoroutine(DownLoadAssetBundle()); } // Update is called once per frame void Update() { } IEnumerator DownLoadAssetBundle() { string artUrl = "https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/HotUpdateLangChao/langchaostart"; yield return DownLoadAssets(artUrl, "HotUpdateAssets", false); } public IEnumerator DownLoadAssets(string dllPath, string name, bool isRemote = true) { //if (!isRemote) //{ // dllPath = GetWebRequestPath(name); //} UnityWebRequest www = UnityWebRequest.Get(dllPath); www.SendWebRequest(); while (!www.isDone) { yield return null; } #if UNITY_2020_1_OR_NEWER if (www.result != UnityWebRequest.Result.Success) { Debug.Log(www.error); } #else if (www.isHttpError || www.isNetworkError) { Debug.Log(www.error); } #endif else { { acr = AssetBundle.LoadFromMemoryAsync(www.downloadHandler.data); while (!acr.isDone) { yield return null; } //AssetBundleRequest abr = acr.assetBundle.LoadAssetAsync("LangChaoStart"); //while (!abr.isDone) //{ // yield return null; //} //Debug.Log(LoadByte("emqxsl-ca").Length); //this.gameObject.SetActive(false); } } } private string GetWebRequestPath(string asset) { var path = $"{Application.streamingAssetsPath}/{asset}"; if (!path.Contains("://")) { path = "file://" + path; } return path; } public byte[] LoadByte( string path) { acr.assetBundle.LoadAsset(path); return (acr.assetBundle.LoadAsset(path)as TextAsset).bytes; } }