Created
October 8, 2019 10:49
-
-
Save overing/4822d456404c5138b2a8f81a63f01364 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 UnityEngine; | |
using UnityGoogleDrive; // https://github.com/Elringus/UnityGoogleDrive | |
public class GoogleDriveTest : MonoBehaviour | |
{ | |
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] | |
static void AfterSceneLoad() | |
{ | |
var camera = FindObjectOfType<Camera>(); | |
if (camera != null) | |
camera.clearFlags = CameraClearFlags.SolidColor; | |
var type = typeof(GoogleDriveTest); | |
var obj = new GameObject(type.Name, type); | |
DontDestroyOnLoad(obj); | |
} | |
Coroutine Coroutine; | |
string Error = string.Empty; | |
readonly List<string> FileList = new List<string>(10); | |
GUIContext m_GUIContext; | |
void OnGUI() | |
{ | |
var cs = m_GUIContext ?? (m_GUIContext = new GUIContext()); | |
GUILayout.BeginHorizontal(); | |
bool original = GUI.enabled; | |
GUI.enabled = Coroutine == null; | |
if (GUILayout.Button("List", cs.Button)) | |
Coroutine = StartCoroutine(List()); | |
GUI.enabled = original; | |
GUILayout.EndHorizontal(); | |
if (string.IsNullOrEmpty(Error)) | |
FileList.ForEach(f => GUILayout.Label(f, cs.Label)); | |
else | |
GUILayout.Label("Error: " + Error, cs.Error); | |
} | |
IEnumerator List() | |
{ | |
var op = GoogleDriveFiles.List(); | |
yield return op.Send(); | |
if (op.IsError) | |
Error = op.Error; | |
else | |
{ | |
Error = string.Empty; | |
var list = op.ResponseData; | |
FileList.Clear(); | |
FileList.AddRange(list.Files.ConvertAll(f => f.Name)); | |
} | |
Coroutine = null; | |
} | |
sealed class GUIContext | |
{ | |
public GUIStyle Button; | |
public GUIStyle Label; | |
public GUIStyle Error; | |
public GUIContext() | |
{ | |
Button = new GUIStyle(GUI.skin.button) { fontSize = Screen.height / 18 }; | |
Label = new GUIStyle(GUI.skin.label) { fontSize = Screen.height / 16 }; | |
Error = new GUIStyle(GUI.skin.label) { fontSize = Screen.height / 16 }; | |
Error.normal.textColor = Color.red; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment