コード例 #1
0
    /// <summary>
    /// 从proto中获取关联的proto文件
    /// </summary>
    /// <param name="protoName"></param>
    /// <param name="protoNameList"></param>
    private void GetRelatedProtoFromProto(string protoName, string protoDirPath, List <string> protoNameList)
    {
        CSStringBuilder.Clear();
        //CSStringBuilder.AppendParams(ServerTool_ProtocolControllerWnd.LocalServerProtoPath);
        CSStringBuilder.AppendParams(protoDirPath);
        CSStringBuilder.AppendParams("/");
        CSStringBuilder.AppendParams(protoName);
        CSStringBuilder.AppendParams(".proto");
        string filePath = CSStringBuilder.ToStringParams();

        try
        {
            if (File.Exists(filePath))
            {
                string[] lineStrs = File.ReadAllLines(filePath);
                for (int i = 0; i < lineStrs.Length; i++)
                {
                    if (Regex.IsMatch(lineStrs[i], linePattern_ImportProto))
                    {
                        string newProtoName = lineStrs[i].Replace("import", string.Empty).Replace('\"', ' ').Replace(';', ' ').Replace(".proto", string.Empty).Trim();
                        if (!protoNameList.Contains(newProtoName))
                        {
                            GetRelatedProtoFromProto(newProtoName, protoDirPath, protoNameList);
                        }
                    }
                }
                if (!protoNameList.Contains(protoName))
                {
                    protoNameList.Add(protoName);
                }
            }
        }
        catch (Exception) { }
    }
コード例 #2
0
 /// <summary>
 /// 打开协议同名的proto文件
 /// </summary>
 /// <param name="protocol"></param>
 private void OpenProtoFile(ProtocolControlCache_Protocol protocol)
 {
     if (protocol != null)
     {
         ProtocolControlCache_ProtocolXMLStructure xmlStructure = ServerProtocolControllerWnd.DeserializeXML(protocol.xmlName);
         if (xmlStructure != null)
         {
             CSStringBuilder.Clear();
             CSStringBuilder.AppendParams(LocalServerProtoPath);
             CSStringBuilder.AppendParams('/');
             CSStringBuilder.AppendParams(xmlStructure.protoName);
             CSStringBuilder.AppendParams(".proto");
         }
         else
         {
             CSStringBuilder.Clear();
             CSStringBuilder.AppendParams(LocalServerProtoPath);
             CSStringBuilder.AppendParams('/');
             CSStringBuilder.AppendParams(protocol.xmlName);
             CSStringBuilder.AppendParams(".proto");
         }
         string fullPath = CSStringBuilder.ToStringParams();
         if (!File.Exists(fullPath))
         {
             UnityEngine.Debug.LogError(string.Format("{0} 文件不存在", fullPath));
             return;
         }
         Process.Start(fullPath);
     }
 }
コード例 #3
0
        static int _m_ToStringParams_xlua_st_(RealStatePtr L)
        {
            try {
                {
                    var gen_ret = CSStringBuilder.ToStringParams(  );
                    LuaAPI.lua_pushstring(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }
        }
コード例 #4
0
 private void ShowList()
 {
     #region 协议列表
     EditorGUILayout.Space();
     scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
     EditorGUILayout.BeginVertical();
     for (int i = 0; i < Data.protocols.Count; i++)
     {
         if (IsConformToKeyword(Data.protocols[i].protocolName) || IsConformToKeyword(Data.protocols[i].xmlName))
         {
             EditorGUILayout.BeginHorizontal();
             if (GUILayout.Button("打开协议", GUILayout.Width(80)))
             {
                 OpenXMLFile(Data.protocols[i]);
             }
             if (GUILayout.Button("打开proto", GUILayout.Width(80)))
             {
                 OpenProtoFile(Data.protocols[i]);
             }
             if (GUILayout.Button("从服务器文件夹同步", GUILayout.Width(120)))
             {
                 SyncProtocol(Data.protocols[i]);
             }
             CSStringBuilder.Clear();
             CSStringBuilder.AppendParams((i + 1).ToString("d4"));
             CSStringBuilder.AppendParams(".  ");
             CSStringBuilder.AppendParams(Data.protocols[i].protocolName);
             EditorGUILayout.LabelField(CSStringBuilder.ToStringParams(), GUILayout.Width(100));
             EditorGUILayout.LabelField(Data.protocols[i].xmlName);
             Data.protocols[i].isProtocolUsedInLua = EditorGUILayout.ToggleLeft("Lua相关的协议", Data.protocols[i].isProtocolUsedInLua, GUILayout.Width(100));
             if (GUILayout.Button("移除  " + Data.protocols[i].xmlName, GUILayout.Width(120), GUILayout.ExpandWidth(true)))
             {
                 indexToBeRemoved = i;
             }
             EditorGUILayout.EndHorizontal();
         }
     }
     if (indexToBeRemoved >= 0)
     {
         Data.protocols.RemoveAt(indexToBeRemoved);
         indexToBeRemoved = -1;
     }
     EditorGUILayout.EndVertical();
     GUI.enabled = true;
     EditorGUILayout.EndScrollView();
     #endregion
 }
コード例 #5
0
 /// <summary>
 /// 打开协议对应的xml文件
 /// </summary>
 /// <param name="protocol">协议</param>
 private void OpenXMLFile(ProtocolControlCache_Protocol protocol)
 {
     if (protocol != null)
     {
         CSStringBuilder.Clear();
         CSStringBuilder.AppendParams(LocalServerProtoXMLPath);
         CSStringBuilder.AppendParams('/');
         CSStringBuilder.AppendParams(protocol.xmlName);
         CSStringBuilder.AppendParams(".xml");
         string fullPath = CSStringBuilder.ToStringParams();
         if (!File.Exists(fullPath))
         {
             UnityEngine.Debug.LogError(string.Format("{0} 文件不存在", fullPath));
             return;
         }
         Process.Start(fullPath);
     }
 }
コード例 #6
0
    /// <summary>
    /// 从xml协议中获取相关的proto文件名
    /// </summary>
    /// <param name="xmlDirPath">xml文件夹路径</param>
    /// <param name="xmlName">xml名</param>
    /// <param name="mainProto">该xml对应的proto文件名</param>
    /// <returns></returns>
    private List <string> GetRelatedProtoFromXML(string xmlDirPath, string protoDirPath, string xmlName, out string mainProto)
    {
        List <string> protoNameList = new List <string>();

        CSStringBuilder.Clear();
        CSStringBuilder.AppendParams(xmlDirPath);
        CSStringBuilder.AppendParams("/");
        CSStringBuilder.AppendParams(xmlName);
        CSStringBuilder.AppendParams(".xml");
        ProtocolControlCache_ProtocolXMLStructure xmlStructure = ServerProtocolControllerWnd.DeserializeXML(CSStringBuilder.ToStringParams());

        if (xmlStructure != null)
        {
            mainProto = xmlStructure.protoName;
            GetRelatedProtoFromProto(mainProto, protoDirPath, protoNameList);
        }
        else
        {
            mainProto = string.Empty;
        }
        return(protoNameList);
    }
コード例 #7
0
    /// <summary>
    /// 刷新相关proto
    /// </summary>
    public void RefreshProtoRelated()
    {
        if (EditorApplication.isCompiling)
        {
            UnityEngine.Debug.LogError("请等待代码编译完毕");
            return;
        }
        EditorUtility.DisplayProgressBar("刷新相关的proto文件", string.Empty, 0);
        string protoFolderPath  = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/luaRes/protobufLua/proto";
        string decodeFolderPath = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/luaRes/protobufLua/decode";
        string adjustFolderPath = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/luaRes/protobufLua/adjust";

        //将proto和proto生成的lua文件复制到对应文件夹
        EditorUtility.DisplayProgressBar("刷新相关的proto文件", "正在清空文件夹", 0.5f);
        CreateEmptyFolder(protoFolderPath);
        CreateEmptyFolder(decodeFolderPath);
        CreateEmptyFolder(adjustFolderPath);
        //proto名列表,保留了关联顺序
        List <string> protoNameList = new List <string>();

        for (int i = 0; i < Data.protocols.Count; i++)
        {
            var temp = Data.protocols[i];
            EditorUtility.DisplayProgressBar("刷新相关的proto文件", "正在解析协议文件 " + temp.xmlName + ".xml", ((float)i / Data.protocols.Count));
            string        mainProto;
            List <string> relatedProtos = GetRelatedProtoFromXML(LocalServerProtoXMLPath, LocalServerProtoPath, temp.xmlName, out mainProto);
            if (!string.IsNullOrEmpty(mainProto) && relatedProtos != null)
            {
                for (int j = 0; j < relatedProtos.Count; j++)
                {
                    if (!protoNameList.Contains(relatedProtos[j]))
                    {
                        protoNameList.Add(relatedProtos[j]);
                    }
                }
            }
        }
        EditorUtility.DisplayProgressBar("刷新相关的proto文件", "正在复制proto文件至文件夹中", 0.3f);
        //复制相关的proto文件到proto文件夹
        CopyAllFiles(protoNameList, LocalServerProtoPath, protoFolderPath, ".proto");
        //从proto文件生成lua文件
        EditorUtility.DisplayProgressBar("刷新相关的proto文件", "正在生成Decode文件(同时检查C#数据结构完整性)", 0f);
        List <string> luaGeneratedList = GenerateLuaFilesFromProto(protoNameList, protoFolderPath, decodeFolderPath, adjustFolderPath);
        //注册所有相关的proto文件到lua中
        string registerAllRelatedProtoLuaScriptPath = Application.dataPath.Substring(0, Application.dataPath.Length - 7) + "/luaRes/protobufLua/registerAllRelatedProto.lua";

        try
        {
            if (File.Exists(registerAllRelatedProtoLuaScriptPath))
            {
                File.Delete(registerAllRelatedProtoLuaScriptPath);
            }
            CSStringBuilder.Clear();
            CSStringBuilder.AppendParams("--[[本文件为工具自动生成,禁止手动修改]]\r\n");
            CSStringBuilder.AppendParams("---加载所有相关proto\r\nlocal LoadAllRelatedProto = {}\r\n\r\n---@param protobufMgr protobuf管理器\r\nfunction LoadAllRelatedProto:LoadAll(protobufMgr)\r\n");
            CSStringBuilder.AppendParams("    ---luaTable->C#数据结构转换\r\n    protobufMgr.DecodeTable = {}\r\n    ---调整luaTable\r\n    protobufMgr.AdjustTable = {}\r\n\r\n");
            for (int i = 0; i < protoNameList.Count; i++)
            {
                EditorUtility.DisplayProgressBar("刷新相关的proto文件", "正在绑定Decode文件中", (i / (float)protoNameList.Count));
                CSStringBuilder.AppendParams("    protobufMgr.RegisterPb(\"");
                CSStringBuilder.AppendParams(protoNameList[i]);
                CSStringBuilder.AppendParams(".proto\")\r\n");
                CSStringBuilder.AppendParams("    ");
                if (!luaGeneratedList.Contains(protoNameList[i]))
                {
                    //如果该proto未生成对应的lua解析文件,则不去引用该文件
                    CSStringBuilder.AppendParams("---未生成 ");
                    CSStringBuilder.AppendParams(protoNameList[i]);
                    CSStringBuilder.AppendParams(".proto 的lua=>C#文件\r\n\r\n");
                    UnityEngine.Debug.LogFormat("{0} 文件中未找到任一C#中已生成的类,故忽略该lua=>C#转换文件", protoNameList[i]);
                }
                else
                {
                    CSStringBuilder.AppendParams("protobufMgr.DecodeTable.");
                    CSStringBuilder.AppendParams(protoNameList[i]);
                    CSStringBuilder.AppendParams(" = require(\"luaRes.protobufLua.decode.");
                    CSStringBuilder.AppendParams(protoNameList[i]);
                    CSStringBuilder.AppendParams("\")\r\n    protobufMgr.AdjustTable.");
                    CSStringBuilder.AppendParams(protoNameList[i]);
                    CSStringBuilder.AppendParams("_adj = require(\"luaRes.protobufLua.adjust.");
                    CSStringBuilder.AppendParams(protoNameList[i]);
                    CSStringBuilder.AppendParams("_adj\")\r\n\r\n");
                }
            }
            CSStringBuilder.AppendParams("end\r\n\r\n");
            CSStringBuilder.AppendParams("return LoadAllRelatedProto");
            File.WriteAllText(registerAllRelatedProtoLuaScriptPath, CSStringBuilder.ToStringParams(), Encoding.UTF8);
            UnityEngine.Debug.Log("消息注册完毕");
        }
        catch (Exception ex)
        {
            UnityEngine.Debug.Log(string.Format("lua注册相关proto失败\r\n{0}\r\n{1}", ex.Message, ex.StackTrace));
        }
        finally
        {
            EditorUtility.ClearProgressBar();
        }
    }