//  Spreadsheet callback
    private void VersionCheckCallback(GoogleSheetsToUnity.GstuSpreadSheet ss)
    {
        string newestVersion = ss["A1"].value;

        //  Compare current version user is running to newest version from spreadsheet
        if (Application.version.CompareTo(newestVersion) != 0)
        {
            ConfirmWindow.Instance.NewConfirmWindow($"Version {ss["A1"].value} is now available!  Would you like to be taken to the download link?", OpenDownloadOnConfirm, ss["B1"].value);
        }
    }
示例#2
0
        public static void Read(string rawText, GSTU_Search search, UnityAction <GstuSpreadSheet> callback)
        {
            ValueRange rawData = LitJson.JsonMapper.ToObject <ValueRange>(rawText);
            // JSON.Load(request.downloadHandler.text).Make<ValueRange>();
            var response = new GSTU_SpreadsheetResponse(rawData);

            if (callback != null)
            {
                var sheet = new GstuSpreadSheet(response, search.titleColumn, search.titleRow);
                sheet.rawText = rawText;
                callback(sheet);
            }
        }
示例#3
0
        /// <summary>
        /// Wait for the Web request to complete and then process the results
        /// </summary>
        /// <param name="www"></param>
        /// <param name="titleColumn"></param>
        /// <param name="titleRow"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        static IEnumerator Read(WWW www, string titleColumn, int titleRow, OnSpreedSheetLoaded callback)
        {
            yield return(www);

            ValueRange rawData = JSON.Load(www.text).Make <ValueRange>();
            GSTU_SpreadsheetResponce responce = new GSTU_SpreadsheetResponce(rawData);

            GstuSpreadSheet spreadSheet = new GstuSpreadSheet(responce, titleColumn, titleRow);

            if (callback != null)
            {
                callback(spreadSheet);
            }
        }
示例#4
0
        /// <summary>
        /// Reads the spread sheet and callback with the results
        /// </summary>
        /// <param name="request"></param>
        /// <param name="search"></param>
        /// <param name="containsMergedCells"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        static IEnumerator Read(UnityWebRequest request, GSTU_Search search, bool containsMergedCells, UnityAction <GstuSpreadSheet> callback)
        {
            var apiKey = Config.gdr.access_token;

            if (Application.isPlaying)
            {
                // yield return new Task(CheckForRefreshToken());
                yield return(CheckForRefreshToken());
            }
#if UNITY_EDITOR
            else
            {
                yield return(EditorCoroutineRunner.StartCoroutine(CheckForRefreshToken()));
            }
#endif

            var newApiKey = Config.gdr.access_token;

            if (!apiKey.Equals(newApiKey))
            {
                request = UnityWebRequest.Get(CreateReadRequestURI(search));
            }

            using (request)
            {
                yield return(request.SendWebRequest());

                if (string.IsNullOrEmpty(request.downloadHandler.text) || request.downloadHandler.text == "{}")
                {
                    Debug.LogWarning("Unable to Retreive data from google sheets");
                    yield break;
                }

                if (request.downloadHandler.text.Contains("UNAUTHENTICATED"))
                {
                    Debug.LogWarning("Unable to Retreive data from google sheets:UNAUTHENTICATED");
                    yield break;
                }

                ValueRange rawData = LitJson.JsonMapper.ToObject <ValueRange>(request.downloadHandler.text);
                // JSON.Load(request.downloadHandler.text).Make<ValueRange>();
                var response = new GSTU_SpreadsheetResponse(rawData);

                //if it contains merged cells then process a second set of json data to know what these cells are
                if (containsMergedCells)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("https://sheets.googleapis.com/v4/spreadsheets");
                    sb.Append("/" + search.sheetId);
                    sb.Append("?access_token=" + Config.gdr.access_token);

                    UnityWebRequest request2 = UnityWebRequest.Get(sb.ToString());

                    yield return(request2.SendWebRequest());

                    SheetsRootObject root = LitJson.JsonMapper.ToObject <SheetsRootObject>(request2.downloadHandler.text);
                    //JSON.Load(request2.downloadHandler.text).Make<SheetsRootObject>();
                    response.sheetInfo = root.sheets.FirstOrDefault(x => x.properties.title == search.worksheetName);
                }

                if (callback != null)
                {
                    var sheet = new GstuSpreadSheet(response, search.titleColumn, search.titleRow);
                    sheet.rawText = request.downloadHandler.text;
                    callback(sheet);
                }
            }
        }