LoadDll.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Threading.Tasks;
  8. using UnityEngine;
  9. using UnityEngine.Networking;
  10. public class LoadDll : MonoBehaviour
  11. {
  12. void Start()
  13. {
  14. StartCoroutine(SendHttp("https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/HotUpdate.dll.bytes"));
  15. }
  16. public IEnumerator SendHttp(string url)
  17. {
  18. Debug.Log("HybridCLRStart1");
  19. UnityWebRequest webRequest = UnityWebRequest.Get(url);
  20. webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
  21. yield return webRequest.SendWebRequest();
  22. if (webRequest.isDone)
  23. {
  24. Assembly hotUpdateAss = Assembly.Load(webRequest.downloadHandler.data);
  25. Debug.Log("HybridCLRStart2");
  26. Type type = hotUpdateAss.GetType("Hello");
  27. Debug.Log("HybridCLRStart3");
  28. type.GetMethod("Run").Invoke(null, null);
  29. Debug.Log("HybridCLRStart4");
  30. StartCoroutine(LoadAB("https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/canvas"));
  31. StartCoroutine(LoadAB("https://wx-model-1317557471.cos.ap-shanghai.myqcloud.com/cube"));
  32. }
  33. }
  34. // Start is called before the first frame update
  35. IEnumerator LoadAB(string url)
  36. {
  37. Debug.Log("LoadAB");
  38. UnityWebRequest webRequest = UnityWebRequest.Get(url);
  39. webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
  40. yield return webRequest.SendWebRequest();
  41. if (webRequest.isDone)
  42. {
  43. AssetBundleCreateRequest request = AssetBundle.LoadFromMemoryAsync(webRequest.downloadHandler.data);
  44. yield return request;//µÈ´ýÏìÓ¦
  45. AssetBundle ab = request.assetBundle;
  46. GameObject[] objs = ab.LoadAllAssets<GameObject>();
  47. Debug.Log("HybridCLRStart5");
  48. foreach (var item in objs)
  49. {
  50. Instantiate(item);
  51. }
  52. }
  53. }
  54. }