Pascal Serrarens de12c36220 First commit
2022-01-11 16:51:37 +01:00

49 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace Passer {
public class CoreUpdater : MonoBehaviour {
private void Awake() {
#if UNITY_EDITOR
StartCoroutine(GetCore("http://passervr.com/testsites/PasserCore.dll"));
#endif
}
IEnumerator GetCore(string uri) {
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri)) {
// Request and wait for the desired page.
yield return webRequest.SendWebRequest();
string[] pages = uri.Split('/');
int page = pages.Length - 1;
#if UNITY_2021_2_OR_NEWER
if (webRequest.result == UnityWebRequest.Result.ConnectionError)
#else
if (webRequest.isNetworkError)
#endif
{
Debug.Log(pages[page] + ": Error: " + webRequest.error);
yield return null;
}
if (webRequest.downloadHandler.isDone == false) {
Debug.Log("partial download");
yield return null;
}
DownloadHandler x = webRequest.downloadHandler;
string savePath = string.Format("{0}/Passer/Plugins/PasserCore.dll", Application.dataPath);
Debug.Log(savePath);
System.IO.File.WriteAllBytes(savePath, webRequest.downloadHandler.data);
Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text);
}
}
}
}