12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using UnityEngine.Networking;
- public class TestLoadVuforia : MonoBehaviour
- {
- public GameObject VuforiaManager;
- // Start is called before the first frame update
- void Start()
- {
- //StartCoroutine(GetRequest("YCYL3_3Test.dat"));
- //StartCoroutine(GetRequest("YCYL3_3Test.xml"));
- StartCoroutine(GetRequestBundle("spacestation", 111));
- }
-
- private IEnumerator GetRequest(string methodName)
- {
- string url = Application.streamingAssetsPath + "/Vuforia/" + methodName;
- using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
- {
-
- yield return webRequest.SendWebRequest();
- if (webRequest.isHttpError || webRequest.isNetworkError)
- {
- Debug.LogError(webRequest.error + "\n" + webRequest.downloadHandler.text);
-
- }
- else
- {
- string path = Application.persistentDataPath + "/StreamingAssets/Vuforia";
- if (!Directory.Exists(path))
- {
- Directory.CreateDirectory(path);
- }
- File.WriteAllBytes(Application.persistentDataPath + "/StreamingAssets/Vuforia/" + methodName, webRequest.downloadHandler.data);
-
- if(methodName == "YCYL3_3Test.dat")
- {
- StartCoroutine(OpenVuforia(5));
- }
- }
- }
- }
- private IEnumerator OpenVuforia(float timer)
- {
- yield return new WaitForSeconds(timer);
- VuforiaManager.SetActive(true);
- }
- private IEnumerator GetRequestBundle(string methodName ,int time)
- {
- string url = Application.streamingAssetsPath + "/Model/" + methodName;
- Debug.Log(url);
- using (UnityWebRequest webRequestAB = UnityWebRequestAssetBundle.GetAssetBundle(url))
- {
-
-
- yield return webRequestAB.SendWebRequest();
- if (webRequestAB.isHttpError || webRequestAB.isNetworkError)
- {
- Debug.LogError(webRequestAB.error + "\n" + webRequestAB.downloadHandler.text);
- }
- else
- {
- AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(webRequestAB);
- // Debug.Log(bundle.GetAllAssetNames()[0]);
- GameObject obj = bundle.LoadAsset<GameObject>(bundle.GetAllAssetNames()[0]);
- List<GameObject> listObjs = new List<GameObject>();
- listObjs.Add(obj);
- object value = listObjs;
- GameObject model = GameObject.Instantiate(obj);
- model.transform.position = Vector3.zero;
- }
- }
- }
- }
|