1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 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"));
- }
-
- 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);
- }
- }
|