Example #1
0
    private bool CreateClsFile(string className, string path, string templateName, CfgFieldInfo[] fieldInfos,
                               Dictionary <string, string> gValueDic, Dictionary <string, string> valueDic,
                               Func <CfgFieldInfo[], Dictionary <string, string>, Dictionary <string, string>, string, bool>[] fillHandlers,
                               bool readTemplateCache, List <ClassInfo> saveList, string fileName, bool canRewrite)
    {
        ClassInfo ci = new ClassInfo();

        ci.Name = className;
        ci.Dir  = EditorHelper.GetProjPath("Assets/Scripts/Game/Data/Config" + path);

        if (canRewrite == false && File.Exists(ci.SavePath))
        {
            UnityEngine.Debug.Log(string.Format("{0}不需要更新,已经跳过处理", ci.Name));
            return(false);
        }

        if (fillHandlers != null && fillHandlers.Length > 0)
        {
            for (int i = 0; i < fillHandlers.Length; i++)
            {
                var handler = fillHandlers[i];
                if (handler != null)
                {
                    if (!handler(fieldInfos, gValueDic, valueDic, fileName))
                    {
                        UnityEngine.Debug.LogError("填充数据错误:" + handler.Method.Name);
                        return(false);
                    }
                }
            }
        }

        ci.Body = TemplateEngine.Do(templateName, gValueDic, valueDic, readTemplateCache);
        if (valueDic != null)
        {
            valueDic.Clear();
        }

        if (ci.Body == null)
        {
            UnityEngine.Debug.LogError("构建" + ci.Name + "失败!");
            return(false);
        }

        saveList.Add(ci);
        return(true);
    }
Example #2
0
    /// <summary>
    /// 填充dao文件
    /// 主要处理了languageCode
    /// </summary>
    /// <param name="fieldInfos"></param>
    /// <param name="gValueDic"></param>
    /// <param name="valueDic"></param>
    /// <param name="readTemplateCache"></param>
    /// <param name="configName"></param>
    /// <returns></returns>
    private bool FillDao(CfgFieldInfo[] fieldInfos, Dictionary <string, string> gValueDic,
                         Dictionary <string, string> valueDic, string configName)
    {
        List <CfgFieldInfo> langFields = new List <CfgFieldInfo>(fieldInfos.Length);

        for (int i = 0; i < fieldInfos.Length; i++)
        {
            CfgFieldInfo info = fieldInfos[i];
            if (info.FunType == FunType.Lang)
            {
                langFields.Add(info);
            }
        }

        //创建CfgDao文件
        if (fieldInfos.Length < 1)
        {
            UnityEngine.Debug.LogError("xml没有字段信息" + "CfgCodeCreator.FillDao");
            return(false);
        }

        //处理语言代码
        if (langFields.Count > 0)
        {
            string languageCode  = "\r\n\r\n" + TemplateEngine.Do("CfgSwitchLangTemplate.txt", gValueDic, valueDic, false);
            string tryGetCodeStr = "";
            for (int i = 0; i < langFields.Count; i++)
            {
                CfgFieldInfo fieldInfo      = langFields[i];
                string       tryGetCodeItem = "                strDao.TryGetString(\"{0}.{1}.\" + cfg.GetKey(), language, ref cfg.{2});\r\n";
                tryGetCodeItem = string.Format(tryGetCodeItem, configName, fieldInfo.Name, fieldInfo.Name);
                tryGetCodeStr += tryGetCodeItem;
            }
            tryGetCodeStr            = tryGetCodeStr.Remove(tryGetCodeStr.Length - 2);
            valueDic["languageCode"] = languageCode.Replace("${TrGetCode}", tryGetCodeStr);
        }
        else
        {
            valueDic["languageCode"] = "";
        }
        return(true);
    }