public static Dictionary <uint, T> GetCfgData <T, TArray>(string cfgName) { string cfgMapPath = CSEditorPath.Get(EEditorPath.LocalResourcesLoadPath) + "Table/" + cfgName + ".bytes"; Dictionary <uint, T> dic = new Dictionary <uint, T>(); TArray list = default(TArray); byte[] cfgData = File.ReadAllBytes(cfgMapPath); using (MemoryStream stream = new MemoryStream(cfgData)) { list = ProtoBuf.Serializer.Deserialize <TArray>(stream); } if (list == null) { return(dic); } Type arrayType = list.GetType(); //foreach (var cur in list.rows) //{ // if (!dic.ContainsKey(cur.id)) // { // dic.Add(cur.id, cur); // } //} return(dic); }
public ProtobufParseTool() { ParseFolderList.Clear(); ParseFolderList.Add(new CSProtobufParseFolder(CSEditorPath.Get(EEditorPath.LocalTableProtoPath), CSEditorPath.Get(EEditorPath.LocalTableProtoClassPath), EProtobufParseFolderType.Table)); ParseFolderList.Add(new CSProtobufParseFolder(CSEditorPath.Get(EEditorPath.LocalServerProtoPath), CSEditorPath.Get(EEditorPath.LocalServerProtoClassPath), EProtobufParseFolderType.Server)); }
public void ParseXMLToRsp(string fileUrl, string outPath, bool isOpenFile, bool isSingleFile = false) { CSProtoFileData.ParseProtoFile(CSEditorPath.Get(EEditorPath.LocalServerProtoPath) + "activity.proto"); return; outXMLDefineContent = string.Empty; FileUtilityEditor.DetectCreateDirectory(outPath); FileInfo file = new FileInfo(fileUrl); XmlNode doc = XmlEditorUtil.LoadXml(fileUrl); XmlNode messageNode = XmlEditorUtil.ReadXml(doc, "messages"); if (messageNode == null) { messageNode = XmlEditorUtil.ReadXml(doc, "message"); } if (messageNode == null) { UnityEngine.Debug.LogError("无法解析xml,没有messages 节点 = " + fileUrl); return; } XmlElement mElement = messageNode as XmlElement; int groupID = System.Convert.ToInt32(mElement.GetAttribute("id").ToString()); //该XML文件生成的枚举文本 string msgDefine = string.Empty; XmlNodeList nList = messageNode.ChildNodes; foreach (var node in nList) { XmlElement e = node as XmlElement; if (e == null) { UnityEngine.Debug.Log("XmlElement is null = " + fileUrl + " " + node.ToString()); continue; } if (!e.HasAttribute("id")) { continue; } int id = System.Convert.ToInt32(e.GetAttribute("id").ToString()); int msgId = groupID * 1000 + id; string enumName = e.GetAttribute("class").ToString(); string desc = e.GetAttribute("desc").ToString(); bool toClient = e.GetAttribute("type").ToString() == "toClient"; //增加一行枚举定义 AddInfo_MsgDefine(enumName, msgId, desc, ref msgDefine); XmlElement protoNode = XmlEditorUtil.ReadXml(e, "proto") as XmlElement; //if (protoNode != null)//没有任何内容需要解析,这个消息只是一个空的消息 //{ // if (!toClient)//如果不是从服务器返回的消息(即客户端发送的服务器的消息) // { // AddInfo_ReqString(enumName,) // } //} //else //{ // string protoClass = protoNode.GetAttribute("name").ToString(); // string patten = "com.sh.game.proto.(\\S+)\\."; // MatchCollection mc = Regex.Matches(protoClass, patten); // if (mc.Count > 0) // { // protoClass = protoClass.Substring(protoClass.LastIndexOf(".") + 1); // string java_outer_classname = mc[0].Groups[1].ToString(); // Dictionary<string, CSProtoMessageData> protoDic = GetProtoDic(java_outer_classname); // if (protoDic != null) // { // if (protoDic.ContainsKey(protoClass)) // { // CSProtoMessageData data = protoDic[protoClass]; // AddInfo(toClient, enumName, desc, msgId, data, ref rspString, ref rspFuncString, ref reqString, ref msgDefine, ref netMsgString); // } // else // { // //UnityEngine.Debug.LogError(protoClass + " is not in protoDic"); // AddInfo(toClient, enumName, desc, msgId, null, ref rspString, ref rspFuncString, ref reqString, ref msgDefine, ref netMsgString); // } // } // } //} } ParseToESocketEventEnum(OutFolder, file.Name, groupID, msgDefine, ref outXMLDefineContent); AssetDatabase.Refresh(); }