using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; public class LoadDll2 { private static string GetWebRequestPath(string asset) { var path = $"{Application.streamingAssetsPath}/{asset}"; if (!path.Contains("://")) { path = "file://" + path; } return path; } static Dictionary ablist = new Dictionary(); public static IEnumerator DownLoadAssets(Action callback) { if (ablist.ContainsKey("obe")) { callback.Invoke(ablist["obe"]); yield return null; } else { string dllPath = GetWebRequestPath("obe"); Debug.Log($"start download asset:{dllPath}"); UnityWebRequest www = UnityWebRequest.Get(dllPath); yield return www.SendWebRequest(); #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 { if (ablist.ContainsKey("obe")) { callback.Invoke(ablist["obe"]); } else { Debug.Log("assets===>" + "obe"); // Or retrieve results as binary data byte[] assetData = www.downloadHandler.data; AssetBundle ab = AssetBundle.LoadFromMemory(assetData); ablist.Add("obe", ab); callback.Invoke(ab); UnityEngine.Object[] assets = ab.LoadAllAssets(); for (int i = 0; i < assets.Length; i++) { Debug.Log("assets===>" + assets[i].name); yield return null; } } } } } }