public ServerProtocolListTool(ServerProtocolControllerWnd wnd) { Instance = this; indexToBeRemoved = -1; scrollPos = Vector2.zero; Load(); }
/// <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); } }
/// <summary> /// 向数据中添加协议和其对应的xml /// </summary> /// <param name="protocolName"></param> /// <param name="xmlName"></param> private bool AddProtocolToData(string protocolName, string xmlName, bool isUsedInLua) { if (Data.GetProtocolByProtocolName(protocolName) != null) { UnityEngine.Debug.LogError(string.Format("协议名冲突: {0}", protocolName)); return(false); } else if (Data.GetProtocolByXMLName(xmlName) != null) { UnityEngine.Debug.LogError(string.Format("XML冲突: {0}", xmlName)); return(false); } string xmlFullPath = RealServerProtoXMLPath + "/" + xmlName + ".xml"; if (File.Exists(xmlFullPath)) { ProtocolControlCache_ProtocolXMLStructure xmlStructure = ServerProtocolControllerWnd.DeserializeXML(xmlFullPath); if (xmlStructure == null) { UnityEngine.Debug.LogError(string.Format("XML文件格式解析失败\r\n{0}", xmlFullPath)); return(false); } } else { UnityEngine.Debug.LogError(string.Format("XML文件不存在\r\n{0}", xmlFullPath)); return(false); } Data.protocols.Add(new ProtocolControlCache_Protocol(protocolName, xmlName, isUsedInLua)); UnityEngine.Debug.Log(string.Format("{0} 协议添加成功 {1}", protocolName, xmlName)); return(true); }
protected override void InitToolDic() { Initialize(); _ProtocolController = this; AddToolBar("服务器协议", new ServerProtocolListTool(this)); AddToolBar("Lua相关服务器消息", new ServerProtocolLuaMessage(this)); }
/// <summary> /// 消息中是否有某个字段的类型不存在 /// </summary> /// <param name="message"></param> /// <returns></returns> public static bool IsAnyFieldNotExistInMessage(ProtocolControlCache_Message message) { if (!message.hasProto || message.protoData == null) { //未使用proto结构时返回false return(false); } ProtocolControlCache_ProtoStructure.Message messageStructure = ServerProtocolControllerWnd.GetMessageStructure(message); return(IsAnyFieldNotExistInMessageInternal(messageStructure, null)); }
/// <summary> /// 处理数据,将proto名和message分割开 /// </summary> public void DealData() { if (string.IsNullOrEmpty(name) == false) { string[] strs = name.Split('.'); if (strs != null && strs.Length >= 2) { protoName = strs[strs.Length - 2]; protoMsgName = strs[strs.Length - 1]; protoName = protoName.ToLower(); if (protoName.Contains("proto")) { protoName = protoName.Substring(0, protoName.IndexOf("proto")); } protoName = ServerProtocolControllerWnd.FormatProtoName(protoName); } } }
/// <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); }
public static void OpenDataTool() { _ProtocolController = EditorWindow.GetWindow <ServerProtocolControllerWnd>("服务器消息协议控制"); _ProtocolController.Show(); }