public void GenerateClass(string savePath, string className, ExcelGameData data)
    {
        if (!Directory.Exists(savePath))
        {
            Directory.CreateDirectory(savePath);
        }
        string fileName = className + ExcelExporterUtil.ClientClassExt;
        //var content = ExcelExporterUtil.GenerateCommonClassStr("Config.JsonConfig", className, "ConfigJsonBase", data);
        List <string> types  = data.fieldTypeList;
        List <string> fields = data.fieldNameList;

        StringBuilder sb = new StringBuilder();

        ExcelExporterUtil.AddCommonSpaceToSb(sb);

        sb.AppendLine("using Newtonsoft.Json;");
        sb.AppendLine();

        //sb.AppendLine("namespace " + "Config.JsonConfig");
        //sb.AppendLine("{");

        //sb.AppendLine("\tpublic class " + className + ": ConfigJsonBase");
        //sb.AppendLine("\t{");

        //ExcelExporterUtil.AddFieldsToSb(sb, types, fields);

        //sb.AppendLine("\t}");
        //sb.AppendLine("}");
        ExcelExporterUtil.AddContentToSb(sb, "Config.JsonConfig", className, "ConfigJsonBase", types, fields, false);


        File.WriteAllText(savePath + fileName, sb.ToString());
    }
Beispiel #2
0
    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());
    }