public IEnumerator <float> DownloadFileCorroutine() { UnityWebRequest request = new UnityWebRequest(url); request.method = UnityWebRequest.kHttpVerbGET; DownloadHandlerBuffer response = new DownloadHandlerBuffer(); request.downloadHandler = response; request.SendWebRequest(); bool fetching = true; while (fetching) { yield return(0.3f); if (request.isHttpError || request.isNetworkError) { fetching = false; Debug.Log(request.error); } if (request.isDone) { fetching = false; FileHelper.writeBytesToFile(response.data, path); if (callback != null) { callback(null); } } } }
public static void DownloadFileASync(string url, string path, Action <string> callback) { DownloadAsBytesASync(url, delegate(object o, DownloadDataCompletedEventArgs a) { if (a.Cancelled || a.Error != null) { MainThreader.Call(callback, null); } else { FileHelper.writeBytesToFile(a.Result, path); MainThreader.Call(callback, path); } }); }
public static Texture SaveTextureAsPNG(Texture2D texture, string path, TextureData settings) { if (!path.EndsWith(".png")) { path += ".png"; } byte[] encoding = texture.EncodeToPNG(); Debug.Log("Texture saved at \"" + path + "\"."); FileHelper.writeBytesToFile(encoding, path); AssetDatabase.ImportAsset(path); if (settings != null) { settings.ApplyModes(path); } Texture saved = AssetDatabase.LoadAssetAtPath <Texture>(path); return(saved); }