/// <summary> /// 生成CS下的Message.cs文件 /// </summary> /// <param name="csMessages"></param> /// <param name="funMap"></param> private static void CreateMessage(CMessages msg, string path) { foreach (var message in msg.messages) { if (message.name != "") { FileStream fs = new FileStream(path + @"\" + message.name + "Message.cs", FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); string tempPath = @".\Templates\CS\" + Global.CsMessageTemplatePath.Substring( Global.CsMessageTemplatePath.LastIndexOf(@"\") + 1); Template temp = CNVelociryHelp.GetTemplate(tempPath); VelocityContext vltCtx = new VelocityContext(); string importString = ""; vltCtx.Put("MessageExplain", message.explain); vltCtx.Put("MessageName", message.name + "Message"); vltCtx.Put("MessageID", msg.ID + message.ID); if (message.lists != null && message.lists.Length > 0) { vltCtx.Put("Length", "int length=0;"); } else { vltCtx.Put("Length", ""); } List <string> usList = new List <string>(); if (message.lists != null && message.lists.Length > 0) { usList.Add("using System.Collections.Generic;"); } if (message.items != null && message.items.Count > 0) { List <CMessageFieldAndList> list = new List <CMessageFieldAndList>(); foreach (var item in message.items) { if (item != null) { CMessageFieldAndList fl = new CMessageFieldAndList(item); if (Global.IsCustomType(fl.className) && fl.isPrefix == "0" && importString == "") { importString = msg.import; } list.Add(fl); if (item.classType == "Position") { usList.Add("using com.game.structs;"); } } } vltCtx.Put("flList", list); } vltCtx.Put("usList", usList); vltCtx.Put("ImportString", importString); System.IO.StringWriter vltWriter = new System.IO.StringWriter(); temp.Merge(vltCtx, vltWriter); sw.Write(vltWriter.ToString()); sw.Close(); fs.Close(); Debug.Log(message.name + "Message.cs生成成功"); } else { Debug.Log("Message文件名称为空", 3); } } }
/// <summary> /// 生成CS下的Bean文件 /// </summary> /// <param name="csMessages"></param> /// <param name="funMap"></param> /// <param name="label1"></param> private static void CreateBeans(CMessages msg, string path) { //Thread myThread=new Thread(new ThreadStart(CreateBeanThread(msg,path,LogText))); foreach (var bean in msg.beans) { if (bean.name != "") { Template temp = CNVelociryHelp.GetTemplate(@".\Templates\CS\" + Global.CsBeanTemplatePath.Substring(Global.CsBeanTemplatePath.LastIndexOf(@"\"))); VelocityContext vltCtx = new VelocityContext(); vltCtx.Put("ImportString", msg.import); vltCtx.Put("BeanExplain", bean.explain); vltCtx.Put("BeanName", bean.name); //if (bean.fileds != null && bean.fileds.Length > 0) //{ // List<BeanVar> beanVarList = new List<BeanVar>(); // //List<CField> beanWriteList = new List<CField>(); // foreach (var field in bean.fileds) // { // BeanVar var = new BeanVar(field); // beanVarList.Add(var); // } // vltCtx.Put("fieldList", beanVarList); //} //if (bean.lists != null && bean.lists.Length > 0) //{ // List<BeanVar> beanVarList = new List<BeanVar>(); // foreach (var list in bean.lists) // { // BeanVar var = new BeanVar(list); // beanVarList.Add(var); // } // vltCtx.Put("listList", beanVarList); //} List <string> usList = new List <string>(); if (bean.lists != null && bean.lists.Length > 0) { usList.Add("using System.Collections.Generic;"); } vltCtx.Put("usList", usList); if (bean.items != null && bean.items.Count > 0) { List <CMessageFieldAndList> list = new List <CMessageFieldAndList>(); foreach (var item in bean.items) { if (item != null) { CMessageFieldAndList fl = new CMessageFieldAndList(item); list.Add(fl); } } vltCtx.Put("flList", list); } System.IO.StringWriter vltWriter = new System.IO.StringWriter(); temp.Merge(vltCtx, vltWriter); FileStream fs = new FileStream(path + @"\" + bean.name + ".cs", FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.Write(vltWriter.ToString()); sw.Close(); fs.Close(); Debug.Log(bean.name + ".cs生成成功"); } else { Debug.Log("Bean名称为空,不能生成文件", 3); } } }