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(bundle.GetAllAssetNames()[0]); List listObjs = new List(); listObjs.Add(obj); object value = listObjs; GameObject model = GameObject.Instantiate(obj); model.transform.position = Vector3.zero; } } } }