/// <summary>
 /// 处理proto文件
 /// </summary>
 /// <param name="protoPath">proto路径</param>
 /// <param name="decodeOutputPath">转换脚本导出路径,默认与proto同路径,后缀名为".lua"</param>
 /// <param name="adjustOutputPath">调整脚本导出路径,默认与proto同路径,后缀为"_adj.lua"</param>
 /// <param name="needCheckCSharpType">是否需要检查C#类型是否存在</param>
 /// <returns>是否有lua文件生成</returns>
 public bool DealProto(string protoPath, string decodeOutputPath = null, string adjustOutputPath = null, bool needCheckCSharpType = false)
 {
     if (string.IsNullOrEmpty(protoPath))
     {
         return(false);
     }
     ClearCache();
     //生成转换代码
     if (string.IsNullOrEmpty(decodeOutputPath))
     {
         decodeOutputPath = Path.ChangeExtension(protoPath, ".lua");
     }
     decodeOutputFilePath = decodeOutputPath;
     proto = ProtocolControlCache_ProtoStructure.GetProtoStructure(protoPath);
     if (proto == null || (proto != null && string.IsNullOrEmpty(proto.Package)))
     {
         ClearCache();
         return(false);
     }
     else
     {
         GenerateDecodeLuaCodes(needCheckCSharpType);
         if (!SaveLuaCodes(decodeOutputFilePath))
         {
             ClearCache();
             return(false);
         }
         ClearCache();
     }
     //生成调整代码
     if (string.IsNullOrEmpty(adjustOutputPath))
     {
         adjustOutputPath = Path.ChangeExtension(protoPath, ".lua");
         adjustOutputPath = adjustOutputPath.Substring(0, adjustOutputPath.Length - 4) + "_adj.lua";
     }
     adjustOutputFilePath = adjustOutputPath;
     proto = ProtocolControlCache_ProtoStructure.GetProtoStructure(protoPath);
     if (proto == null || (proto != null && string.IsNullOrEmpty(proto.Package)))
     {
         ClearCache();
         return(false);
     }
     else
     {
         GenerateAdjustLuaCodes(false);
         if (!SaveLuaCodes(adjustOutputFilePath))
         {
             ClearCache();
             return(false);
         }
         ClearCache();
         return(true);
     }
 }
Example #2
0
 /// <summary>
 /// 从协议的消息结构得到其使用的proto的数据结构,若返回null则表明该消息未使用proto
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 public static ProtocolControlCache_ProtoStructure GetProtoStructure(ProtocolControlCache_Message msg)
 {
     if (msg != null)
     {
         if (msg.hasProto)
         {
             string path = string.Format("{0}/{1}.proto", LocalServerProtoPath, msg.protoData.protoName);
             ProtocolControlCache_ProtoStructure protoStructure = ProtocolControlCache_ProtoStructure.GetProtoStructure(path);
             return(protoStructure);
         }
     }
     return(null);
 }
Example #3
0
    /// <summary>
    /// 更新Lua提示文件
    /// </summary>
    /// <param name="protoFolderPath">proto文件夹路径</param>
    /// <param name="luaRefrenceFileName">lua引用文件名</param>
    /// <param name="isCommitToSVN">是否生成后提交svn</param>
    public static void UpdateLuaHintFile(string protoFolderPath, string luaRefrenceFileName, bool isCommitToSVN)
    {
        if (!Directory.Exists(protoFolderPath))
        {
            UnityEngine.Debug.LogErrorFormat("未找到 {0} 文件夹", protoFolderPath);
            return;
        }
        string luaRefrenceOutputPath = ProtoHintFolderPath;

        if (!Directory.Exists(luaRefrenceOutputPath))
        {
            Directory.CreateDirectory(luaRefrenceOutputPath);
        }
        string[]      files         = Directory.GetFiles(protoFolderPath);
        StringBuilder stringBuilder = new StringBuilder();

        for (int i = 0; i < files.Length; i++)
        {
            EditorUtility.DisplayProgressBar("解析proto结构", files[i], ((float)i) / files.Length);
            var protoStructure = ProtocolControlCache_ProtoStructure.GetProtoStructure(files[i]);
            EditorUtility.DisplayProgressBar("生成proto提示文件", files[i], ((float)i) / files.Length);
            for (int j = 0; j < protoStructure.Messages.Count; j++)
            {
                stringBuilder.Append(GenerateLuaClassHint(protoStructure, protoStructure.Messages[j]));
                stringBuilder.Append("\r\n\r\n");
            }
        }
        EditorUtility.ClearProgressBar();
        string outputFilePath = luaRefrenceOutputPath + "/" + luaRefrenceFileName;

        File.WriteAllText(outputFilePath, stringBuilder.ToString());
        UnityEngine.Debug.LogFormat("{0} 生成完毕,idea中可以引用该文件或者其所在文件夹", outputFilePath);
        if (isCommitToSVN)
        {
            //SVNEditorUtility.SVNCommit(luaRefrenceOutputPath);
        }
    }