public static IEnumerator UploadScreenShot(UploadData data, Action onSuccess = null, Action <string> onError = null) { yield return(new WaitForSeconds(0.1f)); List <IMultipartFormSection> formData = new List <IMultipartFormSection>(); byte[] contents = data.ScreenShot.EncodeToPNG(); formData.Add(new MultipartFormFileSection("file", contents, data.FileName + ".png", "image/png")); UnityWebRequest www = UnityWebRequest.Post($"{apiUrl}/{data.webHookId}/{data.Token}", formData); yield return(www.SendWebRequest()); string error = www.error; if (!string.IsNullOrEmpty(error)) { if (onError != null) { onError(error); } yield break; } if (onSuccess != null) { onSuccess(); } }
private IEnumerator CaptureToDiscord() { if (!SettingData.IsCompletedDiscordData()) { yield break; } _fileName = DateTime.Now.ToString("yyyyMMddHHmmss"); filePath = $"{SettingData.BackupPath}/{_fileName}.png"; yield return(EditorCoroutines.EditorCoroutines.StartCoroutine(CaptureGameView(filePath), this)); var uploadData = new DiscordHelper.UploadData { webHookId = SettingData.DiscordWebhookId, Token = SettingData.DiscordToken, FileName = _fileName }; _screenshot = new Texture2D(1, 1); byte[] bytes = System.IO.File.ReadAllBytes(filePath); _screenshot.LoadImage(bytes); uploadData.ScreenShot = _screenshot; yield return(EditorCoroutines.EditorCoroutines.StartCoroutine(DiscordHelper.DiscordHelper.UploadScreenShot(uploadData, OnSuccess, OnError), this)); }