using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; public class LoadModelAB : MonoBehaviour { public Text t; public GameObject Model; // Start is called before the first frame update void Start() { StartCoroutine(LoadAB()); } IEnumerator LoadAB() { Debug.Log(Application.streamingAssetsPath + "/main_1"); string url = Application.streamingAssetsPath + "/main_1"; #if UNITY_EDITOR url = "https://filebrowser.ghz-tech.com:8843/api/public/dl/1WZasi8T/unity/daping/main_1"; #endif using (UnityWebRequest req = UnityWebRequestAssetBundle.GetAssetBundle(url)) { req.SendWebRequest(); while (!req.isDone) { t.text = "模型加载中 " + (req.downloadProgress/2f * 100).ToString("F2") + "%"; yield return null; } if (req.error == null) { AssetBundle ab = (req.downloadHandler as DownloadHandlerAssetBundle).assetBundle; AssetBundleRequest abr = ab.LoadAssetAsync("main_1"); while(!abr.isDone) { t.text = "模型加载中 "+ (50+ abr.progress / 2f*100).ToString("F2") + "%"; yield return null; } Model = GameObject.Instantiate((GameObject)abr.asset); Model.transform.SetParent(this.transform); Model.transform.localEulerAngles = Vector3.zero; Model.transform.localPosition = Vector3.zero; t.gameObject.SetActive(false); ModelDataManager.Instance.isLoadModel = true; } else { t.text = "模型加载失败"; Debug.Log("���س���" + req.responseCode + "," + req.error); } } } // Update is called once per frame void Update() { } }