public int ProcessFieldTypes(int row) { var rowData = excelData.GetRow(row); rowData.rowType = ExcelRowType.Type; for (int i = 0; i < rowData.count; i++) { var cell = rowData.GetCell(i); string type = "string"; if (clientFieldIndexList.Contains(i) || serverFieldIndexList.Contains(i)) { if (!SupportTypeUtil.TryGetTypeName(cell.stringValue, out type)) { Debug.LogError(string.Format("{0} 不支持类型 {1} 替换为string ", fileName, cell.stringValue)); } } //单次循环处理完 if (clientFieldIndexList.Contains(i)) { clientData.AddFieldType(type); } if (serverFieldIndexList.Contains(i)) { serverData.AddFieldType(type); } } return(++row); }
public void GenerateClass(string savePath, string className, ExcelGameData data) { if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } string fileName = className + ExcelExporterUtil.ClientClassExt; List <string> types = data.fieldTypeList; List <string> fields = data.fieldNameList; StringBuilder sb = new StringBuilder(); ExcelExporterUtil.AddCommonSpaceToSb(sb); sb.AppendLine("namespace Config.TextConfig"); sb.AppendLine("{"); sb.AppendLine("\tpublic class " + className + " : ConfigTextBase"); sb.AppendLine("\t{"); //跳过ID 字段 for (int i = 1; i < types.Count; i++) { var type = SupportTypeUtil.GetIType(types[i]); if (type != null) { sb.AppendLine(string.Format("\t\tpublic {0} {1};", type.realName, fields[i])); } } sb.AppendLine(); sb.AppendLine(); sb.AppendLine("\t\tpublic override void Write(int i, string value)"); sb.AppendLine("\t\t{"); sb.AppendLine("\t\t\tswitch (i)"); sb.AppendLine("\t\t\t{"); for (int i = 0; i < types.Count; i++) { sb.AppendLine("\t\t\t\tcase " + i + ":"); //默认第一个字段名称为ID 先临时处理 sb.AppendLine("\t\t\t\t\t" + (i == 0 ? "ID" : fields[i]) + " = " + SupportTypeUtil.GetTypeParseFuncName(types[i]) + "(value);"); sb.AppendLine("\t\t\t\t\tbreak;"); } sb.AppendLine("\t\t\t\tdefault:"); sb.AppendLine("\t\t\t\t\tUnityEngine.Debug.LogError(GetType().Name + \"src i:\" + i);"); sb.AppendLine("\t\t\t\t\tbreak;"); sb.AppendLine("\t\t\t}"); sb.AppendLine("\t\t}"); sb.AppendLine("\t}"); sb.AppendLine("}"); File.WriteAllText(savePath + fileName, sb.ToString()); }
public static void AddFieldsToSb(StringBuilder sb, List <string> types, List <string> fields) { for (int i = 1; i < types.Count; i++) { var type = SupportTypeUtil.GetIType(types[i]); if (type != null) { if (exportType == ExcelDataExportType.Json && type.isUnityType) { sb.AppendLine("\t\t" + type.jsonAttributeStr); } sb.AppendLine(string.Format("\t\tpublic {0} {1};", type.realName, fields[i])); } } }
bool DrawTypeCell(ExcelCell cell) { var list = SupportTypeUtil.GetSupportTypeList(); var type = SupportTypeUtil.GetIType(cell.stringValue); int index = 0; if (type != null) { index = list.IndexOf(type.realName); } int selectIndex = EditorGUILayout.Popup(index, list.ToArray()); if (selectIndex != index || type == null) { cell.stringValue = list[selectIndex]; return(true); } return(false); }