using UnityEngine; using UnityEngine.Networking; using System.Text; using System.Threading.Tasks; namespace DDD { public static class GoogleSheetWebClient { public static async Task Get(string url) { var req = UnityWebRequest.Get(url); var op = req.SendWebRequest(); while (!op.isDone) await Task.Yield(); if (req.result != UnityWebRequest.Result.Success) { Debug.LogError("GET Failed: " + req.error); return null; } return req.downloadHandler.text; } public static async Task Post(string url, string json) { var req = new UnityWebRequest(url, "POST"); byte[] bodyRaw = Encoding.UTF8.GetBytes(json); req.uploadHandler = new UploadHandlerRaw(bodyRaw); req.downloadHandler = new DownloadHandlerBuffer(); req.SetRequestHeader("Content-Type", "application/json"); var op = req.SendWebRequest(); while (!op.isDone) await Task.Yield(); if (req.result != UnityWebRequest.Result.Success) { Debug.LogError("POST Failed: " + req.error); return null; } return req.downloadHandler.text; } } }