private void DrawSperadsheetList() { EditorElements.HorizontalLine(Style); if (GUILayout.Button("Add spreadsheet")) { Data.FilesToDownload.Add(new LocalizationFile()); } for (int i = 0; i < Data.FilesToDownload.Count; ++i) { EditorGUILayout.Separator(); LocalizationFile curr_file = Data.FilesToDownload[i]; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("File " + (i + 1) + ": " + curr_file.NameToSaveAs, Style.BoldTextStyle); if (GUILayout.Button("X", GUILayout.MaxWidth(50))) { Data.FilesToDownload.RemoveAt(i); --i; } } EditorGUILayout.EndHorizontal(); DrawFileToDownload(curr_file); } }
private void DrawFileToDownload(LocalizationFile file) { EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Name to save as", GUILayout.MaxWidth(190)); file.NameToSaveAs = EditorGUILayout.TextField(file.NameToSaveAs); } EditorGUILayout.EndHorizontal(); string final_path = $"Assets/Resources/{Data.PathToSave}/{file.NameToSaveAs}.txt"; EditorGUILayout.LabelField($"Final path: {final_path}"); EditorGUILayout.Separator(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Google Drive document id", GUILayout.MaxWidth(190)); file.DocumentId = EditorGUILayout.TextField(file.DocumentId); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Google Drive document range", GUILayout.MaxWidth(190)); file.DocumentRange = EditorGUILayout.TextField(file.DocumentRange); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; }
private async Task DownloadLocalizationDataAsync() { progress = ""; for (int i = 0; i < Data.FilesToDownload.Count; ++i) { LocalizationFile curr_file = Data.FilesToDownload[i]; GoogleDrive.DownloadSpreadsheetRequest request = new GoogleDrive.DownloadSpreadsheetRequest(Data.ClientId, Data.ClientSecret, curr_file.DocumentId, curr_file.DocumentRange); request.OnProgressUpdate.Subscribe(delegate(RequestProgress prog) { UpdateProgress(prog.ProgressDescription); }); await request.RunRequest(); if (request.HasErrors) { string error = $"Error downloading file {i + 1} ({curr_file.NameToSaveAs}):\n\n{request.ErrorResult.MessageError})"; UpdateProgress(error); return; } GoogleDrive.DownloadSpreadsheetSuccessObject result = request.SuccessResult; string tsv_data = Fast.Parsers.TSVParser.Compose(result.Data); string final_path = $"Resources/{Data.PathToSave}/{curr_file.NameToSaveAs}.txt"; bool update_assets = Data.FilesToDownload.Count == i + 1; bool serialized = Fast.Serializers.TextAssetSerializer.SerializeToAssetsPath(final_path, tsv_data, update_assets); if (!serialized) { string error = $"Error saving file {i + 1} ({curr_file.NameToSaveAs}):\n\nWrong path?"; UpdateProgress(error); return; } } UpdateProgress("Download success"); }