Created
April 3, 2019 15:46
-
-
Save sokuhatiku/a171130098784d596d0ee333bd19e37d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Threading; | |
using UnityEditor; | |
using UnityEngine; | |
using UnityEngine.Networking; | |
public class PackageDownloadTest : EditorWindow | |
{ | |
[MenuItem("Window/PackageDownloadTest")] | |
static void Open() | |
{ | |
GetWindow<PackageDownloadTest>(); | |
} | |
string downloadURL; | |
private void OnGUI() | |
{ | |
downloadURL = EditorGUILayout.TextField(downloadURL); | |
if (GUILayout.Button("Download")) | |
{ | |
var request = UnityWebRequest.Get(downloadURL); | |
request.SendWebRequest(); | |
while (!request.isDone && !request.isNetworkError && !request.isHttpError) | |
{ | |
if (EditorUtility.DisplayCancelableProgressBar("downloading", "downloading package...", request.downloadProgress)) | |
{ | |
request.Abort(); | |
break; | |
} | |
Thread.Sleep(1); | |
} | |
if (!string.IsNullOrEmpty(request.error)) | |
{ | |
throw new System.Exception(request.error); | |
} | |
var tempFilePath = Path.GetTempFileName(); | |
File.WriteAllBytes(tempFilePath, request.downloadHandler.data); | |
AssetDatabase.ImportPackage(tempFilePath, false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment