123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- public class LoadAssetBundle : MonoSingleton<LoadAssetBundle>
- {
- 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<GameObject>("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<TextAsset>(path);
- return (acr.assetBundle.LoadAsset<TextAsset>(path)as TextAsset).bytes;
- }
-
- }
|