public void SetCell <T>(int col, int row, T value) { // If we're writing a string, add it without formatting. if (value.GetType() == typeof(string)) { SetCellString(col, row, (string)(object)value); return; } var settings = new ES3Settings(); if (ES3Reflection.IsPrimitive(value.GetType())) { SetCellString(col, row, value.ToString()); } else { SetCellString(col, row, settings.encoding.GetString(ES3.Serialize(value))); } // Expand the spreadsheet if necessary. if (col >= cols) { cols = (col + 1); } if (row >= rows) { rows = (row + 1); } }
private void Generate() { var type = types[selectedType].type; if (type == null) { EditorUtility.DisplayDialog("Type not selected", "Type not selected. Please ensure you select a type", "Ok"); return; } // Get the serializable fields of this class. //var fields = ES3Reflection.GetSerializableES3Fields(type); // The string that we suffix to the class name. i.e. UnityEngine_UnityEngine_Transform. string es3TypeSuffix = type.Name; // The string for the full C#-safe type name. This name must be suitable for going inside typeof(). string fullType = GetFullTypeName(type); // The list of WriteProperty calls to write the properties of this type. string writes = GenerateWrites(); // The list of case statements and Read calls to read the properties of this type. string reads = GenerateReads(); // A comma-seperated string of fields we've supported in this type. string propertyNames = ""; bool first = true; for (int i = 0; i < fields.Length; i++) { if (!fieldSelected[i]) { continue; } if (first) { first = false; } else { propertyNames += ", "; } propertyNames += "\"" + fields[i].Name + "\""; } var easySaveEditorPath = ES3EditorUtility.PathToEasySaveFolder() + "Editor/"; // Insert the relevant strings into the template. string template; if (typeof(Component).IsAssignableFrom(type)) { template = File.ReadAllText(easySaveEditorPath + componentTemplateFile); } else if (ES3Reflection.IsPrimitive(type)) { template = File.ReadAllText(easySaveEditorPath + valueTemplateFile); } else { template = File.ReadAllText(easySaveEditorPath + classTemplateFile); } template = template.Replace("[es3TypeSuffix]", es3TypeSuffix); template = template.Replace("[fullType]", fullType); template = template.Replace("[writes]", writes); template = template.Replace("[reads]", reads); template = template.Replace("[propertyNames]", propertyNames); // Create the output file. string outputFilePath = GetOutputPath(type); File.WriteAllText(outputFilePath, template); AssetDatabase.Refresh(); }