Last active
May 5, 2021 08:57
-
-
Save GieziJo/2173ebbc6dab31a6b7bc9987045c678f to your computer and use it in GitHub Desktop.
Download google docs sheet as string using unity editor coroutines and networking
This file contains hidden or 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 Unity.EditorCoroutines.Editor; | |
| using UnityEditor; | |
| using UnityEngine; | |
| using UnityEngine.Networking; | |
| public static class ImportGoogleSheet | |
| { | |
| const string SHEET_ID = ""; | |
| const string SHEET_NAME = ""; | |
| const string owner = ""; | |
| [MenuItem("Utility/Download Sheet")] | |
| public static void LoadSheet() => EditorCoroutineUtility.StartCoroutine(Method(), owner); | |
| static IEnumerator Method() | |
| { | |
| UnityWebRequest request = UnityWebRequest.Get("https://docs.google.com/spreadsheets/d/" + SHEET_ID + | |
| "/gviz/tq?tqx=out:csv&sheet=" + SHEET_NAME); | |
| yield return request.SendWebRequest(); | |
| if (request.result == UnityWebRequest.Result.ProtocolError || request.result == UnityWebRequest.Result.ConnectionError) | |
| Debug.Log(request.error); | |
| else | |
| Debug.Log(request.downloadHandler.text); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment