1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class LoadModelAB : MonoBehaviour
- {
- public GameObject loadtext;
- public GameObject Model;
- // Start is called before the first frame update
- void Start()
- {
- StartCoroutine(LoadAB());
- }
- IEnumerator LoadAB()
- {
- string filePath = System.IO.Path.Combine(Application.streamingAssetsPath + "/bd", "1");
- using (UnityWebRequest req = UnityWebRequestAssetBundle.GetAssetBundle(filePath))
- {
- yield return req.SendWebRequest();
- if (req.error == null)
- {
- AssetBundle ab = (req.downloadHandler as DownloadHandlerAssetBundle).assetBundle;
- AssetBundleRequest abr =ab.LoadAssetAsync<GameObject>("1");
- yield return abr;
- Model = GameObject.Instantiate((GameObject)abr.asset);
- Model.transform.SetParent(this.transform);
- Model.transform.localEulerAngles = Vector3.zero;
- Model.transform.localPosition = Vector3.zero;
- // webglfont = ab.LoadAsset<Font>("simkai");
- loadtext.SetActive(false);
- }
- else
- {
- Debug.Log("���س���" + req.responseCode + "," + req.error);
- loadtext.GetComponent<Text>().text=req.error;
- }
- }
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- }
|