public static void ExportXML(Google2uWorksheet in_sheet, string in_path, Google2uExportOptions in_options) { if (!Directory.Exists(in_path)) Directory.CreateDirectory(in_path); in_path = Path.Combine(in_path, in_sheet.WorksheetName); if (!Directory.Exists(in_path)) Directory.CreateDirectory(in_path); in_path = Path.Combine(in_path, in_sheet.WorksheetName + ".xml").Replace('\\', '/'); using ( var fs = File.Open(in_path, File.Exists(in_path) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var fileString = ExportXMLString(in_sheet, in_options); sw.Write(fileString); sw.Flush(); } } PushNotification("Saving to: " + in_path); }
public static string ExportCsvString(Google2uWorksheet in_sheet, Google2uExportOptions in_options) { // for each page var ret = string.Empty; var rowCt = in_sheet.Rows.Count; if (rowCt <= 0) { return(ret); } // Iterate through each row, printing its cell values. foreach (var row in in_sheet.Rows) { var rowType = row[0].GetTypeFromValue(); var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.CSVCullRows) { break; } continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { continue; } // Iterate over the remaining columns, and print each cell value for (var i = 0; i < in_sheet.Rows[0].Count; i++) { if ((row[i].MyType == SupportedType.Void || string.IsNullOrEmpty(rowHeader) || (in_options.CSVCullColumns && i > in_sheet.FirstBlankCol))) { continue; } var tmpRet = in_options.EscapeCSVStrings ? SanitizeDf(row[i].CellValueString) : AutoQuote(row[i].CellValueString); if (in_options.CSVConvertLineBreaks) { tmpRet = ConvertLineBreaks(tmpRet); } ret += tmpRet; ret += ","; } ret = ret.Remove(ret.Length - 1); // remove the last comma ret += Environment.NewLine; } return(ret); }
public static string ExportNGUILegacyString(Google2uWorksheet in_sheet, Google2uExportOptions in_options, int in_langIndex) { var ret = FormatLine("Flag = Flag-" + in_sheet.Rows[0][in_langIndex].CellValueString); for (var i = 1; i < in_sheet.Rows.Count - 1; ++i) { var row = in_sheet.Rows[i]; if (string.IsNullOrEmpty(row.Cells[0].CellValueString) && in_options.NGUICullRows) { break; } var tmpRet = in_options.EscapeNGUIStrings ? SanitizeDf(row.Cells[in_langIndex].CellValueString) : row.Cells[in_langIndex].CellValueString; if (in_options.NGUIConvertLineBreaks) { tmpRet = ConvertLineBreaks(tmpRet); } ret += FormatLine(row.Cells[0].CellValueString + " = " + tmpRet); } return(ret); }
public static void ExportCsv(Google2uWorksheet in_sheet, string in_path, Google2uExportOptions in_options) { if (!Directory.Exists(in_path)) { Directory.CreateDirectory(in_path); } in_path = Path.Combine(in_path, in_sheet.WorksheetName); if (!Directory.Exists(in_path)) { Directory.CreateDirectory(in_path); } in_path = Path.Combine(in_path, in_sheet.WorksheetName + ".csv").Replace('\\', '/'); using ( var fs = File.Open(in_path, File.Exists(in_path) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var fileString = ExportCsvString(in_sheet, in_options); sw.Write(fileString); sw.Flush(); } } PushNotification("Saving to: " + in_path); }
public void Update(bool in_isActive, Google2uExportOptions in_options) { if (!_Initialized) { return; } if ((DateTime.Now - LastUpdateTime).TotalSeconds > 15) { LastUpdateTime = DateTime.Now; _QueryThread = null; if (WorksheetQueryStatus == QueryStatus.Uninitialized) { if (_NewQueryThread == null || _NewQueryThread.IsAlive == false) { _NewQueryThread = new Thread(QueryCells); _QueryThread = _NewQueryThread; } } else if (IsDataValid && in_isActive && DoUpdateQuery && WorksheetQueryStatus == QueryStatus.Idle) { if (_UpdateQueryThread == null || _UpdateQueryThread.IsAlive == false) { DoUpdateQuery = false; _UpdateQueryThread = new Thread(UpdateQuery); _QueryThread = _UpdateQueryThread; } } if (_QueryThread == null) { return; } WorksheetQueryStatus = QueryStatus.Querying; _QueryThread.Start(this); } else if (Rows != null && WorksheetQueryStatus == QueryStatus.Idle && UpdateCellTypes) { if (_UpdateCellTypesThread == null || _UpdateCellTypesThread.IsAlive == false) { UpdateCellTypes = false; _UpdateCellTypesThread = new Thread(DoUpdateCellTypes); _UpdateCellTypesThread.Start(this); } } if (Rows != null && UpdateValidation) { if (_ValidationThread == null || _ValidationThread.IsAlive == false) { UpdateValidation = false; _ValidationThread = new Thread(DoDataValidation); _ValidationThread.Start(new DataValidationParams(this, in_options)); } } }
public static void ExportJson(Google2uWorksheet in_sheet, string in_path, Google2uExportOptions in_options) { if (!Directory.Exists(in_path)) { Directory.CreateDirectory(in_path); } if (!in_options.JSONExportSingleSubfolder) { in_path = Path.Combine(in_path, in_sheet.WorksheetName); if (!Directory.Exists(in_path)) { Directory.CreateDirectory(in_path); } } var jsonPath = Path.Combine(in_path, in_sheet.WorksheetName + ".json").Replace('\\', '/'); using ( var fs = File.Open(jsonPath, File.Exists(jsonPath) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var fileString = ExportJsonObjectString(in_sheet, in_options, false); sw.Write(fileString); sw.Flush(); } } if (in_options.JSONExportClass) { var jsonClassDir = in_path + "\\Resources"; if (!Directory.Exists(jsonClassDir)) { Directory.CreateDirectory(jsonClassDir); } var jsonClassPath = Path.Combine(jsonClassDir, in_sheet.WorksheetName + ".cs").Replace('\\', '/'); using ( var fs = File.Open(jsonClassPath, File.Exists(jsonClassPath) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var fileString = ExportJsonObjectClassString(in_sheet, in_options); sw.Write(fileString); sw.Flush(); } } } PushNotification("Saving to: " + in_path); }
public static string ExportNGUIString(Google2uWorksheet in_sheet, Google2uExportOptions in_options) { // for each page var ret = string.Empty; var rowCt = in_sheet.Rows.Count; if (rowCt <= 0) return ret; // Iterate through each row, printing its cell values. foreach (var row in in_sheet.Rows) { var rowType = row[0].GetTypeFromValue(); var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.NGUICullRows) break; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { continue; } // Iterate over the remaining columns, and print each cell value for (var i = 0; i < in_sheet.Rows[0].Count; i++) { if ((row[i].MyType == SupportedType.Void || string.IsNullOrEmpty(row[0].CellValueString) || in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(in_sheet.Rows[0][i].CellValueString) || in_sheet.Rows[0][i].CellValueString.Equals("void", StringComparison.InvariantCultureIgnoreCase) || in_sheet.Rows[0][i].CellValueString.Equals("ignore", StringComparison.InvariantCultureIgnoreCase) || (in_options.NGUICullColumns && i >= in_sheet.FirstBlankCol))) { continue; } var tmpRet = in_options.EscapeNGUIStrings ? SanitizeDf(row[i].CellValueString) : AutoQuote(row[i].CellValueString); if (in_options.NGUIConvertLineBreaks) tmpRet = ConvertLineBreaks(tmpRet); ret += tmpRet; ret += ","; } ret = ret.Remove(ret.Length - 1); // remove the last comma ret += Environment.NewLine; } return ret; }
public static void ExportNGUILegacy(Google2uWorksheet in_sheet, string in_path, Google2uExportOptions in_options) { if (!Directory.Exists(in_path)) Directory.CreateDirectory(in_path); var finalCol = in_sheet.Rows[0].Count; if (in_options.NGUICullColumns) finalCol = in_sheet.FirstBlankCol; var languages = new List<string>(); for (var j = 1; j < in_sheet.Rows[0].Count - 1; ++j) { if (j == finalCol) break; languages.Add(in_sheet.Rows[0][j].CellValueString); } foreach (var lang in languages) { var filepath = in_path + "/" + lang + ".txt"; using ( var fs = File.Open(filepath, File.Exists(filepath) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var langIndex = 0; for (var index = 0; index < in_sheet.Rows[0].Cells.Count; index++) { var cell = in_sheet.Rows[0].Cells[index]; if (cell.CellValueString.Equals(lang)) { langIndex = index; break; } } sw.Write(ExportNGUILegacyString(in_sheet, in_options, langIndex)); sw.Flush(); } } } }
public static string ExportNGUILegacyString(Google2uWorksheet in_sheet, Google2uExportOptions in_options, int in_langIndex) { var ret = FormatLine("Flag = Flag-" + in_sheet.Rows[0][in_langIndex].CellValueString); for (var i = 1; i < in_sheet.Rows.Count - 1; ++i) { var row = in_sheet.Rows[i]; if (string.IsNullOrEmpty(row.Cells[0].CellValueString) && in_options.NGUICullRows) break; var tmpRet = in_options.EscapeNGUIStrings ? SanitizeDf(row.Cells[in_langIndex].CellValueString) : row.Cells[in_langIndex].CellValueString; if (in_options.NGUIConvertLineBreaks) tmpRet = ConvertLineBreaks(tmpRet); ret += FormatLine(row.Cells[0].CellValueString + " = " + tmpRet); } return ret; }
public DataValidationParams(Google2uWorksheet in_worksheet, Google2uExportOptions in_options) { Worksheet = in_worksheet; Options = in_options; }
public override bool DrawGUIList(EditorGUILayoutEx in_layout, bool in_showAll) { var ret = true; var SpreadsheetVisibleString = "workbook" + WorkbookName.Replace(' ', '_') + "_Visible"; SpreadsheetVisible = Google2uGUIUtil.GetBool(SpreadsheetVisibleString, SpreadsheetVisible); if ((SpreadsheetVisible == false) && !in_showAll) return true; ShowSpreadsheet = Google2uGUIUtil.GetBool("workbook" + WorkbookName.Replace(' ', '_') + "_Open", ShowSpreadsheet); var mainFadeArea = in_layout.BeginFadeArea(ShowSpreadsheet, WorkbookName, "workbook" + WorkbookName.Replace(' ', '_'), in_layout.OuterBox, in_layout.OuterBoxHeader, SpreadsheetVisibleString); ShowSpreadsheet = mainFadeArea.Open; Google2uGUIUtil.SetBool("workbook" + WorkbookName.Replace(' ', '_') + "_Open", ShowSpreadsheet); // We have to do this here. Otherwise there is a threading issue (Can't initialize from EditorPreferences outside the main thread) if (ExportOptions == null) { ExportOptions = new Google2uExportOptions("workbook" + WorkbookName.Replace(' ', '_') + "_Option_"); } if (mainFadeArea.Show()) { var showExport = false; var exportsheets = new List<Google2uWorksheet>(); switch (WorksheetQueryStatus) { case QueryStatus.Idle: { WorksheetQueryStatus = QueryStatus.Uninitialized; } break; case QueryStatus.Querying: EditorGUILayout.LabelField(Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_WORKSHEETS) + Google2u.Ellipses); break; case QueryStatus.QueryComplete: if (WorksheetsDisplay.Length > 0) { foreach (var Google2uWorksheet in WorksheetsDisplay) { if (Google2uWorksheet.DrawGUIList(in_layout)) { exportsheets.Add(Google2uWorksheet); showExport = true; } } if (_OpenInvalidSheet) { var stillQuerying = false; for (var i = 0; i < Worksheets.Count; ++i) { if (!exportsheets.Contains(Worksheets[i])) continue; if (Worksheets[i].UpdateValidation || Worksheets[i].Validating) stillQuerying = true; if (Worksheets[i].IsDataValid == false) { var ed = EditorWindow.GetWindow<Google2uEditor>(); Google2u.ActiveWorkbookWindow = ed; ed.Workbook = this; ed.Layout = in_layout; ed.title = WorkbookName; ed.wantsMouseMove = true; ActiveWorksheetIndex = i; Worksheets[i].HighlightFirstInvalidCell(); _OpenInvalidSheet = false; break; } } if(!stillQuerying) _OpenInvalidSheet = false; } EditorGUILayout.BeginHorizontal(); var content = new GUIContent(in_layout.RefreshButton, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_REFRESH_WORKBOOK)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { Worksheets.Clear(); WorksheetQueryStatus = QueryStatus.Uninitialized; } var querying = false; var bAllWorksheetsValid = true; foreach (var Google2uWorksheet in exportsheets) { if (Google2uWorksheet.IsDataValid == false) bAllWorksheetsValid = false; if (Google2uWorksheet.WorksheetQueryStatus != QueryStatus.Idle) querying = true; } { var guiEnabled = GUI.enabled; if (querying) GUI.enabled = false; content = bAllWorksheetsValid ? new GUIContent(in_layout.ValidateButtonGreen, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_VALIDATE_WORKBOOK)) : new GUIContent(in_layout.ValidateButtonRed, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_VALIDATE_WORKBOOK)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { // Do Validation for the worksheets we will be exporting foreach (var Google2uWorksheet in exportsheets) { Google2uWorksheet.UpdateValidation = true; Google2uWorksheet.Validating = true; } _OpenInvalidSheet = true; } GUI.enabled = guiEnabled; } content = new GUIContent(in_layout.EditButton, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EDIT_WORKBOOK)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { var ed = EditorWindow.GetWindow<Google2uEditor>(); Google2u.ActiveWorkbookWindow = ed; ed.Workbook = this; ed.Layout = in_layout; ed.title = WorkbookName; ed.wantsMouseMove = true; } GUILayout.FlexibleSpace(); if (showExport) { var oldEnabled = GUI.enabled; if (bAllWorksheetsValid == false) GUI.enabled = false; content = new GUIContent(in_layout.SaveButton, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EXPORT)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { DoExport(exportsheets); } GUI.enabled = oldEnabled; } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.LabelField(Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_NO_WORKSHEETS)); } break; } } in_layout.EndFadeArea(); return ret; }
public static void ExportObjectDb(Google2uWorksheet in_sheet, string in_resourcesPath, string in_editorPath, string in_playmakerPath, Google2uExportOptions in_options) { if (!Directory.Exists(in_resourcesPath)) Directory.CreateDirectory(in_resourcesPath); if (!Directory.Exists(in_editorPath)) Directory.CreateDirectory(in_editorPath); var arrayDelimiter = in_options.DelimiterOptions[in_options.ArrayDelimiters]; var stringArrayDelimiter = in_options.DelimiterOptions[in_options.StringArrayDelimiters]; var complexTypeDelimiter = in_options.DelimiterOptions[in_options.ComplexTypeDelimiters]; var complexTypeArrayDelimiters = in_options.DelimiterOptions[in_options.ComplexArrayDelimiters]; var typesInFirstRow = in_sheet.UseTypeRow; /////////////////////////////////////////////// // open the file var className = Path.GetInvalidFileNameChars() .Aggregate(in_sheet.WorksheetName, (in_current, in_c) => in_current.Replace(in_c, '_')); var exportInfo = new Google2uObjDbExport {Data = in_sheet, CullEmptyRows = in_options.ObjectDBCullRows, CullEmptyCols = in_options.ObjectDBCullColumns}; var overrideName = in_options.GetOverrideObjectDatabaseGameObjectName(in_sheet.WorksheetName); exportInfo.ObjectName = string.IsNullOrEmpty(overrideName) ? (string.IsNullOrEmpty(in_options.ExportDatabaseGameObjectName) ? "Google2uDatabase" : in_options.ExportDatabaseGameObjectName) : overrideName; exportInfo.ScriptName = className; using (var fs = File.Open(Path.Combine(in_resourcesPath, className + ".cs"), File.Exists(Path.Combine(in_resourcesPath, className + ".cs")) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var fileString = string.Empty; fileString += FormatLine("//----------------------------------------------"); fileString += FormatLine("// Google2u: Google Doc Unity integration"); fileString += FormatLine("// Copyright © 2015 Litteratus"); fileString += FormatLine("//"); fileString += FormatLine("// This file has been auto-generated"); fileString += FormatLine("// Do not manually edit"); fileString += FormatLine("//----------------------------------------------"); fileString += FormatLine(string.Empty); fileString += FormatLine("using UnityEngine;"); fileString += FormatLine("using System.Globalization;"); fileString += FormatLine(string.Empty); fileString += FormatLine("namespace Google2u"); fileString += FormatLine("{"); fileString += FormatLine(" [System.Serializable]"); fileString += FormatLine(" public class " + className + "Row : IGoogle2uRow"); fileString += FormatLine(" {"); // variable declarations for (var i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) { } else if (IsSupportedArrayType(in_sheet.Rows[0][i].MyType)) { fileString += FormatLine(" public System.Collections.Generic.List<" + StringSupportedType(in_sheet.Rows[0][i].MyType) + "> " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = new System.Collections.Generic.List<" + StringSupportedType(in_sheet.Rows[0][i].MyType) + ">();"); } else fileString += FormatLine(" public " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ";"); } // constructor parameter list fileString += (" public " + className + "Row("); { var firstItem = true; for (var i = 0; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) continue; if (!firstItem) fileString += (", "); firstItem = false; fileString += ("string _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)); } } fileString += FormatLine(") " + Environment.NewLine + " {"); // processing each of the input parameters and copying it into the members for (var i = 1; i < in_sheet.Rows[0].Count; i++) { //nightmare time if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) { } else if (in_sheet.Rows[0][i].MyType == SupportedType.GameObject) { fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = GameObject.Find(\"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Bool) { fileString += FormatLine(" {"); fileString += FormatLine(" " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " res;"); fileString += FormatLine(" if(" + StringSupportedType(in_sheet.Rows[0][i].MyType) + ".TryParse(_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ", out res))"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = res;"); fileString += FormatLine(" else"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " string: \"+ _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " +\" to bool\");"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Byte) { fileString += FormatLine(" {"); fileString += FormatLine(" " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " res;"); fileString += FormatLine(" if(" + StringSupportedType(in_sheet.Rows[0][i].MyType) + ".TryParse(_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ", NumberStyles.Any, CultureInfo.InvariantCulture, out res))"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = res;"); fileString += FormatLine(" else"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " string: \"+ _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " +\" to byte\");"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Float) { fileString += FormatLine(" {"); fileString += FormatLine(" " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " res;"); fileString += FormatLine(" if(" + StringSupportedType(in_sheet.Rows[0][i].MyType) + ".TryParse(_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ", NumberStyles.Any, CultureInfo.InvariantCulture, out res))"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = res;"); fileString += FormatLine(" else"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " string: \"+ _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " +\" to " + StringSupportedType(in_sheet.Rows[0][i].MyType) + "\");"); fileString += FormatLine(" }"); } else if ((in_sheet.Rows[0][i].MyType == SupportedType.ByteArray) || (in_sheet.Rows[0][i].MyType == SupportedType.BoolArray) || (in_sheet.Rows[0][i].MyType == SupportedType.FloatArray)) { fileString += FormatLine(" {"); fileString += FormatLine(" " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " res;"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + arrayDelimiter + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); if (in_sheet.Rows[0][i].MyType == SupportedType.BoolArray) fileString += FormatLine(" if(" + StringSupportedType(in_sheet.Rows[0][i].MyType) + ".TryParse(result[i], out res))"); else fileString += FormatLine(" if(" + StringSupportedType(in_sheet.Rows[0][i].MyType) + ".TryParse(result[i], NumberStyles.Any, CultureInfo.InvariantCulture, out res))"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add(res);"); fileString += FormatLine(" else"); fileString += FormatLine(" {"); if (in_sheet.Rows[0][i].MyType == SupportedType.ByteArray) fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( 0 );"); else if (in_sheet.Rows[0][i].MyType == SupportedType.BoolArray) fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( false );"); else if (in_sheet.Rows[0][i].MyType == SupportedType.FloatArray) fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( float.NaN );"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " string: \"+ result[i] +\" to " + (StringSupportedType(in_sheet.Rows[0][i].MyType)) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Int) { fileString += FormatLine(" {"); fileString += FormatLine(" " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " res;"); fileString += FormatLine(" if(int.TryParse(_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ", NumberStyles.Any, CultureInfo.InvariantCulture, out res))"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = res;"); fileString += FormatLine(" else"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " string: \"+ _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " +\" to int\");"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.IntArray) { fileString += FormatLine(" {"); fileString += FormatLine(" " + (StringSupportedType(in_sheet.Rows[0][i].MyType)) + " res;"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + arrayDelimiter + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine( " if(int.TryParse(result[i], NumberStyles.Any, CultureInfo.InvariantCulture, out res))"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( res );"); fileString += FormatLine(" else"); fileString += FormatLine(" {"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( 0 );"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " string: \"+ result[i] +\" to " + (StringSupportedType(in_sheet.Rows[0][i].MyType)) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.String) { if (in_options.TrimStrings) fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Trim();"); else fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ";"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.StringArray) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + stringArrayDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); if (in_options.TrimStringArrays) fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( result[i].Trim() );"); else fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( result[i] );"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector2) { fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 2)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " in \" + _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int i = 0; i < 2; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float res;"); fileString += FormatLine( " if(float.TryParse(splitpath[i], NumberStyles.Any, CultureInfo.InvariantCulture, out res))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[i] = res;"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".x = results[0];"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".y = results[1];"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector2Array) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + complexTypeArrayDelimiters + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = result[i].Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 2)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " in \" + _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int j = 0; j < splitpath.Length; j++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float [] temp = new float[splitpath.Length];"); fileString += FormatLine( " if(float.TryParse(splitpath[j], NumberStyles.Any, CultureInfo.InvariantCulture, out temp[j]))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[j] = temp[j];"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" continue;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(in_sheet.Rows[0][i].MyType)) + "(results[0], results[1] ));"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector3) { fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " in \" + _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int i = 0; i < 3; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float res;"); fileString += FormatLine( " if(float.TryParse(splitpath[i], NumberStyles.Any, CultureInfo.InvariantCulture, out res))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[i] = res;"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".x = results[0];"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".y = results[1];"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".z = results[2];"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector3Array) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + complexTypeArrayDelimiters + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = result[i].Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " in \" + _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int j = 0; j < splitpath.Length; j++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float [] temp = new float[splitpath.Length];"); fileString += FormatLine( " if(float.TryParse(splitpath[j], NumberStyles.Any, CultureInfo.InvariantCulture, out temp[j]))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[j] = temp[j];"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" continue;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(in_sheet.Rows[0][i].MyType)) + "(results[0], results[1], results[2] ));"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Color) { fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3 && splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " in \" + _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int i = 0; i < splitpath.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float res;"); fileString += FormatLine( " if(float.TryParse(splitpath[i], NumberStyles.Any, CultureInfo.InvariantCulture, out res))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[i] = res;"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".r = results[0];"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".g = results[1];"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".b = results[2];"); fileString += FormatLine(" if(splitpath.Length == 4)"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".a = results[3];"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.ColorArray) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + complexTypeArrayDelimiters + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = result[i].Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3 && splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " in \" + _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int j = 0; j < splitpath.Length; j++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float [] temp = new float[splitpath.Length];"); fileString += FormatLine( " if(float.TryParse(splitpath[j], NumberStyles.Any, CultureInfo.InvariantCulture, out temp[j]))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[j] = temp[j];"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" continue;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" if(splitpath.Length == 3)"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(in_sheet.Rows[0][i].MyType)) + "(results[0], results[1], results[2] ));"); fileString += FormatLine(" else"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(in_sheet.Rows[0][i].MyType)) + "(results[0], results[1], results[2], results[3] ));"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Color32) { fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3 && splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " in \" + _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" byte []results = new byte[splitpath.Length];"); fileString += FormatLine(" for(int i = 0; i < splitpath.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" byte res;"); fileString += FormatLine( " if(byte.TryParse(splitpath[i], NumberStyles.Any, CultureInfo.InvariantCulture, out res))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[i] = res;"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".r = results[0];"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".g = results[1];"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".b = results[2];"); fileString += FormatLine(" if(splitpath.Length == 4)"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".a = results[3];"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Color32Array) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + complexTypeArrayDelimiters + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = result[i].Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3 && splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " in \" + _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" byte []results = new byte[splitpath.Length];"); fileString += FormatLine(" for(int j = 0; j < splitpath.Length; j++)"); fileString += FormatLine(" {"); fileString += FormatLine(" byte [] temp = new byte[splitpath.Length];"); fileString += FormatLine( " if(byte.TryParse(splitpath[j], NumberStyles.Any, CultureInfo.InvariantCulture, out temp[j]))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[j] = temp[j];"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" continue;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" if(splitpath.Length == 3)"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(in_sheet.Rows[0][i].MyType)) + "(results[0], results[1], results[2], System.Convert.ToByte(0) ));"); fileString += FormatLine(" else"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(in_sheet.Rows[0][i].MyType)) + "(results[0], results[1], results[2], results[3] ));"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Quaternion) { fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " in \" + _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int i = 0; i < 4; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float res;"); fileString += FormatLine( " if(float.TryParse(splitpath[i], NumberStyles.Any, CultureInfo.InvariantCulture, out res))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[i] = res;"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".x = results[0];"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".y = results[1];"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".z = results[2];"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".w = results[3];"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.QuaternionArray) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Split(\"" + complexTypeArrayDelimiters + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = result[i].Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3 && splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(in_sheet.Rows[0][i].MyType) + " in \" + _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int j = 0; j < splitpath.Length; j++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float [] temp = new float[splitpath.Length];"); fileString += FormatLine( " if(float.TryParse(splitpath[j], NumberStyles.Any, CultureInfo.InvariantCulture, out temp[j]))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[j] = temp[j];"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" continue;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(in_sheet.Rows[0][i].MyType)) + "(results[0], results[1], results[2], results[3] ));"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else { fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = _" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ";"); } } fileString += FormatLine(" }"); fileString += FormatLine(string.Empty); { var colCount = 0; for (var i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) continue; colCount++; } fileString += FormatLine(" public int Length { get { return " + colCount + "; } }"); } fileString += FormatLine(string.Empty); // allow indexing by [] fileString += FormatLine(" public string this[int i]"); fileString += FormatLine(" {"); fileString += FormatLine(" get"); fileString += FormatLine(" {"); fileString += FormatLine(" return GetStringDataByIndex(i);"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(string.Empty); // get string data by index lets the user use an int field rather than the name to retrieve the data fileString += FormatLine(" public string GetStringDataByIndex( int index )"); fileString += FormatLine(" {"); fileString += FormatLine(" string ret = System.String.Empty;"); fileString += FormatLine(" switch( index )"); fileString += FormatLine(" {"); { var colNum = 0; for (var i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) continue; fileString += FormatLine(" case " + colNum++ + ":"); fileString += FormatLine(" ret = " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".ToString();"); fileString += FormatLine(" break;"); } } fileString += FormatLine(" }"); fileString += FormatLine(string.Empty); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(string.Empty); // get the data by column name rather than index fileString += FormatLine(" public string GetStringData( string colID )"); fileString += FormatLine(" {"); fileString += FormatLine(" var ret = System.String.Empty;"); if (in_options.LowercaseHeader) fileString += FormatLine(" switch( colID.ToLower() )"); else fileString += FormatLine(" switch( colID )"); fileString += FormatLine(" {"); for (var i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) continue; fileString += FormatLine(" case \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\":"); fileString += FormatLine(" ret = " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".ToString();"); fileString += FormatLine(" break;"); } fileString += FormatLine(" }"); fileString += FormatLine(string.Empty); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(" public override string ToString()"); fileString += FormatLine(" {"); fileString += FormatLine(" string ret = System.String.Empty;"); for (var i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) continue; fileString += FormatLine(" ret += \"{\" + \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\" + \" : \" + " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".ToString() + \"} \";"); } fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" public class " + className + " : Google2uComponentBase, IGoogle2uDB"); fileString += FormatLine(" {"); // this is the enums, the enum matches the name of the row fileString += FormatLine(" public enum rowIds {"); fileString += (" "); { var curRow = 0; // Iterate through each row, printing its cell values to be the enum names. foreach (var row in in_sheet.Rows) { if (curRow == 0 || (typesInFirstRow && curRow == 1)) { curRow++; continue; } var rowType = row[0].MyType; var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.ObjectDBCullRows) break; curRow++; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { curRow++; continue; } fileString += row[0].CellValueString; if ((curRow + 1)%20 == 0) fileString += Environment.NewLine + " "; fileString += (", "); curRow++; } } fileString = fileString.Remove(fileString.Length - 2); // remove the last comma fileString += FormatLine(string.Empty); fileString += FormatLine(" };"); fileString += FormatLine(" public string [] rowNames = {"); fileString += " "; // Iterate through each row, printing its cell values for the row names strings. { var curRow = 0; foreach (var row in in_sheet.Rows) { if (curRow == 0 || (typesInFirstRow && curRow == 1)) { curRow++; continue; } var rowType = row[0].MyType; var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.ObjectDBCullRows) break; curRow++; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { curRow++; continue; } fileString += "\"" + row[0].CellValueString + "\""; if ((curRow + 1)%20 == 0) fileString += Environment.NewLine + " "; fileString += ", "; curRow++; } } fileString = fileString.Remove(fileString.Length - 2); // remove the last comma fileString += FormatLine(Environment.NewLine + " };"); // the declaration of the storage for the row data fileString += FormatLine(" public System.Collections.Generic.List<" + className + "Row> Rows = new System.Collections.Generic.List<" + className + "Row>();"); { // the dont destroy on awake flag if (in_options.UseDoNotDestroy) { fileString += FormatLine(string.Empty); fileString += FormatLine(" void Awake()"); fileString += FormatLine(" {"); fileString += FormatLine(" DontDestroyOnLoad(this);"); fileString += FormatLine(" }"); } // this is the processing that actually gets the data into the object itself later on, // this loops through the generic input and seperates it into strings for the above // row class to handle and parse into its members fileString += FormatLine( " public override void AddRowGeneric (System.Collections.Generic.List<string> input)"); fileString += FormatLine(" {"); fileString += (" Rows.Add(new " + className + "Row("); { var typeCount = 1; // variable declarations for (var i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) continue; typeCount++; } var firstItem = true; for (var i = 0; i < typeCount; i++) { if (!firstItem) fileString += (","); firstItem = false; fileString += ("input[" + i + "]"); } } fileString += FormatLine("));"); fileString += FormatLine(" }"); fileString += FormatLine(" public override void Clear ()"); fileString += FormatLine(" {"); fileString += FormatLine(" Rows.Clear();"); fileString += FormatLine(" }"); } fileString += FormatLine(" public IGoogle2uRow GetGenRow(string in_RowString)"); fileString += FormatLine(" {"); fileString += FormatLine(" IGoogle2uRow ret = null;"); fileString += FormatLine(" try"); fileString += FormatLine(" {"); fileString += FormatLine(" ret = Rows[(int)System.Enum.Parse(typeof(rowIds), in_RowString)];"); fileString += FormatLine(" }"); fileString += FormatLine(" catch(System.ArgumentException) {"); fileString += FormatLine( " Debug.LogError( in_RowString + \" is not a member of the rowIds enumeration.\");"); fileString += FormatLine(" }"); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(" public IGoogle2uRow GetGenRow(rowIds in_RowID)"); fileString += FormatLine(" {"); fileString += FormatLine(" IGoogle2uRow ret = null;"); fileString += FormatLine(" try"); fileString += FormatLine(" {"); fileString += FormatLine(" ret = Rows[(int)in_RowID];"); fileString += FormatLine(" }"); fileString += FormatLine(" catch( System.Collections.Generic.KeyNotFoundException ex )"); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError( in_RowID + \" not found: \" + ex.Message );"); fileString += FormatLine(" }"); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(" public " + className + "Row GetRow(rowIds in_RowID)"); fileString += FormatLine(" {"); fileString += FormatLine(" " + className + "Row ret = null;"); fileString += FormatLine(" try"); fileString += FormatLine(" {"); fileString += FormatLine(" ret = Rows[(int)in_RowID];"); fileString += FormatLine(" }"); fileString += FormatLine(" catch( System.Collections.Generic.KeyNotFoundException ex )"); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError( in_RowID + \" not found: \" + ex.Message );"); fileString += FormatLine(" }"); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(" public " + className + "Row GetRow(string in_RowString)"); fileString += FormatLine(" {"); fileString += FormatLine(" " + className + "Row ret = null;"); fileString += FormatLine(" try"); fileString += FormatLine(" {"); fileString += FormatLine(" ret = Rows[(int)System.Enum.Parse(typeof(rowIds), in_RowString)];"); fileString += FormatLine(" }"); fileString += FormatLine(" catch(System.ArgumentException) {"); fileString += FormatLine( " Debug.LogError( in_RowString + \" is not a member of the rowIds enumeration.\");"); fileString += FormatLine(" }"); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(string.Empty); fileString += FormatLine(" }"); fileString += FormatLine(string.Empty); fileString += FormatLine("}"); sw.Write(fileString); sw.Flush(); } // using StreamWriter } // Using Filestream exportInfo.LastAttempt = DateTime.Now; Instance.ObjDbExport.Add(exportInfo); using (var fs = File.Open(Path.Combine(in_editorPath, className + ".cs"), File.Exists(Path.Combine(in_editorPath, className + ".cs")) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var fileString = string.Empty; ////////////////////////////////////////////////////////////////////////////////////////////////////// // Writing out the custom inspector ////////////////////////////////////////////////////////////////////////////////////////////////////// fileString += FormatLine("using UnityEngine;"); fileString += FormatLine("using UnityEditor;"); fileString += FormatLine(string.Empty); fileString += FormatLine("namespace Google2u"); fileString += FormatLine("{"); fileString += FormatLine(" [CustomEditor(typeof(" + className + "))]"); fileString += FormatLine(" public class " + className + "Editor : Editor"); fileString += FormatLine(" {"); fileString += FormatLine(" public int Index = 0;"); // sneaky time, count all the arrays and make an index for each of them within the inspector for (var i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].IsArrayType) { fileString += FormatLine(" public int " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index = 0;"); } } fileString += FormatLine(" public override void OnInspectorGUI ()"); fileString += FormatLine(" {"); fileString += FormatLine(" " + className + " s = target as " + className + ";"); fileString += FormatLine(" " + className + "Row r = s.Rows[ Index ];"); fileString += FormatLine(string.Empty); fileString += FormatLine(" EditorGUILayout.BeginHorizontal();"); fileString += FormatLine(" if ( GUILayout.Button(\"<<\") )"); fileString += FormatLine(" {"); fileString += FormatLine(" Index = 0;"); fileString += FormatLine(" }"); fileString += FormatLine(" if ( GUILayout.Button(\"<\") )"); fileString += FormatLine(" {"); fileString += FormatLine(" Index -= 1;"); fileString += FormatLine(" if ( Index < 0 )"); fileString += FormatLine(" Index = s.Rows.Count - 1;"); fileString += FormatLine(" }"); fileString += FormatLine(" if ( GUILayout.Button(\">\") )"); fileString += FormatLine(" {"); fileString += FormatLine(" Index += 1;"); fileString += FormatLine(" if ( Index >= s.Rows.Count )"); fileString += FormatLine(" Index = 0;"); fileString += FormatLine(" }"); fileString += FormatLine(" if ( GUILayout.Button(\">>\") )"); fileString += FormatLine(" {"); fileString += FormatLine(" Index = s.Rows.Count - 1;"); fileString += FormatLine(" }"); fileString += FormatLine(string.Empty); fileString += FormatLine(" EditorGUILayout.EndHorizontal();"); fileString += FormatLine(string.Empty); fileString += FormatLine(" EditorGUILayout.BeginHorizontal();"); fileString += FormatLine(" GUILayout.Label( \"ID\", GUILayout.Width( 150.0f ) );"); fileString += FormatLine(" {"); fileString += FormatLine(" EditorGUILayout.LabelField( s.rowNames[ Index ] );"); fileString += FormatLine(" }"); fileString += FormatLine(" EditorGUILayout.EndHorizontal();"); fileString += FormatLine(string.Empty); for (var i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol) continue; fileString += FormatLine(" EditorGUILayout.BeginHorizontal();"); if (in_sheet.Rows[0][i].IsArrayType) { fileString += FormatLine(" if ( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Count == 0 )"); fileString += FormatLine(" {"); fileString += FormatLine(" GUILayout.Label( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", GUILayout.Width( 150.0f ) );"); fileString += FormatLine(" {"); fileString += FormatLine(" EditorGUILayout.LabelField( \"Empty Array\" );"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" else"); fileString += FormatLine(" {"); fileString += FormatLine(" GUILayout.Label( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", GUILayout.Width( 130.0f ) );"); // when you switch the row you are examining, they may have different array sizes... therefore, we may actually be past the end of the list fileString += FormatLine(" if ( " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index >= r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Count )"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index = 0;"); // back button fileString += FormatLine(" if ( GUILayout.Button(\"<\", GUILayout.Width( 18.0f )) )"); fileString += FormatLine(" {"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index -= 1;"); fileString += FormatLine(" if ( " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index < 0 )"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index = r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Count - 1;"); fileString += FormatLine(" }"); fileString += FormatLine(" EditorGUILayout.LabelField(" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index.ToString(), GUILayout.Width( 15.0f ));"); // fwd button fileString += FormatLine(" if ( GUILayout.Button(\">\", GUILayout.Width( 18.0f )) )"); fileString += FormatLine(" {"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index += 1;"); fileString += FormatLine(" if ( " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index >= r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".Count )"); fileString += FormatLine(" " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index = 0;"); fileString += FormatLine(" }"); } if (in_sheet.Rows[0][i].MyType != SupportedType.Void) { if (in_sheet.Rows[0][i].MyType == SupportedType.Float) { fileString += FormatLine(" GUILayout.Label( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", GUILayout.Width( 150.0f ) );"); fileString += FormatLine(" {"); fileString += FormatLine(" EditorGUILayout.FloatField( (float)r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" }"); } else if ((in_sheet.Rows[0][i].MyType == SupportedType.Byte) || (in_sheet.Rows[0][i].MyType == SupportedType.Int)) { fileString += FormatLine(" GUILayout.Label( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", GUILayout.Width( 150.0f ) );"); fileString += FormatLine(" {"); fileString += FormatLine(" EditorGUILayout.IntField( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.BoolArray) { fileString += FormatLine(" EditorGUILayout.Toggle( System.Convert.ToBoolean( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index] ) );"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.StringArray) { fileString += FormatLine(" EditorGUILayout.TextField( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index] );"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.FloatArray) { fileString += FormatLine(" EditorGUILayout.FloatField( (float)r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index] );"); fileString += FormatLine(" }"); } else if (IsSupportedArrayType(in_sheet.Rows[0][i].MyType) && (in_sheet.Rows[0][i].MyType == SupportedType.ByteArray) || (in_sheet.Rows[0][i].MyType == SupportedType.IntArray)) { fileString += FormatLine(" EditorGUILayout.IntField( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index] );"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Byte) { fileString += FormatLine(" GUILayout.Label( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", GUILayout.Width( 150.0f ) );"); fileString += FormatLine(" {"); fileString += FormatLine(" EditorGUILayout.TextField( System.Convert.ToString( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " ) );"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Bool) { fileString += FormatLine(" GUILayout.Label( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", GUILayout.Width( 150.0f ) );"); fileString += FormatLine(" {"); fileString += FormatLine(" EditorGUILayout.Toggle( System.Convert.ToBoolean( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " ) );"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.String) { fileString += FormatLine(" GUILayout.Label( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", GUILayout.Width( 150.0f ) );"); fileString += FormatLine(" {"); fileString += FormatLine(" EditorGUILayout.TextField( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.GameObject) { fileString += FormatLine(" GUILayout.Label( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", GUILayout.Width( 150.0f ) );"); fileString += FormatLine(" {"); fileString += FormatLine(" EditorGUILayout.ObjectField( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector2) { fileString += FormatLine(" EditorGUILayout.Vector2Field( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector2Array) { fileString += FormatLine(" EditorGUILayout.EndHorizontal();"); fileString += FormatLine(" EditorGUILayout.BeginHorizontal();"); fileString += FormatLine(" EditorGUILayout.Vector2Field( \"\", r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index] );"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector3) { fileString += FormatLine(" EditorGUILayout.Vector3Field( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector3Array) { fileString += FormatLine(" EditorGUILayout.EndHorizontal();"); fileString += FormatLine(" EditorGUILayout.BeginHorizontal();"); fileString += FormatLine(" EditorGUILayout.Vector3Field( \"\", r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index] );"); fileString += FormatLine(" }"); } else if ((in_sheet.Rows[0][i].MyType == SupportedType.Color) || (in_sheet.Rows[0][i].MyType == SupportedType.Color32)) { fileString += FormatLine(" GUILayout.Label( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", GUILayout.Width( 150.0f ) );"); fileString += FormatLine(" {"); fileString += FormatLine(" EditorGUILayout.ColorField( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" }"); } else if ((in_sheet.Rows[0][i].MyType == SupportedType.ColorArray) || (in_sheet.Rows[0][i].MyType == SupportedType.Color32Array)) { fileString += FormatLine(" EditorGUILayout.EndHorizontal();"); fileString += FormatLine(" EditorGUILayout.BeginHorizontal();"); fileString += FormatLine(" EditorGUILayout.ColorField( \"\", r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index] );"); fileString += FormatLine(" }"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.Quaternion) { fileString += FormatLine(" Vector4 converted" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = new Vector4( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".x, " + "r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".y, " + "r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".z, " + "r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".w ); "); fileString += FormatLine(" EditorGUILayout.Vector4Field( \"" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "\", converted" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); } else if (in_sheet.Rows[0][i].MyType == SupportedType.QuaternionArray) { fileString += FormatLine(" EditorGUILayout.EndHorizontal();"); fileString += FormatLine(" EditorGUILayout.BeginHorizontal();"); fileString += FormatLine(" Vector4 converted" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " = new Vector4( r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index].x, " + "r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index].y, " + "r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index].z, " + "r." + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "[" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + "_Index].w ); "); fileString += FormatLine(" EditorGUILayout.Vector4Field( \"\", converted" + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" }"); } } fileString += FormatLine(" EditorGUILayout.EndHorizontal();"); fileString += FormatLine(string.Empty); } fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine("}"); sw.Write(fileString); /////////////////////////////////// // done writing, clean up sw.Flush(); sw.Close(); fs.Close(); } } /////////////////////////////////// // export playmaker actions (check if playmaker is installed first) if (in_options.GeneratePlaymakerActions) { var playmakerPath = in_playmakerPath; using (var fs = File.Open(Path.Combine(playmakerPath, "Get" + className + "DataByID.cs"), File.Exists(Path.Combine(playmakerPath, "Get" + className + "DataByID.cs")) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { ///////////////////////////// // Generate the Action for Get*DataByID var fileString = string.Empty; fileString += FormatLine("using UnityEngine;"); fileString += FormatLine(string.Empty); fileString += FormatLine("namespace HutongGames.PlayMaker.Actions"); fileString += FormatLine("{"); fileString += FormatLine(" [ActionCategory(\"Google2u\")]"); fileString += FormatLine(" [Tooltip(\"Gets the specified entry in the " + className + " Database.\")]"); fileString += FormatLine(" public class Get" + className + "DataByID : FsmStateAction"); fileString += FormatLine(" {"); fileString += FormatLine(" [RequiredField]"); fileString += FormatLine(" [UIHint(UIHint.Variable)]"); fileString += FormatLine(" [Tooltip(\"The object that contains the " + className + " database.\")]"); fileString += FormatLine(" public FsmGameObject databaseObj;"); fileString += FormatLine(" [RequiredField]"); fileString += FormatLine(" [UIHint(UIHint.Variable)]"); fileString += FormatLine(" [Tooltip(\"Row name of the entry you wish to retrieve.\")]"); fileString += FormatLine(" public FsmString rowName;"); for (var i = 1; i < in_sheet.Rows[0].Count; i++) { var fsmvarType = string.Empty; var varType = StringSupportedType(in_sheet.Rows[0][i].MyType); var varName = MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader); if ((in_sheet.Rows[0][i].MyType == SupportedType.Void) || (IsSupportedArrayType(in_sheet.Rows[0][i].MyType)) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) { continue; } if (in_sheet.Rows[0][i].MyType == SupportedType.Float) { fsmvarType = "FsmFloat"; } else if ((in_sheet.Rows[0][i].MyType == SupportedType.Int) || (in_sheet.Rows[0][i].MyType == SupportedType.Byte)) { fsmvarType = "FsmInt"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.Bool) { fsmvarType = "FsmBool"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.String) { fsmvarType = "FsmString"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.GameObject) { fsmvarType = "FsmGameObject"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector2) { fsmvarType = "FsmVector2"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector3) { fsmvarType = "FsmVector3"; } else if ((in_sheet.Rows[0][i].MyType == SupportedType.Color) || (in_sheet.Rows[0][i].MyType == SupportedType.Color32)) { fsmvarType = "FsmColor"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.Quaternion) { fsmvarType = "FsmQuaternion"; } fileString += FormatLine(" [UIHint(UIHint.Variable)]"); fileString += FormatLine(" [Tooltip(\"Store the " + varName + " in a " + varType + " variable.\")]"); fileString += FormatLine(" public " + fsmvarType + " " + varName + ";"); } fileString += FormatLine(" public override void Reset()"); fileString += FormatLine(" {"); fileString += FormatLine(" databaseObj = null;"); fileString += FormatLine(" rowName = null;"); for (var i = 1; i < in_sheet.Rows[0].Count; i++) { var varName = MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader); if ((in_sheet.Rows[0][i].MyType == SupportedType.Void) || IsSupportedArrayType(in_sheet.Rows[0][i].MyType) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) continue; var tmpVarName = varName.Split(new[] {'_'}, StringSplitOptions.RemoveEmptyEntries)[0]; if (string.Compare(tmpVarName, "IGNORE", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(tmpVarName, "VOID", StringComparison.OrdinalIgnoreCase) == 0) continue; fileString += FormatLine(" " + varName + " = null;"); } fileString += FormatLine(" }"); fileString += FormatLine(" public override void OnEnter()"); fileString += FormatLine(" {"); fileString += FormatLine( " if ( databaseObj != null && rowName != null && rowName.Value != System.String.Empty )"); fileString += FormatLine(" {"); fileString += FormatLine(" Google2u." + className + " db = databaseObj.Value.GetComponent<Google2u." + className + ">();"); fileString += FormatLine(" Google2u." + className + "Row row = db.GetRow( rowName.Value );"); for (var i = 1; i < in_sheet.Rows[0].Count; i++) { var varName = MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader); if ((in_sheet.Rows[0][i].MyType == SupportedType.Void) || IsSupportedArrayType(in_sheet.Rows[0][i].MyType) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) continue; var tmpVarName = varName.Split(new[] {'_'}, StringSplitOptions.RemoveEmptyEntries)[0]; if (string.Compare(tmpVarName, "IGNORE", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(tmpVarName, "VOID", StringComparison.OrdinalIgnoreCase) == 0) continue; fileString += FormatLine(" if ( " + varName + " != null )"); fileString += FormatLine(" " + varName + ".Value = row." + varName + ";"); } fileString += FormatLine(" }"); fileString += FormatLine(" Finish();"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine("}"); sw.Write(fileString); /////////////////////////////////// // done writing, clean up sw.Flush(); sw.Close(); fs.Close(); } } using (var fs = File.Open(Path.Combine(playmakerPath, "Get" + className + "DataByIndex.cs"), File.Exists(Path.Combine(playmakerPath, "Get" + className + "DataByIndex.cs")) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var fileString = string.Empty; ///////////////////////////// // Generate the Action for Get*DataByIndex fileString += FormatLine("using UnityEngine;"); fileString += FormatLine(string.Empty); fileString += FormatLine("namespace HutongGames.PlayMaker.Actions"); fileString += FormatLine("{"); fileString += FormatLine(" [ActionCategory(\"Google2u\")]"); fileString += FormatLine(" [Tooltip(\"Gets the specified entry in the " + className + " Database By Index.\")]"); fileString += FormatLine(" public class Get" + className + "DataByIndex : FsmStateAction"); fileString += FormatLine(" {"); fileString += FormatLine(" [RequiredField]"); fileString += FormatLine(" [UIHint(UIHint.Variable)]"); fileString += FormatLine(" [Tooltip(\"The object that contains the " + className + " database.\")]"); fileString += FormatLine(" public FsmGameObject databaseObj;"); fileString += FormatLine(" [RequiredField]"); fileString += FormatLine(" [UIHint(UIHint.Variable)]"); fileString += FormatLine(" [Tooltip(\"Row index of the entry you wish to retrieve.\")]"); fileString += FormatLine(" public FsmInt rowIndex;"); fileString += FormatLine(" [UIHint(UIHint.Variable)]"); fileString += FormatLine(" [Tooltip(\"Row ID of the entry.\")]"); fileString += FormatLine(" public FsmString rowName;"); for (var i = 1; i < in_sheet.Rows[0].Count; i++) { var fsmvarType = string.Empty; var varType = StringSupportedType(in_sheet.Rows[0][i].MyType); var varName = MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader); if ((in_sheet.Rows[0][i].MyType == SupportedType.Void) || IsSupportedArrayType(in_sheet.Rows[0][i].MyType) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) { continue; } if (in_sheet.Rows[0][i].MyType == SupportedType.Float) { fsmvarType = "FsmFloat"; } else if ((in_sheet.Rows[0][i].MyType == SupportedType.Byte) || (in_sheet.Rows[0][i].MyType == SupportedType.Int)) { fsmvarType = "FsmInt"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.Bool) { fsmvarType = "FsmBool"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.String) { fsmvarType = "FsmString"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.GameObject) { fsmvarType = "FsmGameObject"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector2) { fsmvarType = "FsmVector2"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.Vector3) { fsmvarType = "FsmVector3"; } else if ((in_sheet.Rows[0][i].MyType == SupportedType.Color) || (in_sheet.Rows[0][i].MyType == SupportedType.Color32)) { fsmvarType = "FsmColor"; } else if (in_sheet.Rows[0][i].MyType == SupportedType.Quaternion) { fsmvarType = "FsmQuaternion"; } fileString += FormatLine(" [UIHint(UIHint.Variable)]"); fileString += FormatLine(" [Tooltip(\"Store the " + varName + " in a " + varType + " variable.\")]"); fileString += FormatLine(" public " + fsmvarType + " " + varName + ";"); } fileString += FormatLine(" public override void Reset()"); fileString += FormatLine(" {"); fileString += FormatLine(" databaseObj = null;"); fileString += FormatLine(" rowIndex = null;"); for (var i = 1; i < in_sheet.Rows[0].Count; i++) { var varName = MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader); if ((in_sheet.Rows[0][i].MyType == SupportedType.Void) || IsSupportedArrayType(in_sheet.Rows[0][i].MyType) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) continue; var tmpVarName = varName.Split(new[] {'_'}, StringSplitOptions.RemoveEmptyEntries)[0]; if (string.Compare(tmpVarName, "IGNORE", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(tmpVarName, "VOID", StringComparison.OrdinalIgnoreCase) == 0) continue; fileString += FormatLine(" " + varName + " = null;"); } fileString += FormatLine(" }"); fileString += FormatLine(" public override void OnEnter()"); fileString += FormatLine(" {"); fileString += FormatLine(" if ( databaseObj != null && rowIndex != null )"); fileString += FormatLine(" {"); fileString += FormatLine(" Google2u." + className + " db = databaseObj.Value.GetComponent<Google2u." + className + ">();"); fileString += FormatLine(" // For sanity sake, we are going to do an auto-wrap based on the input"); fileString += FormatLine(" // This should prevent accessing the array out of bounds"); fileString += FormatLine(" int i = rowIndex.Value;"); fileString += FormatLine(" int L = db.Rows.Count;"); fileString += FormatLine(" while ( i < 0 )"); fileString += FormatLine(" i += L;"); fileString += FormatLine(" while ( i > L-1 )"); fileString += FormatLine(" i -= L;"); fileString += FormatLine(" Google2u." + className + "Row row = db.Rows[i];"); fileString += FormatLine(" if ( rowName != null )"); fileString += FormatLine(" rowName.Value = db.rowNames[i];"); for (var i = 1; i < in_sheet.Rows[0].Count; i++) { var varName = MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader); if ((in_sheet.Rows[0][i].MyType == SupportedType.Void) || IsSupportedArrayType(in_sheet.Rows[0][i].MyType) || (in_options.ObjectDBCullColumns && i > in_sheet.FirstBlankCol)) continue; var tmpVarName = varName.Split(new[] {'_'}, StringSplitOptions.RemoveEmptyEntries)[0]; if (string.Compare(tmpVarName, "IGNORE", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(tmpVarName, "VOID", StringComparison.OrdinalIgnoreCase) == 0) continue; fileString += FormatLine(" if ( " + varName + " != null )"); fileString += FormatLine(" " + varName + ".Value = row." + varName + ";"); } fileString += FormatLine(" }"); fileString += FormatLine(" Finish();"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine("}"); sw.Write(fileString); /////////////////////////////////// // done writing, clean up sw.Flush(); sw.Close(); fs.Close(); } } using (var fs = File.Open(Path.Combine(playmakerPath, "Get" + className + "Count.cs"), File.Exists(Path.Combine(playmakerPath, "Get" + className + "Count.cs")) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { ///////////////////////////// // Generate the Action for Get*DataByIndex var fileString = string.Empty; fileString += FormatLine("using UnityEngine;"); fileString += FormatLine(string.Empty); fileString += FormatLine("namespace HutongGames.PlayMaker.Actions"); fileString += FormatLine("{"); fileString += FormatLine(" [ActionCategory(\"Google2u\")]"); fileString += FormatLine(" [Tooltip(\"Gets the specified entry in the " + className + " Database By Index.\")]"); fileString += FormatLine(" public class Get" + className + "Count : FsmStateAction"); fileString += FormatLine(" {"); fileString += FormatLine(" [RequiredField]"); fileString += FormatLine(" [UIHint(UIHint.Variable)]"); fileString += FormatLine(" [Tooltip(\"The object that contains the " + className + " database.\")]"); fileString += FormatLine(" public FsmGameObject databaseObj;"); fileString += FormatLine(" [UIHint(UIHint.Variable)]"); fileString += FormatLine(" [Tooltip(\"Row Count of the database.\")]"); fileString += FormatLine(" public FsmInt rowCount;"); fileString += FormatLine(" public override void Reset()"); fileString += FormatLine(" {"); fileString += FormatLine(" databaseObj = null;"); fileString += FormatLine(" rowCount = null;"); fileString += FormatLine(" }"); fileString += FormatLine(" public override void OnEnter()"); fileString += FormatLine(" {"); fileString += FormatLine(" if ( databaseObj != null && rowCount != null )"); fileString += FormatLine(" {"); fileString += FormatLine(" Google2u." + className + " db = databaseObj.Value.GetComponent<Google2u." + className + ">();"); fileString += FormatLine(" rowCount.Value = db.Rows.Count;"); fileString += FormatLine(" }"); fileString += FormatLine(" Finish();"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine("}"); sw.Write(fileString); /////////////////////////////////// // done writing, clean up sw.Flush(); sw.Close(); fs.Close(); } } } // /found playmaker PushNotification("Saving to: " + in_editorPath); } // ExportObjectDb
public static void ExportJson(Google2uWorksheet in_sheet, string in_path, Google2uExportOptions in_options) { if (!Directory.Exists(in_path)) Directory.CreateDirectory(in_path); in_path = Path.Combine(in_path, in_sheet.WorksheetName); if (!Directory.Exists(in_path)) Directory.CreateDirectory(in_path); var jsonPath = Path.Combine(in_path, in_sheet.WorksheetName + ".json").Replace('\\', '/'); ; using ( var fs = File.Open(jsonPath, File.Exists(in_path) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var fileString = ExportJsonObjectString(in_sheet, in_options, false); sw.Write(fileString); sw.Flush(); } } if (in_options.JSONExportClass) { var jsonClassDir = in_path + "\\Resources"; if (!Directory.Exists(jsonClassDir)) Directory.CreateDirectory(jsonClassDir); var jsonClassPath = Path.Combine(jsonClassDir, in_sheet.WorksheetName + ".cs").Replace('\\', '/'); ; using ( var fs = File.Open(jsonClassPath, File.Exists(in_path) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var fileString = ExportJsonObjectClassString(in_sheet, in_options); sw.Write(fileString); sw.Flush(); } } } PushNotification("Saving to: " + in_path); }
public static string ExportXMLString(Google2uWorksheet in_sheet, Google2uExportOptions in_options) { var bConvertArrays = !in_options.XMLCellArrayToString; // Create the System.Xml.XmlDocument. var xmlDoc = new XmlDocument(); var rootNode = xmlDoc.CreateElement("Sheets"); xmlDoc.AppendChild(rootNode); var sheetNode = xmlDoc.CreateElement("sheet"); var sheetName = xmlDoc.CreateAttribute("name"); sheetName.Value = in_sheet.WorksheetName; var curRow = 0; sheetNode.Attributes.Append(sheetName); rootNode.AppendChild(sheetNode); // Iterate through each row, printing its cell values. foreach (var row in in_sheet.Rows) { if (curRow < 1) { curRow++; continue; } if (in_sheet.UseTypeRow == true && curRow == 1) { curRow++; continue; } var rowType = row[0].GetTypeFromValue(); var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.XMLCullRows) { break; } curRow++; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { curRow++; continue; } if (in_options.XMLColsAsChildTags) { XmlNode rowNode = xmlDoc.CreateElement("row"); var rowName = xmlDoc.CreateAttribute("name"); rowName.Value = row[0].CellValueString; if (rowNode.Attributes == null) { continue; } rowNode.Attributes.Append(rowName); sheetNode.AppendChild(rowNode); // Iterate over the remaining columns, and print each cell value for (var i = 1; i < in_sheet.Rows[0].Count; i++) { // Don't process rows or columns marked for ignore if ((row[i].MyType == SupportedType.Void || string.IsNullOrEmpty(row[0].CellValueString) || in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(in_sheet.Rows[0][i].CellValueString) || in_sheet.Rows[0][i].CellValueString.Equals("void", StringComparison.InvariantCultureIgnoreCase) || in_sheet.Rows[0][i].CellValueString.Equals("ignore", StringComparison.InvariantCultureIgnoreCase) || (in_options.XMLCullColumns && i >= in_sheet.FirstBlankCol))) { continue; } XmlNode colNode = xmlDoc.CreateElement(in_sheet.Rows[0][i].CellValueString); var colType = xmlDoc.CreateAttribute("type"); colType.Value = row[i].CellTypeString; if (colNode.Attributes != null) { colNode.Attributes.Append(colType); } if (bConvertArrays && IsSupportedArrayType(row[i].MyType)) { var delim = in_options.DelimiterOptions[in_options.ArrayDelimiters].ToCharArray(); if (row[i].MyType == SupportedType.StringArray) { delim = in_options.DelimiterOptions[in_options.StringArrayDelimiters].ToCharArray(); } var value = row[i].CellValueString.Split(delim, StringSplitOptions.RemoveEmptyEntries); foreach (var s in value) { XmlNode arrNode = xmlDoc.CreateElement("entry"); if (row[i].MyType == SupportedType.BoolArray) { var val = s.ToLower(); if (val == "1") { val = "true"; } if (val == "0") { val = "false"; } arrNode.InnerText = val; } else { arrNode.InnerText = s; } colNode.AppendChild(arrNode); } } else { colNode.InnerText = row[i].CellValueString; } rowNode.AppendChild(colNode); } curRow++; } else { XmlNode rowNode = xmlDoc.CreateElement("row"); if (rowNode.Attributes == null) { continue; } var rowAttribute = xmlDoc.CreateAttribute("UID"); rowAttribute.Value = row[0].CellValueString; rowNode.Attributes.Append(rowAttribute); // Iterate over the remaining columns, and print each cell value for (var i = 1; i < in_sheet.Rows[0].Count; i++) { // Don't process rows or columns marked for ignore if ((row[i].MyType == SupportedType.Void || string.IsNullOrEmpty(row[0].CellValueString) || in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(in_sheet.Rows[0][i].CellValueString) || in_sheet.Rows[0][i].CellValueString.Equals("void", StringComparison.InvariantCultureIgnoreCase) || in_sheet.Rows[0][i].CellValueString.Equals("ignore", StringComparison.InvariantCultureIgnoreCase) || (in_options.XMLCullColumns && i >= in_sheet.FirstBlankCol))) { continue; } rowAttribute = xmlDoc.CreateAttribute(in_sheet.Rows[0][i].CellValueString); rowAttribute.Value = row[i].CellValueString; rowNode.Attributes.Append(rowAttribute); } sheetNode.AppendChild(rowNode); curRow++; } } string retstring; using (var stringWriter = new StringWriter()) { using (var xmlTextWriter = new XmlTextWriter(stringWriter)) { xmlTextWriter.Formatting = Formatting.Indented; xmlDoc.WriteTo(xmlTextWriter); retstring = stringWriter.ToString(); } } return(retstring); }
public override bool DrawGUIList(EditorGUILayoutEx in_layout, bool in_showAll) { var ret = true; var spreadsheetVisibleString = "workbook" + WorkbookName.Replace(' ', '_') + "_Visible"; SpreadsheetVisible = Google2uGUIUtil.GetBool(spreadsheetVisibleString, SpreadsheetVisible); if ((SpreadsheetVisible == false) && !in_showAll) { return(true); } ShowSpreadsheet = Google2uGUIUtil.GetBool("workbook" + WorkbookName.Replace(' ', '_') + "_Open", ShowSpreadsheet); var mainFadeArea = in_layout.BeginFadeArea(ShowSpreadsheet, WorkbookName, "workbook" + WorkbookName.Replace(' ', '_'), in_layout.OuterBox, in_layout.OuterBoxHeader, spreadsheetVisibleString); ShowSpreadsheet = mainFadeArea.Open; Google2uGUIUtil.SetBool("workbook" + WorkbookName.Replace(' ', '_') + "_Open", ShowSpreadsheet); // We have to do this here. Otherwise there is a threading issue (Can't initialize from EditorPreferences outside the main thread) if (ExportOptions == null) { ExportOptions = new Google2uExportOptions("workbook" + WorkbookName.Replace(' ', '_') + "_Option_"); } if (mainFadeArea.Show()) { var showExport = false; var exportsheets = new List <Google2uWorksheet>(); switch (WorksheetQueryStatus) { case QueryStatus.Idle: { WorksheetQueryStatus = QueryStatus.Uninitialized; } break; case QueryStatus.Querying: EditorGUILayout.LabelField( Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_WORKSHEETS) + Google2u.Ellipses); break; case QueryStatus.QueryComplete: if (WorksheetsDisplay.Length > 0) { foreach (var google2UWorksheet in WorksheetsDisplay) { if (google2UWorksheet.DrawGUIList(in_layout)) { exportsheets.Add(google2UWorksheet); showExport = true; } } if (_OpenInvalidSheet) { var stillQuerying = false; for (var i = 0; i < Worksheets.Count; ++i) { if (!exportsheets.Contains(Worksheets[i])) { continue; } if (Worksheets[i].UpdateValidation || Worksheets[i].Validating) { stillQuerying = true; } if (Worksheets[i].IsDataValid == false) { var ed = EditorWindow.GetWindow <Google2uEditor>(); Google2u.ActiveWorkbookWindow = ed; ed.Workbook = this; ed.Layout = in_layout; #if (UNITY_4) ed.title = WorkbookName; #elif (UNITY_5_0) ed.title = WorkbookName; #else ed.titleContent.text = WorkbookName; #endif ed.wantsMouseMove = true; ActiveWorksheetIndex = i; Worksheets[i].HighlightFirstInvalidCell(); _OpenInvalidSheet = false; break; } } if (!stillQuerying) { _OpenInvalidSheet = false; } } EditorGUILayout.BeginHorizontal(); var content = new GUIContent(in_layout.RefreshButton, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_REFRESH_WORKBOOK)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { Worksheets.Clear(); WorksheetQueryStatus = QueryStatus.Uninitialized; } var querying = false; var bAllWorksheetsValid = true; foreach (var google2UWorksheet in exportsheets) { if (google2UWorksheet.IsDataValid == false) { bAllWorksheetsValid = false; } if (google2UWorksheet.WorksheetQueryStatus != QueryStatus.Idle) { querying = true; } } { var guiEnabled = GUI.enabled; if (querying) { GUI.enabled = false; } content = bAllWorksheetsValid ? new GUIContent(in_layout.ValidateButtonGreen, Google2u.LocalizationInfo.Localize( Localization.rowIds.ID_LABEL_VALIDATE_WORKBOOK)) : new GUIContent(in_layout.ValidateButtonRed, Google2u.LocalizationInfo.Localize( Localization.rowIds.ID_LABEL_VALIDATE_WORKBOOK)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { // Do Validation for the worksheets we will be exporting foreach (var google2UWorksheet in exportsheets) { google2UWorksheet.UpdateValidation = true; google2UWorksheet.Validating = true; } _OpenInvalidSheet = true; } GUI.enabled = guiEnabled; } content = new GUIContent(in_layout.EditButton, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EDIT_WORKBOOK)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { var ed = EditorWindow.GetWindow <Google2uEditor>(); Google2u.ActiveWorkbookWindow = ed; ed.Workbook = this; ed.Layout = in_layout; #if (UNITY_4) ed.title = WorkbookName; #elif (UNITY_5_0) ed.title = WorkbookName; #else ed.titleContent.text = WorkbookName; #endif ed.wantsMouseMove = true; } GUILayout.FlexibleSpace(); if (showExport) { var oldEnabled = GUI.enabled; if (bAllWorksheetsValid == false) { GUI.enabled = false; } content = new GUIContent(in_layout.SaveButton, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EXPORT)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { DoExport(exportsheets); } GUI.enabled = oldEnabled; } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.LabelField( Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_NO_WORKSHEETS)); } break; } } in_layout.EndFadeArea(); return(ret); }
public static void ExportNGUILegacy(Google2uWorksheet in_sheet, string in_path, Google2uExportOptions in_options) { if (!Directory.Exists(in_path)) { Directory.CreateDirectory(in_path); } var finalCol = in_sheet.Rows[0].Count; if (in_options.NGUICullColumns) { finalCol = in_sheet.FirstBlankCol; } var languages = new List <string>(); for (var j = 1; j < in_sheet.Rows[0].Count - 1; ++j) { if (j == finalCol) { break; } languages.Add(in_sheet.Rows[0][j].CellValueString); } foreach (var lang in languages) { var filepath = in_path + "/" + lang + ".txt"; using ( var fs = File.Open(filepath, File.Exists(filepath) ? FileMode.Truncate : FileMode.OpenOrCreate, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { var langIndex = 0; for (var index = 0; index < in_sheet.Rows[0].Cells.Count; index++) { var cell = in_sheet.Rows[0].Cells[index]; if (cell.CellValueString.Equals(lang)) { langIndex = index; break; } } sw.Write(ExportNGUILegacyString(in_sheet, in_options, langIndex)); sw.Flush(); } } } }
public void Update(bool in_isActive, Google2uExportOptions in_options) { if (!_Initialized) return; if ((DateTime.Now - LastUpdateTime).TotalSeconds > 15) { LastUpdateTime = DateTime.Now; _QueryThread = null; if (WorksheetQueryStatus == QueryStatus.Uninitialized) { if (_NewQueryThread == null || _NewQueryThread.IsAlive == false) { _NewQueryThread = new Thread(QueryCells); _QueryThread = _NewQueryThread; } } else if (IsDataValid && in_isActive && DoUpdateQuery && WorksheetQueryStatus == QueryStatus.Idle) { if (_UpdateQueryThread == null || _UpdateQueryThread.IsAlive == false) { DoUpdateQuery = false; _UpdateQueryThread = new Thread(UpdateQuery); _QueryThread = _UpdateQueryThread; } } if (_QueryThread == null) return; WorksheetQueryStatus = QueryStatus.Querying; _QueryThread.Start(this); } else if (Rows != null && WorksheetQueryStatus == QueryStatus.Idle && UpdateCellTypes) { if (_UpdateCellTypesThread == null || _UpdateCellTypesThread.IsAlive == false) { UpdateCellTypes = false; _UpdateCellTypesThread = new Thread(DoUpdateCellTypes); _UpdateCellTypesThread.Start(this); } } if (Rows != null && UpdateValidation) { if (_ValidationThread == null || _ValidationThread.IsAlive == false) { UpdateValidation = false; _ValidationThread = new Thread(DoDataValidation); _ValidationThread.Start(new DataValidationParams(this, in_options)); } } }
public static string ExportJsonObjectString(Google2uWorksheet in_sheet, Google2uExportOptions in_options, bool in_newlines) { var indent = 0; var retString = string.Empty; var escapeUnicode = in_options.EscapeUnicode; var bConvertArrays = !in_options.JSONCellArrayToString; if (in_options.JSONExportPretty) { in_newlines = true; } if (in_options.JSONExportType == Google2uExportOptions.ExportType.ExportObject) { retString += Indent(indent, "{"); if (in_newlines) { retString += Environment.NewLine; indent++; } retString += Indent(indent, ("\"" + SanitizeJson(in_sheet.WorksheetName, escapeUnicode) + "Row\":")); // "sheetName": if (in_newlines) { retString += Environment.NewLine; } } retString += Indent(indent, "["); // [ if (in_newlines) { retString += Environment.NewLine; indent++; } var rowCt = in_sheet.Rows.Count; if (rowCt > 0) { var curRow = 0; var validRow = false; // Iterate through each row, printing its cell values. foreach (var row in in_sheet.Rows) { // if we are skipping the type row, record the types and increment curRow now if (curRow == 0 || (curRow == 1 && in_sheet.UseTypeRow)) { curRow++; continue; } var rowType = row[0].GetTypeFromValue(); var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.JSONCullRows) { break; } curRow++; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { curRow++; continue; } if (validRow) { retString += ","; if (in_newlines) { retString += Environment.NewLine; } } validRow = true; retString += Indent(indent, "{"); if (in_newlines) { retString += Environment.NewLine; indent++; } var firstCell = true; // Iterate over the remaining columns, and print each cell value for (var i = 0; i < in_sheet.Rows[0].Count; i++) { // Don't process rows or columns marked for ignore if ((row[i].MyType == SupportedType.Void || string.IsNullOrEmpty(row[0].CellValueString) || in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(in_sheet.Rows[0][i].CellValueString) || in_sheet.Rows[0][i].CellValueString.Equals("void", StringComparison.InvariantCultureIgnoreCase) || in_sheet.Rows[0][i].CellValueString.Equals("ignore", StringComparison.InvariantCultureIgnoreCase) || (in_options.JSONCullColumns && i >= in_sheet.FirstBlankCol) || (in_options.JSONIgnoreIDColumn && i == 0))) { continue; } if (firstCell) { firstCell = false; } else { retString += ", "; if (in_newlines) { retString += Environment.NewLine; } } var myType = in_sheet.Rows[0].Cells[i].MyType; if (IsComplexType(myType)) { retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":"); if (in_newlines) { retString += Environment.NewLine; indent++; } retString += Indent(indent, "["); if (in_newlines) { retString += Environment.NewLine; indent++; } var complexTypeDelim = in_options.DelimiterOptions[in_options.ComplexTypeDelimiters].ToCharArray(); var value = row[i].CellValueString.Split(complexTypeDelim, StringSplitOptions.RemoveEmptyEntries); var ct = 0; foreach (var s in value) { retString += Indent(indent, SanitizeJson(s, escapeUnicode)); if (ct < value.Length - 1) { retString += ","; if (in_newlines) { retString += Environment.NewLine; } } ct++; } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "]"); if (in_newlines) { indent--; } } else if (IsComplexArrayType(myType)) { retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":"); if (in_newlines) { retString += Environment.NewLine; indent++; } retString += Indent(indent, "["); if (in_newlines) { retString += Environment.NewLine; indent++; } var complexArrayDelim = in_options.DelimiterOptions[in_options.ComplexArrayDelimiters].ToCharArray(); var complexArray = row[i].CellValueString.Split(complexArrayDelim, StringSplitOptions.RemoveEmptyEntries); var ctArray = 0; foreach (var cv in complexArray) { if (in_newlines) { retString += Environment.NewLine; indent++; } retString += Indent(indent, "["); if (in_newlines) { retString += Environment.NewLine; indent++; } var complexTypeDelim = in_options.DelimiterOptions[in_options.ComplexTypeDelimiters].ToCharArray(); var complexType = cv.Split(complexTypeDelim, StringSplitOptions.RemoveEmptyEntries); var ctValue = 0; foreach (var s in complexType) { retString += Indent(indent, SanitizeJson(s, escapeUnicode)); if (ctValue < complexType.Length - 1) { retString += ","; if (in_newlines) { retString += Environment.NewLine; } } ctValue++; } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "]"); if (in_newlines) { indent--; } if (ctArray < complexArray.Length - 1) { retString += ","; if (in_newlines) { retString += Environment.NewLine; } } ctArray++; } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "]"); if (in_newlines) { indent--; } } else if (bConvertArrays && IsSupportedArrayType(myType)) { var delim = in_options.DelimiterOptions[in_options.ArrayDelimiters].ToCharArray(); retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":"); if (in_newlines) { retString += Environment.NewLine; indent++; } retString += Indent(indent, "["); if (in_newlines) { retString += Environment.NewLine; indent++; } var isString = false; if (row[i].MyType == SupportedType.StringArray) { delim = in_options.DelimiterOptions[in_options.StringArrayDelimiters].ToCharArray(); isString = true; } if (i == 0) { isString = true; } var value = row[i].CellValueString.Split(delim, StringSplitOptions.RemoveEmptyEntries); var ct = 0; foreach (var s in value) { if (isString) { retString += Indent(indent, "\"" + SanitizeJson(s, escapeUnicode) + "\""); } else if (in_sheet.Rows[0].Cells[i].MyType == SupportedType.BoolArray) { var val = s.ToLower(); if (val == "1") { val = "true"; } if (val == "0") { val = "false"; } retString += Indent(indent, SanitizeJson(val, escapeUnicode)); } else { retString += Indent(indent, SanitizeJson(s, escapeUnicode)); } if (ct < value.Length - 1) { retString += ","; if (in_newlines) { retString += Environment.NewLine; } } ct++; } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "]"); if (in_newlines) { indent--; } } else { if (in_sheet.UseTypeRow == false || in_sheet.Rows[0].Cells[i].MyType == SupportedType.String || (i == 0)) { retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":\"" + SanitizeJson(row[i].CellValueString, escapeUnicode) + "\""); } else if (in_sheet.Rows[0].Cells[i].MyType == SupportedType.Bool) { var val = row[i].CellValueString.ToLower(); if (val == "1") { val = "true"; } if (val == "0") { val = "false"; } retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":" + SanitizeJson(val, escapeUnicode)); } else if (in_sheet.Rows[0].Cells[i].MyType == SupportedType.BoolArray) { var val = row[i].CellValueString.ToLower(); if (val == "1") { val = "true"; } if (val == "0") { val = "false"; } retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":" + SanitizeJson(val, escapeUnicode)); } else { retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":" + SanitizeJson(row[i].CellValueString, escapeUnicode) + ""); } } if (in_newlines) { //retString += Environment.NewLine; } } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "}"); curRow++; } } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "]"); if (in_options.JSONExportType == Google2uExportOptions.ExportType.ExportObject) { if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "}"); } return(retString); }
public static string ExportJsonObjectClassString(Google2uWorksheet in_sheet, Google2uExportOptions in_options, int in_indent) { var retString = string.Empty; if (in_sheet.Rows.Count <= 0) { return(retString); } var headerRow = in_sheet.Rows[0]; var indent = in_indent; retString += FormatLine("//----------------------------------------------"); retString += FormatLine("// Google2u: Google Doc Unity integration"); retString += FormatLine("// Copyright © 2015 Litteratus"); retString += FormatLine("//"); retString += FormatLine("// This file has been auto-generated"); retString += FormatLine("// Do not manually edit"); retString += FormatLine("//----------------------------------------------"); retString += FormatLine(string.Empty); retString += FormatLine("using System.Collections.Generic;"); retString += FormatLine("using UnityEngine;"); retString += FormatLine(string.Empty); retString += FormatLine("namespace Google2u"); retString += FormatLine("{"); indent++; retString += Indent(indent, "public class " + in_sheet.WorksheetName + "Row" + Environment.NewLine); retString += Indent(indent, "{" + Environment.NewLine); indent++; var idCell = true; foreach (var cell in headerRow.Cells) { if (!idCell && (cell.MyType == SupportedType.Void || cell.MyType == SupportedType.Unrecognized)) // Don't process rows or columns marked for ignore { if (in_options.JSONCullColumns) { break; } continue; } retString += Indent(indent, ""); if (idCell) { retString += "public string " + cell.CellValueString + " { get; set; }" + Environment.NewLine; } else { // check the type switch (cell.MyType) { case SupportedType.GameObject: case SupportedType.String: retString += "public string " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Int: retString += "public int " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Float: retString += "public float " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Bool: retString += "public bool " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Byte: retString += "public byte " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Vector2: retString += "public List<float> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; retString += Indent(indent, ""); retString += "public Vector2 " + cell.CellValueString + "_Vector2 { get { return new Vector2(" + cell.CellValueString + "[0], " + cell.CellValueString + "[1]); } }" + Environment.NewLine; break; case SupportedType.Vector3: retString += "public List<float> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; retString += Indent(indent, ""); retString += "public Vector3 " + cell.CellValueString + "_Vector3 { get { return new Vector3(" + cell.CellValueString + "[0], " + cell.CellValueString + "[1], " + cell.CellValueString + "[2]); } }" + Environment.NewLine; break; case SupportedType.Color: retString += "public List<float> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; retString += Indent(indent, ""); retString += "public Color " + cell.CellValueString + "_Color { get { return new Color(" + cell.CellValueString + "[0], " + cell.CellValueString + "[1], " + cell.CellValueString + "[2], " + cell.CellValueString + "[3]); } }" + Environment.NewLine; break; case SupportedType.Color32: retString += "public List<int> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; retString += Indent(indent, ""); retString += "public Color32 " + cell.CellValueString + "_Color32 { get { return new Color((byte)" + cell.CellValueString + "[0], (byte)" + cell.CellValueString + "[1], (byte)" + cell.CellValueString + "[2], (byte)" + cell.CellValueString + "[3]); } }" + Environment.NewLine; break; case SupportedType.Quaternion: retString += "public List<float> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; retString += Indent(indent, ""); retString += "public Quaternion " + cell.CellValueString + "_Quaternion { get { return new Color(" + cell.CellValueString + "[0], " + cell.CellValueString + "[1], " + cell.CellValueString + "[2], " + cell.CellValueString + "[3]); } }" + Environment.NewLine; break; case SupportedType.FloatArray: retString += "public List<float> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.IntArray: retString += "public List<int> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.BoolArray: retString += "public List<bool> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.ByteArray: retString += "public List<byte> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.StringArray: retString += "public List<string> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Vector2Array: retString += "public List<List<float>> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; retString += Indent(indent, ""); retString += string.Format( "public Vector2[] {0}_Vector2Array {{get {{var len = {0}.Count; var ret = new Vector2[len]; for (var i = 0; i < len; ++i) {{ ret[i] = new Vector2({0}[i][0], {0}[i][1]); }} return ret; }} }}", cell.CellValueString); break; case SupportedType.Vector3Array: retString += "public List<List<float>> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; retString += Indent(indent, ""); retString += string.Format( "public Vector3[] {0}_Vector3Array {{get {{var len = {0}.Count; var ret = new Vector3[len]; for (var i = 0; i < len; ++i) {{ ret[i] = new Vector3({0}[i][0], {0}[i][1], {0}[i][2]); }} return ret; }} }}", cell.CellValueString); break; case SupportedType.ColorArray: retString += "public List<List<float>> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; retString += Indent(indent, ""); retString += string.Format( "public Color[] {0}_ColorArray {{get {{var len = {0}.Count; var ret = new Color[len]; for (var i = 0; i < len; ++i) {{ ret[i] = new Color({0}[i][0], {0}[i][1], {0}[i][2], {0}[i][3]); }} return ret; }} }}", cell.CellValueString); break; case SupportedType.Color32Array: retString += "public List<List<float>> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; retString += Indent(indent, ""); retString += string.Format( "public Color32[] {0}_Color32Array {{get {{var len = {0}.Count; var ret = new Color32[len]; for (var i = 0; i < len; ++i) {{ ret[i] = new Color32({0}[i][0], {0}[i][1], {0}[i][2], {0}[i][3]); }} return ret; }} }}", cell.CellValueString); break; case SupportedType.QuaternionArray: retString += "public List<List<float>> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; retString += Indent(indent, ""); retString += string.Format( "public Quaternion[] {0}_QuaternionArray {{get {{var len = {0}.Count; var ret = new Quaternion[len]; for (var i = 0; i < len; ++i) {{ ret[i] = new Quaternion({0}[i][0], {0}[i][1], {0}[i][2], {0}[i][3]); }} return ret; }} }}", cell.CellValueString); break; } } idCell = false; } indent--; retString += Indent(indent, "}" + Environment.NewLine); if (in_options.JSONExportType == Google2uExportOptions.ExportType.ExportObject) { retString += Environment.NewLine; retString += Indent(indent, "public class " + in_sheet.WorksheetName + "Database" + Environment.NewLine); retString += Indent(indent, "{" + Environment.NewLine); indent++; retString += Indent(indent, "public List< " + in_sheet.WorksheetName + "Row > " + in_sheet.WorksheetName + "Row { get; set; }" + Environment.NewLine); indent--; retString += Indent(indent, "}" + Environment.NewLine); } retString += FormatLine("}"); return(retString); }
public static string ExportJsonObjectClassString(Google2uWorksheet in_sheet, Google2uExportOptions in_options) { return(ExportJsonObjectClassString(in_sheet, in_options, 0)); }
public override bool DrawGUIList(EditorGUILayoutEx in_layout, bool in_showAll) { var ret = true; ShowSpreadsheet = Google2uGUIUtil.GetBool("mworkbook" + WorkbookName.Replace(' ', '_') + "_Open", ShowSpreadsheet); var mainFadeArea = in_layout.BeginFadeArea(ShowSpreadsheet, WorkbookName, "mworkbook" + WorkbookName.Replace(' ', '_'), in_layout.OuterBox, in_layout.OuterBoxHeader); ShowSpreadsheet = mainFadeArea.Open; Google2uGUIUtil.SetBool("mworkbook" + WorkbookName.Replace(' ', '_') + "_Open", ShowSpreadsheet); if (mainFadeArea.Show()) { // We have to do this here. Otherwise there is a threading issue (Can't initialize from EditorPreferences outside the main thread) if (ExportOptions == null) { ExportOptions = new Google2uExportOptions("mworkbook" + WorkbookName.Replace(' ', '_') + "_Option_"); } var showExport = false; var exportsheets = new List<Google2uWorksheet>(); switch (WorksheetQueryStatus) { case QueryStatus.Idle: { WorksheetQueryStatus = QueryStatus.Uninitialized; } break; case QueryStatus.Querying: EditorGUILayout.LabelField( Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_QUERYING_WORKSHEETS) + Google2u.Ellipses); break; case QueryStatus.QueryComplete: if (Worksheets.Count > 0) { foreach (var google2UWorksheet in Worksheets) { if (google2UWorksheet.DrawGUIList(in_layout)) { exportsheets.Add(google2UWorksheet); showExport = true; } } EditorGUILayout.BeginHorizontal(); var content = new GUIContent(in_layout.RefreshButton, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_REFRESH_WORKBOOK)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { Worksheets.Clear(); WorksheetQueryStatus = QueryStatus.Uninitialized; } var querying = false; var bAllWorksheetsValid = true; foreach (var google2UWorksheet in exportsheets) { if (google2UWorksheet.IsDataValid == false) bAllWorksheetsValid = false; if (google2UWorksheet.WorksheetQueryStatus != QueryStatus.Idle) querying = true; } { var guiEnabled = GUI.enabled; if (querying) GUI.enabled = false; content = bAllWorksheetsValid ? new GUIContent(in_layout.ValidateButtonGreen, Google2u.LocalizationInfo.Localize( Localization.rowIds.ID_LABEL_VALIDATE_WORKBOOK)) : new GUIContent(in_layout.ValidateButtonRed, Google2u.LocalizationInfo.Localize( Localization.rowIds.ID_LABEL_VALIDATE_WORKBOOK)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { // Do Validation for the worksheets we will be exporting foreach (var google2UWorksheet in exportsheets) { google2UWorksheet.UpdateValidation = true; } } GUI.enabled = guiEnabled; } content = new GUIContent(in_layout.EditButton, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_VIEW_WORKBOOK)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { var ed = EditorWindow.GetWindow<Google2uEditor>(); ed.Workbook = this; ed.Layout = in_layout; #if(UNITY_4) ed.title = WorkbookName; #elif(UNITY_5_0) ed.title = WorkbookName; #else ed.titleContent.text = WorkbookName; #endif ed.wantsMouseMove = true; } content = new GUIContent(in_layout.DeleteButton, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_REMOVE_WORKBOOK)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { if ( EditorUtility.DisplayDialog( Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_REMOVE_WORKBOOK), Google2u.LocalizationInfo.Localize( Localization.rowIds.ID_MESSAGE_REMOVE_WORKBOOK), Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_DELETE), Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_CANCEL))) ret = false; } GUILayout.FlexibleSpace(); if (showExport) { var oldEnabled = GUI.enabled; if (bAllWorksheetsValid == false) GUI.enabled = false; content = new GUIContent(in_layout.SaveButton, Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_LABEL_EXPORT)); if (GUILayout.Button(content, GUILayout.Height(EditorGUILayoutEx.ButtonHeight), GUILayout.Width(EditorGUILayoutEx.ButtonWidth))) { DoExport(exportsheets); } GUI.enabled = oldEnabled; } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.LabelField( Google2u.LocalizationInfo.Localize(Localization.rowIds.ID_MESSAGE_NO_WORKSHEETS)); } break; } } in_layout.EndFadeArea(); return ret; }
public static string ExportJsonObjectClassString(Google2uWorksheet in_sheet, Google2uExportOptions in_options) { return ExportJsonObjectClassString(in_sheet, in_options, 0); }
public static void ExportStaticDB(Google2uWorksheet in_sheet, string in_path, string in_fileName, Google2uExportOptions in_options) { if (!Directory.Exists(in_path)) Directory.CreateDirectory(in_path); var className = Path.GetInvalidFileNameChars().Aggregate(in_sheet.WorksheetName, (in_current, in_c) => in_current.Replace(in_c, '_')); var arrayDelimiter = in_options.DelimiterOptions[in_options.ArrayDelimiters]; var stringArrayDelimiter = in_options.DelimiterOptions[in_options.StringArrayDelimiters]; var complexTypeDelimiter = in_options.DelimiterOptions[in_options.ComplexTypeDelimiters]; var complexTypeArrayDelimiters = in_options.DelimiterOptions[in_options.ComplexArrayDelimiters]; var typesInFirstRow = in_sheet.UseTypeRow; /////////////////////////////////////////////// // open the file using (var fs = File.Open(Path.Combine(in_path, className + ".cs"), FileMode.Create, FileAccess.Write)) { using (var sw = new StreamWriter(fs)) { //////////////////////////////////////// // writing out the class var fileString = System.String.Empty; fileString += FormatLine("//----------------------------------------------"); fileString += FormatLine("// Google2u: Google Doc Unity integration"); fileString += FormatLine("// Copyright © 2015 Litteratus"); fileString += FormatLine("//"); fileString += FormatLine("// This file has been auto-generated"); fileString += FormatLine("// Do not manually edit"); fileString += FormatLine("//----------------------------------------------"); fileString += FormatLine(System.String.Empty); fileString += FormatLine("using UnityEngine;"); fileString += FormatLine(System.String.Empty); fileString += FormatLine("namespace Google2u"); fileString += FormatLine("{"); fileString += FormatLine(" [System.Serializable]"); fileString += FormatLine(" public class " + className + "Row : IGoogle2uRow"); fileString += FormatLine(" {"); // variable declarations for (int i = 1; i < in_sheet.Rows[0].Count; i++) { var rowType = in_sheet.Rows[0][i].MyType; var rowHeader = in_sheet.Rows[0][i].CellValueString; if (rowType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(rowHeader, in_options.LowercaseHeader)) || (in_options.StaticDBCullColumns && i > in_sheet.FirstBlankCol)) { continue; } if (IsSupportedArrayType(rowType)) fileString += FormatLine(" public System.Collections.Generic.List<" + StringSupportedType(rowType) + "> " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " = new System.Collections.Generic.List<" + StringSupportedType(rowType) + ">();"); else fileString += FormatLine(" public " + StringSupportedType(rowType) + " " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ";"); } // constructor parameter list fileString += (" public " + className + "Row("); { var firstItem = true; for (var i = 0; i < in_sheet.Rows[0].Count; i++) { var rowType = in_sheet.Rows[0][i].MyType; var rowHeader = in_sheet.Rows[0][i].CellValueString; if (rowType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(rowHeader, in_options.LowercaseHeader)) || (in_options.StaticDBCullColumns && i > in_sheet.FirstBlankCol)) continue; if (!firstItem) fileString += (", "); firstItem = false; fileString += ("string _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader)); } } fileString += FormatLine(") " + System.Environment.NewLine + " {"); // processing each of the input parameters and copying it into the members for (int i = 1; i < in_sheet.Rows[0].Count; i++) { var rowType = in_sheet.Rows[0][i].MyType; var rowHeader = in_sheet.Rows[0][i].CellValueString; //nightmare time if (rowType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(rowHeader, in_options.LowercaseHeader)) || (in_options.StaticDBCullColumns && i > in_sheet.FirstBlankCol)) { continue; } if (rowType == SupportedType.GameObject) { fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " = GameObject.Find(\"" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); } else if (rowType == SupportedType.Bool) { fileString += FormatLine(" {"); fileString += FormatLine(" " + StringSupportedType(rowType) + " res;"); fileString += FormatLine(" if(" + StringSupportedType(rowType) + ".TryParse(_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ", out res))"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " = res;"); fileString += FormatLine(" else"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " string: \"+ _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " +\" to bool\");"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Byte) { fileString += FormatLine(" {"); fileString += FormatLine(" " + StringSupportedType(rowType) + " res;"); fileString += FormatLine(" if(" + StringSupportedType(rowType) + ".TryParse(_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ", out res))"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " = res;"); fileString += FormatLine(" else"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " string: \"+ _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " +\" to byte\");"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Float) { fileString += FormatLine(" {"); fileString += FormatLine(" " + StringSupportedType(rowType) + " res;"); fileString += FormatLine(" if(" + StringSupportedType(rowType) + ".TryParse(_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ", out res))"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " = res;"); fileString += FormatLine(" else"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " string: \"+ _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " +\" to " + StringSupportedType(rowType) + "\");"); fileString += FormatLine(" }"); } else if ((rowType == SupportedType.ByteArray) || (rowType == SupportedType.BoolArray) || (rowType == SupportedType.FloatArray)) { fileString += FormatLine(" {"); fileString += FormatLine(" " + StringSupportedType(rowType) + " res;"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + arrayDelimiter + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" if(" + StringSupportedType(rowType) + ".TryParse(result[i], out res))"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add(res);"); fileString += FormatLine(" else"); fileString += FormatLine(" {"); if (rowType == SupportedType.ByteArray) fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( 0 );"); else if (rowType == SupportedType.BoolArray) fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( false );"); else if (rowType == SupportedType.FloatArray) fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( float.NaN );"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " string: \"+ result[i] +\" to " + (StringSupportedType(rowType)) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Int) { fileString += FormatLine(" {"); fileString += FormatLine(" " + StringSupportedType(rowType) + " res;"); fileString += FormatLine(" if(int.TryParse(_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ", out res))"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " = res;"); fileString += FormatLine(" else"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " string: \"+ _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " +\" to int\");"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.IntArray) { fileString += FormatLine(" {"); fileString += FormatLine(" " + (StringSupportedType(rowType)) + " res;"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + arrayDelimiter + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" if(int.TryParse(result[i], out res))"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( res );"); fileString += FormatLine(" else"); fileString += FormatLine(" {"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( 0 );"); fileString += FormatLine(" Debug.LogError(\"Failed To Convert " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " string: \"+ result[i] +\" to " + (StringSupportedType(rowType)) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.String) { if (in_options.TrimStrings) fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Trim();"); else fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ";"); } else if (rowType == SupportedType.StringArray) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + stringArrayDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); if (in_options.TrimStringArrays) fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( result[i].Trim() );"); else fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( result[i] );"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Vector2) { fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 2)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(rowType) + " in \" + _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int i = 0; i < 2; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float res;"); fileString += FormatLine(" if(float.TryParse(splitpath[i], out res))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[i] = res;"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".x = results[0];"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".y = results[1];"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Vector2Array) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + complexTypeArrayDelimiters + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = result[i].Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 2)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(rowType) + " in \" + _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int j = 0; j < splitpath.Length; j++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float [] temp = new float[splitpath.Length];"); fileString += FormatLine(" if(float.TryParse(splitpath[j], out temp[j]))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[j] = temp[j];"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" continue;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(rowType)) + "(results[0], results[1] ));"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Vector3) { fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(rowType) + " in \" + _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int i = 0; i < 3; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float res;"); fileString += FormatLine(" if(float.TryParse(splitpath[i], out res))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[i] = res;"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".x = results[0];"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".y = results[1];"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".z = results[2];"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Vector3Array) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + complexTypeArrayDelimiters + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = result[i].Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(rowType) + " in \" + _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int j = 0; j < splitpath.Length; j++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float [] temp = new float[splitpath.Length];"); fileString += FormatLine(" if(float.TryParse(splitpath[j], out temp[j]))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[j] = temp[j];"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" continue;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(rowType)) + "(results[0], results[1], results[2] ));"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Color) { fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3 && splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(rowType) + " in \" + _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int i = 0; i < splitpath.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float res;"); fileString += FormatLine(" if(float.TryParse(splitpath[i], out res))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[i] = res;"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".r = results[0];"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".g = results[1];"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".b = results[2];"); fileString += FormatLine(" if(splitpath.Length == 4)"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".a = results[3];"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.ColorArray) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + complexTypeArrayDelimiters + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = result[i].Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3 && splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(rowType) + " in \" + _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int j = 0; j < splitpath.Length; j++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float [] temp = new float[splitpath.Length];"); fileString += FormatLine(" if(float.TryParse(splitpath[j], out temp[j]))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[j] = temp[j];"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" continue;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" if(splitpath.Length == 3)"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(rowType)) + "(results[0], results[1], results[2] ));"); fileString += FormatLine(" else"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(rowType)) + "(results[0], results[1], results[2], results[3] ));"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Color32) { fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3 && splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(rowType) + " in \" + _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" byte []results = new byte[splitpath.Length];"); fileString += FormatLine(" for(int i = 0; i < splitpath.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" byte res;"); fileString += FormatLine(" if(byte.TryParse(splitpath[i], out res))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[i] = res;"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".r = results[0];"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".g = results[1];"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".b = results[2];"); fileString += FormatLine(" if(splitpath.Length == 4)"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".a = results[3];"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Color32Array) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + complexTypeArrayDelimiters + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = result[i].Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3 && splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(rowType) + " in \" + _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" byte []results = new byte[splitpath.Length];"); fileString += FormatLine(" for(int j = 0; j < splitpath.Length; j++)"); fileString += FormatLine(" {"); fileString += FormatLine(" byte [] temp = new byte[splitpath.Length];"); fileString += FormatLine(" if(byte.TryParse(splitpath[j], out temp[j]))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[j] = temp[j];"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" continue;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" if(splitpath.Length == 3)"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(rowType)) + "(results[0], results[1], results[2], System.Convert.ToByte(0) ));"); fileString += FormatLine(" else"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(rowType)) + "(results[0], results[1], results[2], results[3] ));"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.Quaternion) { fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(rowType) + " in \" + _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int i = 0; i < 4; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float res;"); fileString += FormatLine(" if(float.TryParse(splitpath[i], out res))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[i] = res;"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".x = results[0];"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".y = results[1];"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".z = results[2];"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".w = results[3];"); fileString += FormatLine(" }"); } else if (rowType == SupportedType.QuaternionArray) { fileString += FormatLine(" {"); fileString += FormatLine(" string []result = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Split(\"" + complexTypeArrayDelimiters + "\".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" for(int i = 0; i < result.Length; i++)"); fileString += FormatLine(" {"); fileString += FormatLine(" {"); fileString += FormatLine(" string [] splitpath = result[i].Split(\"" + complexTypeDelimiter + "\".ToCharArray(),System.StringSplitOptions.RemoveEmptyEntries);"); fileString += FormatLine(" if(splitpath.Length != 3 && splitpath.Length != 4)"); fileString += FormatLine(" Debug.LogError(\"Incorrect number of parameters for " + StringSupportedType(rowType) + " in \" + _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " );"); fileString += FormatLine(" float []results = new float[splitpath.Length];"); fileString += FormatLine(" for(int j = 0; j < splitpath.Length; j++)"); fileString += FormatLine(" {"); fileString += FormatLine(" float [] temp = new float[splitpath.Length];"); fileString += FormatLine(" if(float.TryParse(splitpath[j], out temp[j]))"); fileString += FormatLine(" {"); fileString += FormatLine(" results[j] = temp[j];"); fileString += FormatLine(" }"); fileString += FormatLine(" else "); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError(\"Error parsing \" + " + "_" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " + \" Component: \" + splitpath[i] + \" parameter \" + i + \" of variable " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + "\");"); fileString += FormatLine(" continue;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ".Add( new " + (StringSupportedType(rowType)) + "(results[0], results[1], results[2], results[3] ));"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); } else { fileString += FormatLine(" " + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + " = _" + MakeValidVariableName(rowHeader, in_options.LowercaseHeader) + ";"); } } fileString += FormatLine(" }"); fileString += FormatLine(System.String.Empty); { int colCount = 0; for (int i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.StaticDBCullColumns && i > in_sheet.FirstBlankCol)) continue; colCount++; } fileString += FormatLine(" public int Length { get { return " + colCount + "; } }"); } fileString += FormatLine(System.String.Empty); // allow indexing by [] fileString += FormatLine(" public string this[int i]"); fileString += FormatLine(" {"); fileString += FormatLine(" get"); fileString += FormatLine(" {"); fileString += FormatLine(" return GetStringDataByIndex(i);"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); fileString += FormatLine(System.String.Empty); // get string data by index lets the user use an int field rather than the name to retrieve the data fileString += FormatLine(" public string GetStringDataByIndex( int index )"); fileString += FormatLine(" {"); fileString += FormatLine(" string ret = System.String.Empty;"); fileString += FormatLine(" switch( index )"); fileString += FormatLine(" {"); { var colNum = 0; for (int i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.StaticDBCullColumns && i > in_sheet.FirstBlankCol)) continue; fileString += FormatLine(" case " + colNum++ + ":"); fileString += FormatLine(" ret = " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".ToString();"); fileString += FormatLine(" break;"); } } fileString += FormatLine(" }"); fileString += FormatLine(System.String.Empty); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(System.String.Empty); // get the data by column name rather than index fileString += FormatLine(" public string GetStringData( string colID )"); fileString += FormatLine(" {"); fileString += FormatLine(" var ret = System.String.Empty;"); if (in_options.LowercaseHeader) fileString += FormatLine(" switch( colID.ToLower() )"); else fileString += FormatLine(" switch( colID )"); fileString += FormatLine(" {"); for (int i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.StaticDBCullColumns && i > in_sheet.FirstBlankCol)) continue; fileString += FormatLine(" case \"" + (in_sheet.Rows[0][i].CellValueString) + "\":"); fileString += FormatLine(" ret = " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".ToString();"); fileString += FormatLine(" break;"); } fileString += FormatLine(" }"); fileString += FormatLine(System.String.Empty); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(" public override string ToString()"); fileString += FormatLine(" {"); fileString += FormatLine(" string ret = System.String.Empty;"); for (int i = 1; i < in_sheet.Rows[0].Count; i++) { if (in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader)) || (in_options.StaticDBCullColumns && i > in_sheet.FirstBlankCol)) continue; fileString += FormatLine(" ret += \"{\" + \"" + (in_sheet.Rows[0][i].CellValueString) + "\" + \" : \" + " + MakeValidVariableName(in_sheet.Rows[0][i].CellValueString, in_options.LowercaseHeader) + ".ToString() + \"} \";"); } fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(" }"); /////////////////////////////////////////////////////////////////////////////// // the database class itself, this contains the rows defined above fileString += FormatLine(" public sealed class " + className + " : IGoogle2uDB"); fileString += FormatLine(" {"); // this is the enums, the enum matches the name of the row fileString += FormatLine(" public enum rowIds {"); fileString += (" "); { int curRow = 0; // Iterate through each row, printing its cell values to be the enum names. foreach (var row in in_sheet.Rows) { if (curRow == 0 || (in_sheet.UseTypeRow && curRow == 1)) { curRow++; continue; } var rowType = row[0].MyType; var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.StaticDBCullRows) break; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { continue; } fileString += rowHeader; if ((curRow + 1) % 20 == 0) fileString += System.Environment.NewLine + " "; fileString += (", "); curRow++; } } fileString = fileString.Remove(fileString.Length - 2); // remove the last comma fileString += FormatLine(System.String.Empty); fileString += FormatLine(" };"); fileString += FormatLine(" public string [] rowNames = {"); fileString += " "; // Iterate through each row, printing its cell values for the row names strings. { int curRow = 0; foreach (var row in in_sheet.Rows) { if (curRow == 0 || (in_sheet.UseTypeRow && curRow == 1)) { curRow++; continue; } var rowType = row[0].MyType; var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.StaticDBCullRows) break; curRow++; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { curRow++; continue; } fileString += "\"" + rowHeader + "\""; if ((curRow + 1) % 20 == 0) fileString += System.Environment.NewLine + " "; fileString += ", "; curRow++; } } fileString = fileString.Remove(fileString.Length - 2); // remove the last comma fileString += FormatLine(System.Environment.NewLine + " };"); // the declaration of the storage for the row data fileString += FormatLine(" public System.Collections.Generic.List<" + className + "Row> Rows = new System.Collections.Generic.List<" + className + "Row>();"); // declare the instance as well as the get functionality fileString += FormatLine(System.String.Empty); fileString += FormatLine(" public static " + className + " Instance"); fileString += FormatLine(" {"); fileString += FormatLine(" get { return Nested" + className + ".instance; }"); fileString += FormatLine(" }"); fileString += FormatLine(System.String.Empty); fileString += FormatLine(" private class Nested" + className + ""); fileString += FormatLine(" {"); fileString += FormatLine(" static Nested" + className + "() { }"); fileString += FormatLine(" internal static readonly " + className + " instance = new " + className + "();"); fileString += FormatLine(" }"); fileString += FormatLine(System.String.Empty); fileString += FormatLine(" private " + className + "()"); fileString += FormatLine(" {"); var rowCt = 0; // Iterate through each row, printing its cell values. for (int i = 0; i < in_sheet.Rows.Count; i++) { // skip the first row. This is the title row, and we can get the values later if (rowCt == 0 || (typesInFirstRow && rowCt == 1)) { rowCt++; continue; } var rowType = in_sheet.Rows[i][0].MyType; var rowHeader = in_sheet.Rows[i][0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.StaticDBCullRows) break; rowCt++; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { rowCt++; continue; } // Iterate over the remaining columns, and print each cell value fileString += " Rows.Add( new " + className + "Row("; for (int j = 0; j < in_sheet.Rows[0].Count; j++) { if ((j != 0) && (in_sheet.Rows[i][j].MyType == SupportedType.Void || string.IsNullOrEmpty(MakeValidVariableName(in_sheet.Rows[0][j].CellValueString, in_options.LowercaseHeader)) || (in_options.StaticDBCullColumns && j > in_sheet.FirstBlankCol))) { continue; } fileString += ToLiteral(in_sheet.Rows[i][j].CellValueString) + ", "; } fileString = fileString.Remove(fileString.Length - 2); // remove the last comma fileString += FormatLine("));"); rowCt++; } fileString += FormatLine(" }"); fileString += FormatLine(" public IGoogle2uRow GetGenRow(string in_RowString)"); fileString += FormatLine(" {"); fileString += FormatLine(" IGoogle2uRow ret = null;"); fileString += FormatLine(" try"); fileString += FormatLine(" {"); fileString += FormatLine(" ret = Rows[(int)System.Enum.Parse(typeof(rowIds), in_RowString)];"); fileString += FormatLine(" }"); fileString += FormatLine(" catch(System.ArgumentException) {"); fileString += FormatLine(" Debug.LogError( in_RowString + \" is not a member of the rowIds enumeration.\");"); fileString += FormatLine(" }"); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(" public IGoogle2uRow GetGenRow(rowIds in_RowID)"); fileString += FormatLine(" {"); fileString += FormatLine(" IGoogle2uRow ret = null;"); fileString += FormatLine(" try"); fileString += FormatLine(" {"); fileString += FormatLine(" ret = Rows[(int)in_RowID];"); fileString += FormatLine(" }"); fileString += FormatLine(" catch( System.Collections.Generic.KeyNotFoundException ex )"); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError( in_RowID + \" not found: \" + ex.Message );"); fileString += FormatLine(" }"); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(" public " + className + "Row GetRow(rowIds in_RowID)"); fileString += FormatLine(" {"); fileString += FormatLine(" " + className + "Row ret = null;"); fileString += FormatLine(" try"); fileString += FormatLine(" {"); fileString += FormatLine(" ret = Rows[(int)in_RowID];"); fileString += FormatLine(" }"); fileString += FormatLine(" catch( System.Collections.Generic.KeyNotFoundException ex )"); fileString += FormatLine(" {"); fileString += FormatLine(" Debug.LogError( in_RowID + \" not found: \" + ex.Message );"); fileString += FormatLine(" }"); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(" public " + className + "Row GetRow(string in_RowString)"); fileString += FormatLine(" {"); fileString += FormatLine(" " + className + "Row ret = null;"); fileString += FormatLine(" try"); fileString += FormatLine(" {"); fileString += FormatLine(" ret = Rows[(int)System.Enum.Parse(typeof(rowIds), in_RowString)];"); fileString += FormatLine(" }"); fileString += FormatLine(" catch(System.ArgumentException) {"); fileString += FormatLine(" Debug.LogError( in_RowString + \" is not a member of the rowIds enumeration.\");"); fileString += FormatLine(" }"); fileString += FormatLine(" return ret;"); fileString += FormatLine(" }"); fileString += FormatLine(System.String.Empty); fileString += FormatLine(" }"); fileString += FormatLine(System.String.Empty); fileString += FormatLine("}"); sw.Write(fileString); /////////////////////////////////// // done writing, clean up sw.Flush(); } // Using streamwriter } // Using FileSystem PushNotification("Saving to: " + in_path); }
public static string ExportJsonObjectClassString(Google2uWorksheet in_sheet, Google2uExportOptions in_options, int in_indent) { var retString = string.Empty; if (in_sheet.Rows.Count <= 0) return retString; var headerRow = in_sheet.Rows[0]; var indent = in_indent; retString += FormatLine("//----------------------------------------------"); retString += FormatLine("// Google2u: Google Doc Unity integration"); retString += FormatLine("// Copyright © 2015 Litteratus"); retString += FormatLine("//"); retString += FormatLine("// This file has been auto-generated"); retString += FormatLine("// Do not manually edit"); retString += FormatLine("//----------------------------------------------"); retString += FormatLine(System.String.Empty); retString += FormatLine("using System.Collections.Generic;"); retString += FormatLine("using UnityEngine;"); retString += FormatLine(System.String.Empty); retString += FormatLine("namespace Google2u"); retString += FormatLine("{"); indent++; retString += Indent(indent, "public class " + in_sheet.WorksheetName + "Row" + Environment.NewLine); retString += Indent(indent, "{" + Environment.NewLine); indent++; var idCell = true; foreach (var cell in headerRow.Cells) { if(!idCell && (cell.MyType == SupportedType.Void || cell.MyType == SupportedType.Unrecognized)) // Don't process rows or columns marked for ignore { if (string.IsNullOrEmpty(cell.CellValueString) && in_options.JSONCullColumns) break; continue; } retString += Indent(indent, ""); if (idCell) { retString += "public string " + cell.CellValueString + " { get; set; }" + Environment.NewLine; } else { // check the type switch (cell.MyType) { case SupportedType.GameObject: case SupportedType.String: retString += "public string " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Int: retString += "public int " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Float: retString += "public float " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Bool: retString += "public bool " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Byte: retString += "public byte " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Vector2: retString += "public List<float> " + cell.CellValueString + " { get; set; }" + Environment.NewLine;retString += Indent(indent, ""); retString += "public Vector2 " + cell.CellValueString + "_Vector2 { get { return new Vector2(" + cell.CellValueString + "[0], " + cell.CellValueString + "[1]); } }" + Environment.NewLine; break; case SupportedType.Vector3: retString += "public List<float> " + cell.CellValueString + " { get; set; }" + Environment.NewLine;retString += Indent(indent, ""); retString += "public Vector3 " + cell.CellValueString + "_Vector3 { get { return new Vector3(" + cell.CellValueString + "[0], " + cell.CellValueString + "[1], " + cell.CellValueString + "[2]); } }" + Environment.NewLine; break; case SupportedType.Color: retString += "public List<float> " + cell.CellValueString + " { get; set; }" + Environment.NewLine;retString += Indent(indent, ""); retString += "public Color " + cell.CellValueString + "_Color { get { return new Color(" + cell.CellValueString + "[0], " + cell.CellValueString + "[1], " + cell.CellValueString + "[2], " + cell.CellValueString + "[3]); } }" + Environment.NewLine; break; case SupportedType.Color32: retString += "public List<int> " + cell.CellValueString + " { get; set; }" + Environment.NewLine;retString += Indent(indent, ""); retString += "public Color32 " + cell.CellValueString + "_Color32 { get { return new Color((byte)" + cell.CellValueString + "[0], (byte)" + cell.CellValueString + "[1], (byte)" + cell.CellValueString + "[2], (byte)" + cell.CellValueString + "[3]); } }" + Environment.NewLine; break; case SupportedType.Quaternion: retString += "public List<float> " + cell.CellValueString + " { get; set; }" + Environment.NewLine;retString += Indent(indent, ""); retString += "public Quaternion " + cell.CellValueString + "_Quaternion { get { return new Color(" + cell.CellValueString + "[0], " + cell.CellValueString + "[1], " + cell.CellValueString + "[2], " + cell.CellValueString + "[3]); } }" + Environment.NewLine; break; case SupportedType.FloatArray: retString += "public List<float> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.IntArray: retString += "public List<int> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.BoolArray: retString += "public List<bool> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.ByteArray: retString += "public List<byte> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.StringArray: retString += "public List<string> " + cell.CellValueString + " { get; set; }" + Environment.NewLine; break; case SupportedType.Vector2Array: retString += "public List<List<float>> " + cell.CellValueString + " { get; set; }" + Environment.NewLine;retString += Indent(indent, ""); retString += string.Format("public Vector2[] {0}_Vector2Array {{get {{var len = {0}.Count; var ret = new Vector2[len]; for (var i = 0; i < len; ++i) {{ ret[i] = new Vector2({0}[i][0], {0}[i][1]); }} return ret; }} }}", cell.CellValueString); break; case SupportedType.Vector3Array: retString += "public List<List<float>> " + cell.CellValueString + " { get; set; }" + Environment.NewLine;retString += Indent(indent, ""); retString += string.Format("public Vector3[] {0}_Vector3Array {{get {{var len = {0}.Count; var ret = new Vector3[len]; for (var i = 0; i < len; ++i) {{ ret[i] = new Vector3({0}[i][0], {0}[i][1], {0}[i][2]); }} return ret; }} }}", cell.CellValueString); break; case SupportedType.ColorArray: retString += "public List<List<float>> " + cell.CellValueString + " { get; set; }" + Environment.NewLine;retString += Indent(indent, ""); retString += string.Format("public Color[] {0}_ColorArray {{get {{var len = {0}.Count; var ret = new Color[len]; for (var i = 0; i < len; ++i) {{ ret[i] = new Color({0}[i][0], {0}[i][1], {0}[i][2], {0}[i][3]); }} return ret; }} }}", cell.CellValueString); break; case SupportedType.Color32Array: retString += "public List<List<float>> " + cell.CellValueString + " { get; set; }" + Environment.NewLine;retString += Indent(indent, ""); retString += string.Format("public Color32[] {0}_Color32Array {{get {{var len = {0}.Count; var ret = new Color32[len]; for (var i = 0; i < len; ++i) {{ ret[i] = new Color32({0}[i][0], {0}[i][1], {0}[i][2], {0}[i][3]); }} return ret; }} }}", cell.CellValueString); break; case SupportedType.QuaternionArray: retString += "public List<List<float>> " + cell.CellValueString + " { get; set; }" + Environment.NewLine;retString += Indent(indent, ""); retString += string.Format("public Quaternion[] {0}_QuaternionArray {{get {{var len = {0}.Count; var ret = new Quaternion[len]; for (var i = 0; i < len; ++i) {{ ret[i] = new Quaternion({0}[i][0], {0}[i][1], {0}[i][2], {0}[i][3]); }} return ret; }} }}", cell.CellValueString); break; } } idCell = false; } indent--; retString += Indent(indent, "}" + Environment.NewLine); if (in_options.JSONExportType == Google2uExportOptions.ExportType.ExportObject) { retString += Environment.NewLine; retString += Indent(indent, "public class " + in_sheet.WorksheetName + "Database" + Environment.NewLine); retString += Indent(indent, "{" + Environment.NewLine); indent++; retString += Indent(indent, "public List< " + in_sheet.WorksheetName + "Row > " + in_sheet.WorksheetName + "Row { get; set; }" + Environment.NewLine); indent--; retString += Indent(indent, "}" + Environment.NewLine); } retString += FormatLine("}"); return retString; }
public static string ExportNGUILegacyString(Google2uWorksheet in_sheet, Google2uExportOptions in_options) { return(ExportNGUILegacyString(in_sheet, in_options, 1)); }
public static string ExportJsonObjectString(Google2uWorksheet in_sheet, Google2uExportOptions in_options, bool in_newlines) { var indent = 0; var retString = String.Empty; var escapeUnicode = in_options.EscapeUnicode; var bConvertArrays = !in_options.JSONCellArrayToString; if (in_options.JSONExportType == Google2uExportOptions.ExportType.ExportObject) { retString += Indent(indent, "{"); if (in_newlines) { retString += Environment.NewLine; indent++; } retString += Indent(indent, ("\"" + SanitizeJson(in_sheet.WorksheetName, escapeUnicode) + "Row\":")); // "sheetName": if (in_newlines) { retString += Environment.NewLine; } } retString += Indent(indent, "["); // [ if (in_newlines) { retString += Environment.NewLine; indent++; } var rowCt = in_sheet.Rows.Count; if (rowCt > 0) { var curRow = 0; var validRow = false; // Iterate through each row, printing its cell values. foreach (var row in in_sheet.Rows) { // if we are skipping the type row, record the types and increment curRow now if (curRow == 0 || (curRow == 1 && in_sheet.UseTypeRow)) { curRow++; continue; } var rowType = row[0].GetTypeFromValue(); var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.JSONCullRows) break; curRow++; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { curRow++; continue; } if (validRow) { retString += ","; if (in_newlines) { retString += Environment.NewLine; } } validRow = true; retString += Indent(indent, "{"); if (in_newlines) { retString += Environment.NewLine; indent++; } bool firstCell = true; // Iterate over the remaining columns, and print each cell value for (int i = 0; i < in_sheet.Rows[0].Count; i++) { // Don't process rows or columns marked for ignore if ((row[i].MyType == SupportedType.Void || string.IsNullOrEmpty(row[0].CellValueString) || (in_options.JSONCullColumns && i > in_sheet.FirstBlankCol))) { continue; } if (firstCell) firstCell = false; else { retString += ", "; if (in_newlines) retString += Environment.NewLine; } var myType = in_sheet.Rows[0].Cells[i].MyType; if (IsComplexType(myType)) { retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":"); if (in_newlines) { retString += Environment.NewLine; indent++; } retString += Indent(indent, "["); if (in_newlines) { retString += Environment.NewLine; indent++; } var complexTypeDelim = in_options.DelimiterOptions[in_options.ComplexTypeDelimiters].ToCharArray(); var value = row[i].CellValueString.Split(complexTypeDelim, StringSplitOptions.RemoveEmptyEntries); var ct = 0; foreach (var s in value) { retString += Indent(indent, SanitizeJson(s, escapeUnicode)); if (ct < value.Length - 1) { retString += ","; if (in_newlines) { retString += Environment.NewLine; } } ct++; } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "]"); if (in_newlines) { indent--; } } else if(IsComplexArrayType(myType)) { retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":"); if (in_newlines) { retString += Environment.NewLine; indent++; } retString += Indent(indent, "["); if (in_newlines) { retString += Environment.NewLine; indent++; } var complexArrayDelim = in_options.DelimiterOptions[in_options.ComplexArrayDelimiters].ToCharArray(); var complexArray = row[i].CellValueString.Split(complexArrayDelim, StringSplitOptions.RemoveEmptyEntries); var ctArray = 0; foreach (var cv in complexArray) { if (in_newlines) { retString += Environment.NewLine; indent++; } retString += Indent(indent, "["); if (in_newlines) { retString += Environment.NewLine; indent++; } var complexTypeDelim = in_options.DelimiterOptions[in_options.ComplexTypeDelimiters].ToCharArray(); var complexType = cv.Split(complexTypeDelim, StringSplitOptions.RemoveEmptyEntries); var ctValue = 0; foreach (var s in complexType) { retString += Indent(indent, SanitizeJson(s, escapeUnicode)); if (ctValue < complexType.Length - 1) { retString += ","; if (in_newlines) { retString += Environment.NewLine; } } ctValue++; } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "]"); if (in_newlines) { indent--; } if (ctArray < complexArray.Length - 1) { retString += ","; if (in_newlines) { retString += Environment.NewLine; } } ctArray++; } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "]"); if (in_newlines) { indent--; } } else if (bConvertArrays && IsSupportedArrayType(myType)) { var delim = in_options.DelimiterOptions[in_options.ArrayDelimiters].ToCharArray(); retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":"); if (in_newlines) { retString += Environment.NewLine; indent++; } retString += Indent(indent, "["); if (in_newlines) { retString += Environment.NewLine; indent++; } bool isString = false; if (row[i].MyType == SupportedType.StringArray) { delim = in_options.DelimiterOptions[in_options.StringArrayDelimiters].ToCharArray(); isString = true; } if (i == 0) isString = true; var value = row[i].CellValueString.Split(delim, System.StringSplitOptions.RemoveEmptyEntries); var ct = 0; foreach (var s in value) { if (isString) { retString += Indent(indent, "\"" + SanitizeJson(s, escapeUnicode) + "\""); } else if (in_sheet.Rows[0].Cells[i].MyType == SupportedType.BoolArray) { string val = s.ToLower(); if (val == "1") val = "true"; if (val == "0") val = "false"; retString += Indent(indent, SanitizeJson(val, escapeUnicode)); } else retString += Indent(indent, SanitizeJson(s, escapeUnicode)); if (ct < value.Length - 1) { retString += ","; if (in_newlines) { retString += Environment.NewLine; } } ct++; } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "]"); if (in_newlines) { indent--; } } else { if (in_sheet.UseTypeRow == false || in_sheet.Rows[0].Cells[i].MyType == SupportedType.String || (i == 0)) { retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":\"" + SanitizeJson(row[i].CellValueString, escapeUnicode) + "\""); } else if (in_sheet.Rows[0].Cells[i].MyType == SupportedType.Bool) { string val = row[i].CellValueString.ToLower(); if (val == "1") val = "true"; if (val == "0") val = "false"; retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":" + SanitizeJson(val, escapeUnicode)); } else if (in_sheet.Rows[0].Cells[i].MyType == SupportedType.BoolArray) { string val = row[i].CellValueString.ToLower(); if (val == "1") val = "true"; if (val == "0") val = "false"; retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":" + SanitizeJson(val, escapeUnicode)); } else retString += Indent(indent, "\"" + SanitizeJson(in_sheet.Rows[0][i].CellValueString, escapeUnicode) + "\":" + SanitizeJson(row[i].CellValueString, escapeUnicode) + ""); } if (in_newlines) { //retString += Environment.NewLine; } } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "}"); curRow++; } } if (in_newlines) { retString += Environment.NewLine; indent--; } retString += Indent(indent, "]"); if (in_options.JSONExportType == Google2uExportOptions.ExportType.ExportObject) { if (in_newlines) { retString += Environment.NewLine; indent--; } retString += ("}"); } return retString; }
public static string ExportXMLString(Google2uWorksheet in_sheet, Google2uExportOptions in_options) { var bConvertArrays = !in_options.XMLCellArrayToString; // Create the System.Xml.XmlDocument. var xmlDoc = new XmlDocument(); var rootNode = xmlDoc.CreateElement("Sheets"); xmlDoc.AppendChild(rootNode); var sheetNode = xmlDoc.CreateElement("sheet"); var sheetName = xmlDoc.CreateAttribute("name"); sheetName.Value = in_sheet.WorksheetName; var curRow = 0; sheetNode.Attributes.Append(sheetName); rootNode.AppendChild(sheetNode); // Iterate through each row, printing its cell values. foreach (var row in in_sheet.Rows) { if (curRow < 1) { curRow++; continue; } if (in_sheet.UseTypeRow == true && curRow == 1) { curRow++; continue; } var rowType = row[0].GetTypeFromValue(); var rowHeader = row[0].CellValueString; if (string.IsNullOrEmpty(rowHeader)) // if this header is empty { if (in_options.XMLCullRows) break; curRow++; continue; } if (rowType == SupportedType.Void || rowHeader.Equals("void", StringComparison.InvariantCultureIgnoreCase)) // if this cell is void, then skip the row completely { curRow++; continue; } XmlNode rowNode = xmlDoc.CreateElement("row"); var rowName = xmlDoc.CreateAttribute("name"); rowName.Value = row[0].CellValueString; if (rowNode.Attributes == null) continue; rowNode.Attributes.Append(rowName); sheetNode.AppendChild(rowNode); // Iterate over the remaining columns, and print each cell value for (var i = 1; i < in_sheet.Rows[0].Count; i++) { // Don't process rows or columns marked for ignore if ((row[i].MyType == SupportedType.Void || string.IsNullOrEmpty(row[0].CellValueString) || in_sheet.Rows[0][i].MyType == SupportedType.Void || string.IsNullOrEmpty(in_sheet.Rows[0][i].CellValueString) || in_sheet.Rows[0][i].CellValueString.Equals("void", StringComparison.InvariantCultureIgnoreCase) || in_sheet.Rows[0][i].CellValueString.Equals("ignore", StringComparison.InvariantCultureIgnoreCase) || (in_options.XMLCullColumns && i >= in_sheet.FirstBlankCol))) { continue; } XmlNode colNode = xmlDoc.CreateElement(in_sheet.Rows[0][i].CellValueString); var colType = xmlDoc.CreateAttribute("type"); colType.Value = row[i].CellTypeString; if (colNode.Attributes != null) colNode.Attributes.Append(colType); if (bConvertArrays && IsSupportedArrayType(row[i].MyType)) { var delim = in_options.DelimiterOptions[in_options.ArrayDelimiters].ToCharArray(); if (row[i].MyType == SupportedType.StringArray) delim = in_options.DelimiterOptions[in_options.StringArrayDelimiters].ToCharArray(); var value = row[i].CellValueString.Split(delim, StringSplitOptions.RemoveEmptyEntries); foreach (var s in value) { XmlNode arrNode = xmlDoc.CreateElement("entry"); if (row[i].MyType == SupportedType.BoolArray) { var val = s.ToLower(); if (val == "1") val = "true"; if (val == "0") val = "false"; arrNode.InnerText = val; } else arrNode.InnerText = s; colNode.AppendChild(arrNode); } } else { colNode.InnerText = row[i].CellValueString; } rowNode.AppendChild(colNode); } curRow++; } string retstring; using (var stringWriter = new StringWriter()) { using (var xmlTextWriter = new XmlTextWriter(stringWriter)) { xmlTextWriter.Formatting = Formatting.Indented; xmlDoc.WriteTo(xmlTextWriter); retstring = stringWriter.ToString(); } } return retstring; }
public static string ExportNGUILegacyString(Google2uWorksheet in_sheet, Google2uExportOptions in_options) { return ExportNGUILegacyString(in_sheet, in_options, 1); }