/// <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); }
/// <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); }