loadmp4.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using TriLibCore;
  4. using UnityEngine;
  5. using UnityEngine.Networking;
  6. public class Loadmp4 : MonoBehaviour
  7. {
  8. public string strs;
  9. // Start is called before the first frame update
  10. void Awake()
  11. {
  12. StartCoroutine(LoadAB());
  13. }
  14. IEnumerator LoadAB()
  15. {
  16. string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "ui/"+strs);
  17. //UnityWebRequest request = UnityWebRequest.Get(filePath);
  18. Debug.Log("LoadAB====>"+ filePath);
  19. using (UnityWebRequest req = UnityWebRequestAssetBundle.GetAssetBundle(filePath))
  20. {
  21. yield return req.SendWebRequest();
  22. if (req.error == null)
  23. {
  24. Debug.Log("LoadAB====>start");
  25. AssetBundle ab = (req.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
  26. GameObject go = GameObject.Instantiate( ab.LoadAsset<GameObject>(strs),this.transform);
  27. go.SetActive(true);
  28. Debug.Log("LoadAB====>end");
  29. // UI.SetActive(true);
  30. }
  31. else
  32. {
  33. Debug.Log(filePath);
  34. }
  35. }
  36. }
  37. // Update is called once per frame
  38. void Update()
  39. {
  40. }
  41. }