TestLoadVuforia.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. using UnityEngine.Networking;
  6. public class TestLoadVuforia : MonoBehaviour
  7. {
  8. public GameObject VuforiaManager;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. StartCoroutine(GetRequest("YCYL3_3Test.dat"));
  13. StartCoroutine(GetRequest("YCYL3_3Test.xml"));
  14. }
  15. private IEnumerator GetRequest(string methodName)
  16. {
  17. string url = Application.streamingAssetsPath + "/Vuforia/" + methodName;
  18. using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
  19. {
  20. yield return webRequest.SendWebRequest();
  21. if (webRequest.isHttpError || webRequest.isNetworkError)
  22. {
  23. Debug.LogError(webRequest.error + "\n" + webRequest.downloadHandler.text);
  24. }
  25. else
  26. {
  27. string path = Application.persistentDataPath + "/StreamingAssets/Vuforia";
  28. if (!Directory.Exists(path))
  29. {
  30. Directory.CreateDirectory(path);
  31. }
  32. File.WriteAllBytes(Application.persistentDataPath + "/StreamingAssets/Vuforia/" + methodName, webRequest.downloadHandler.data);
  33. if(methodName == "YCYL3_3Test.dat")
  34. {
  35. StartCoroutine(OpenVuforia(5));
  36. }
  37. }
  38. }
  39. }
  40. private IEnumerator OpenVuforia(float timer)
  41. {
  42. yield return new WaitForSeconds(timer);
  43. VuforiaManager.SetActive(true);
  44. }
  45. }