public void LoadProto() { string allText = System.IO.File.ReadAllText(protoPath).Trim(); string patternMsgCommon = @"(//.\w+\n|)message p.\w+ \{[\s\S]*?\}"; //匹配出“p_”开头的message,包含注释 string patternMsgModel = @"(//.\w+\n|)message [^p].\w+ \{[\s\S]*?\}"; //匹配出非“p_”开头的message,包含注释 string patternModel = @"##model_begin.*##model_end##"; //收集模块 string patternCommond = @"##begin.*##end##"; //收集协议号 string patternParam = @"[^#]+"; //解析指令 List <sMessage> modelMsgList = new List <sMessage> (); foreach (Match match in Regex.Matches(allText, patternMsgCommon, RegexOptions.Multiline)) { commonMsgList.Add(sMessage.ValueOf(match.Value)); } foreach (Match match in Regex.Matches(allText, patternMsgModel, RegexOptions.Multiline)) { modelMsgList.Add(sMessage.ValueOf(match.Value)); } foreach (Match match in Regex.Matches(allText, patternModel, RegexOptions.Multiline)) { modelList.Add(sModel.ValueOf(match.Value, patternParam)); } modelList.Sort((left, right) => { return(left.CompareTo(right)); }); foreach (Match match in Regex.Matches(allText, patternCommond, RegexOptions.Multiline)) { sCommand command = sCommand.ValueOf(match.Value, patternParam); command.msg_c2s = modelMsgList.Find(a => a.nameEn.Equals(command.nameEn + "_c2s")); if (command.msg_c2s != null) { command.msg_c2s.id = "1"; command.msg_c2s.nameCn = command.nameCn; command.msg_c2s.modelId = command.modelId; command.msg_c2s.commandId = command.id; } command.msg_s2c = modelMsgList.Find(a => a.nameEn.Equals(command.nameEn + "_s2c")); if (command.msg_s2c != null) { command.msg_s2c.id = "2"; command.msg_s2c.nameCn = command.nameCn; command.msg_s2c.modelId = command.modelId; command.msg_s2c.commandId = command.id; } sModel model = modelList.Find(a => a.id == command.modelId); if (model != null) { model.AddCommand(command); } else { Debug.LogError("found modelId:" + command.modelId); } } }
public ProtoTreeViewItem(sModel model, sCommand command) { Type = eType.command; this._model = model; this._command = command; this.id = int.Parse(command.modelId) * 100 + int.Parse(command.id); this.depth = 1; this.displayName = "[" + this.id + "]" + command.nameEn; }
public ProtoTreeViewItem(sModel model, sCommand command, sMessage message) { Type = eType.message; this._model = model; this._command = command; this._message = message; this.id = int.Parse(message.modelId) * 10000 + int.Parse(message.commandId) * 100 + int.Parse(message.id); this.depth = 2; this.displayName = message.nameEn; }
public static sCommand ValueOf(string content, string pattern) { sCommand command = new sCommand(); MatchCollection matchCol = Regex.Matches(content, pattern, RegexOptions.Multiline); command.nameEn = matchCol [2].Value; command.modelId = matchCol [3].Value; command.id = matchCol [4].Value; command.nameCn = matchCol [5].Value; return(command); }
public void Export() { string formatStr_NetProtocol = "MODEL_PB = {{\n{0}}}\n"; string formatLine_NetProtocol = "\t[{0}] = \"{1}\",\n"; string formatStr_ProtocolDefine = "PROTOCOL = {{\n{0}}}\n"; string formatLine_ProtocolDefine = "\t{0} = {1},\t--{2}\n"; string cmdStr_NetProtocol = string.Empty; string cmdStr_ProtocolDefine = string.Empty; for (int i = 0; i < modelList.Count; i++) { cmdStr_ProtocolDefine += "--@brife " + modelList [i].nameCn + "\n"; for (int j = 0; j < modelList [i].cmdList.Count; j++) { sCommand command = modelList [i].cmdList [j]; int modelId = int.Parse(command.modelId); int commandId = int.Parse(command.id); int pId = modelId * 1000 + commandId; cmdStr_ProtocolDefine += string.Format(formatLine_ProtocolDefine, command.nameEn.ToUpper(), pId, command.nameCn); cmdStr_NetProtocol += string.Format(formatLine_NetProtocol, pId, command.nameEn); } cmdStr_ProtocolDefine += "\n"; } if (System.IO.File.Exists(path_ProtocolDefine)) { System.IO.File.Delete(path_ProtocolDefine); } System.IO.File.WriteAllText(path_ProtocolDefine, string.Format(formatStr_ProtocolDefine, cmdStr_ProtocolDefine).Trim()); if (System.IO.File.Exists(path_NetProtocol)) { System.IO.File.Delete(path_NetProtocol); } System.IO.File.WriteAllText(path_NetProtocol, string.Format(formatStr_NetProtocol, cmdStr_NetProtocol).Trim()); /** 编译 *.proto */ string batPath = Application.dataPath + @"\..\BuildProto\"; batPath = batPath.Replace("/", "\\"); ProcessCommand("build.bat", batPath); AssetDatabase.Refresh(); }
protected override TreeViewItem BuildRoot() { selected = -1; Clear(); LoadProto(); TreeViewItem root = new TreeViewItem() { depth = -1 }; SetupDepthsFromParentsAndChildren(root); for (int i = 0; i < modelList.Count; i++) { sModel model = modelList [i]; ProtoTreeViewItem modelItem = new ProtoTreeViewItem(model); for (int j = 0; j < model.cmdList.Count; j++) { sCommand command = model.cmdList [j]; ProtoTreeViewItem commonItem = new ProtoTreeViewItem(model, command); if (command.msg_c2s != null) { ProtoTreeViewItem c2sItem = new ProtoTreeViewItem(model, command, command.msg_c2s); commonItem.AddChild(c2sItem); itemDic [c2sItem.id] = c2sItem; } if (command.msg_s2c != null) { ProtoTreeViewItem s2cItem = new ProtoTreeViewItem(model, command, command.msg_s2c); commonItem.AddChild(s2cItem); itemDic [s2cItem.id] = s2cItem; } modelItem.AddChild(commonItem); itemDic [commonItem.id] = commonItem; } root.AddChild(modelItem); itemDic [modelItem.id] = modelItem; } SetupDepthsFromParentsAndChildren(root); return(root); }
public void AddCommand(sCommand command) { cmdList.Add(command); }