string InsertContent(string path, string beginFlag, string endFlag, string insertStr, ref int allEndIndex) { if (!File.Exists(path)) { allEndIndex = -1; return(insertStr); } string content = FileUtilityEditor.ReadToEnd(path); int bIndex = content.IndexOf(beginFlag); int eIndex = content.IndexOf(endFlag); allEndIndex = content.IndexOf("//End"); if (bIndex == -1 || eIndex == -1) { if (allEndIndex == -1) { return(insertStr); } return(content.Insert(allEndIndex, insertStr + "\r\n\r\n")); } eIndex = eIndex + content.Substring(eIndex).IndexOf("\r\n\r\n"); if (eIndex == -1) { return(insertStr); } return(content.Substring(0, bIndex) + insertStr + content.Substring(eIndex + 4)); }
//public string java_package; //public string java_outer_classname; //public string namespaceStr;//package task; public static List <CSProtoMessageData> ParseProtoFile(string file) { List <CSProtoMessageData> list = new List <CSProtoMessageData>(); string fileContent = FileUtilityEditor.ReadToEnd(file); //匹配出 //message VeinBean { // required int32 newId = 1;//现在的配置表id // optional int32 fightValue = 2;//战斗力 //} MatchCollection matchs = null; matchs = Regex.Matches(fileContent, pattern); if (matchs != null && matchs.Count > 0) { for (int i = 0; i < matchs.Count; i++) { CSProtoMessageData data = new CSProtoMessageData(matchs[i].Groups[0].Value); list.Add(data); break; } } return(list); }
private void OnGUI_ServerProtoXML_C() { GUILayout.BeginHorizontal(); { GUILayout.Label("搜索:", GUILayout.Width(40)); SerachTxt = EditorGUILayout.TextField(SerachTxt, GUILayout.Width(300)); if (GUILayout.Button("刷新", GUILayout.Width(80))) { ProtobufXMLParseFolder.RefushFolder(); } GUILayout.Space(10); if (GUILayout.Button("生成", GUILayout.Width(80))) { } GUILayout.Space(10); if (GUILayout.Button("打开", GUILayout.Width(80))) { FileUtilityEditor.Open(ProtobufXMLParseFolder.OrigionFolder); } } GUILayout.EndHorizontal(); ProtobufXMLParseFolder.ShowFolderFileList(SerachTxt); }
void AddToTemplate(string outpath, string templatePath) { string templateContent = File.ReadAllText(templatePath); string content = File.ReadAllText(outpath); content = string.Format(templateContent, content, OutFolder); FileUtilityEditor.Write(outpath, content, false); }
public void OnGUI() { if (GUILayout.Button("打开工程")) { FileUtilityEditor.Open(URL.LocalProjectPath); } if (GUILayout.Button("打开工程缓存配置文件夹")) { FileUtilityEditor.Open(URL.LocalProjectPath + "/ProjectCaches"); } }
private void OnGUICommon() { #region 路径显示 EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(string.Format("服务器XML文件夹路径"), GUILayout.Width(200)); if (GUILayout.Button("打开文件夹", GUILayout.Width(100))) { FileUtilityEditor.Open(RealServerProtoXMLPath); } EditorGUILayout.LabelField(RealServerProtoXMLPath); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(string.Format("服务器proto文件夹路径"), GUILayout.Width(200)); if (GUILayout.Button("打开文件夹", GUILayout.Width(100))) { FileUtilityEditor.Open(RealServerProtoPath); } EditorGUILayout.LabelField(RealServerProtoPath); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(string.Format("本地proto文件夹路径"), GUILayout.Width(200)); if (GUILayout.Button("打开文件夹", GUILayout.Width(100))) { FileUtilityEditor.Open(LocalServerProtoPath); } EditorGUILayout.LabelField(LocalServerProtoPath); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(string.Format("本地xml文件夹路径"), GUILayout.Width(200)); if (GUILayout.Button("打开文件夹", GUILayout.Width(100))) { FileUtilityEditor.Open(LocalServerProtoXMLPath); } EditorGUILayout.LabelField(LocalServerProtoXMLPath); EditorGUILayout.EndHorizontal(); #endregion #region 钮 EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("数据操作:", GUILayout.Width(60)); if (GUILayout.Button("保存数据", GUILayout.Width(100))) { Save(); } if (GUILayout.Button("一键提交", GUILayout.Width(100))) { } EditorGUILayout.EndHorizontal(); #endregion }
/// <summary> /// 将内容枚举内容写入生成文件中 /// </summary> /// <param name="outFolder">生成文件存放路径</param> /// <param name="name">写入内容的xml文件名字</param> /// <param name="id">写入内容的xml所以功能ID</param> /// <param name="content">写入的枚举内容</param> /// <param name="fileContent">文本内容</param> /// <param name="IsWrite">是否直接写入文件,当批量增加xml的时候,反复的写入会造成大量的开销</param> private void ParseToESocketEventEnum(string outFolder, string name, int id, string content, ref string fileContent, bool IsWrite = true) { string outFile = outFolder + "ESocketEvent.cs"; if (string.IsNullOrEmpty(fileContent)) { fileContent = FileUtilityEditor.ReadToEnd(outFile); } if (string.IsNullOrEmpty(fileContent)) { string defaultContext = "/// <summary>\r\n/// 网络事件\r\n/// </summary>\r\npublic enum ESocketEvent\r\n{\r\n}"; FileUtilityEditor.Write(outFile, defaultContext, false); fileContent = defaultContext; } string startFlag = GetServerProtoEnumStart(name, id); string endFlag = GetServerProtoEnumEnd(name, id); pattern = startFlag + "([\\s\\S]*)" + endFlag; content = startFlag + content + endFlag; matchs = Regex.Matches(fileContent, pattern); if (matchs != null && matchs.Count > 0) { string enumContent = matchs[0].Groups[0].Value; fileContent = fileContent.Replace(enumContent, content); } else//沒有找到之前的生成内容,说明这个xml是新加入的,那么插入到最下面 { pattern = "public enum ESocketEvent\r\n{([^}]+)}"; matchs = Regex.Matches(fileContent, pattern); //拿到之前的ESocketEvent枚举内所有内容 if (matchs != null && matchs.Count > 0) { string enumContent = matchs[0].Groups[0].Value; content = enumContent.Insert(enumContent.Length - 1, "\r\n" + content); fileContent = fileContent.Replace(enumContent, content); } } if (IsWrite) { FileUtilityEditor.Write(outFile, fileContent, false); } }
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(); }