LoadModelAB.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. public class LoadModelAB : MonoBehaviour
  6. {
  7. public GameObject Model;
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11. StartCoroutine(LoadAB());
  12. }
  13. IEnumerator LoadAB()
  14. {
  15. using (UnityWebRequest req = UnityWebRequestAssetBundle.GetAssetBundle("https://filebrowser.ghz-tech.com:8843/api/public/dl/1WZasi8T/unity/daping/main_1"))
  16. {
  17. yield return req.SendWebRequest();
  18. if (req.error == null)
  19. {
  20. AssetBundle ab = (req.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
  21. Model = GameObject.Instantiate(ab.LoadAsset<GameObject>("main_1"));
  22. Model.transform.SetParent(this.transform);
  23. Model.transform.localEulerAngles = Vector3.zero;
  24. Model.transform.localPosition = Vector3.zero;
  25. // webglfont = ab.LoadAsset<Font>("simkai");
  26. }
  27. else
  28. {
  29. Debug.Log("ÏÂÔسö´í" + req.responseCode + "," + req.error);
  30. }
  31. }
  32. }
  33. // Update is called once per frame
  34. void Update()
  35. {
  36. }
  37. }