public bool WriteCSharpFile() { //Write using (FileStream fs = new FileStream(m_strOutputFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, new System.Text.UTF8Encoding(false))) { sw.WriteLine("///////////////////////////////"); sw.WriteLine("// Generate By UnityEditor //"); sw.WriteLine("///////////////////////////////"); sw.WriteLine(); sw.WriteLine(); sw.WriteLine("using ETModel;"); sw.WriteLine(); sw.WriteLine("namespace Magic.Cougar"); sw.WriteLine("{"); sw.WriteLine("////////////////////MessageNum2Class////////////////////"); Dictionary <uint, string> dctTypeToMsg = m_reader.GetTypeToExcludeLuaMsg(); foreach (var v in dctTypeToMsg) { string msgName = v.Value; int index = msgName.IndexOf('.'); if (index != -1) { msgName = msgName.Substring(index + 1); } sw.WriteLine("[Message((ushort)MessageType.{0})]", msgName); sw.WriteLine(StringUtility.ConcatString(" public partial class ", msgName, " { }")); } sw.WriteLine("////////////////////MessageNum2Class////////////////////"); sw.WriteLine("}"); sw.WriteLine(); } } return(true); }
public bool WriteCSharpFile() { //Write using (FileStream fs = new FileStream(m_strOutputFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, new System.Text.UTF8Encoding(false))) { sw.WriteLine("///////////////////////////////"); sw.WriteLine("// Generate By UnityEditor //"); sw.WriteLine("///////////////////////////////"); sw.WriteLine(); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine(); sw.WriteLine("namespace Magic.Cougar"); sw.WriteLine("{"); sw.WriteLine(" public enum MessageType : ushort"); sw.WriteLine(" {"); sw.WriteLine("////////////////////Custom MessageDefine////////////////////"); Dictionary <uint, string> dctCustomMsg = m_reader.GetCustomMsgType(); foreach (var v in dctCustomMsg) { sw.WriteLine(" {0} = {1},", v.Value, v.Key); } sw.WriteLine("////////////////////Custom MessageDefine////////////////////"); sw.WriteLine(); sw.WriteLine(); sw.WriteLine("////////////////////Proto MessageDefine////////////////////"); Dictionary <uint, string> dctTypeToMsg = m_reader.GetTypeToExcludeLuaMsg(); foreach (var v in dctTypeToMsg) { string msgName = v.Value; int index = msgName.IndexOf('.'); if (index != -1) { msgName = msgName.Substring(index + 1); } sw.WriteLine(" {0} = {1},", msgName, v.Key); } sw.WriteLine("////////////////////Proto MessageDefine////////////////////"); sw.WriteLine(" }"); sw.WriteLine("}"); sw.WriteLine(); sw.WriteLine(); } } return(true); }
private void GenCSProtoHandle() { //Write string strOutFile = Path.GetFullPath(m_strOutputPath + "/" + "PartialProtoMsgHandler.cs"); using (FileStream fs = new FileStream(strOutFile, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(fs, new System.Text.UTF8Encoding(false))) { sw.WriteLine("///////////////////////////////"); sw.WriteLine("// Generate By UnityEditor //"); sw.WriteLine("// PartialProtoMsgHandler.cs //"); sw.WriteLine("///////////////////////////////"); sw.WriteLine(); sw.WriteLine(); sw.WriteLine("using System;"); sw.WriteLine("using ProtoBuf;"); sw.WriteLine("using Magic.Cougar;"); sw.WriteLine(); sw.WriteLine("namespace Magic.GameLogic"); sw.WriteLine("{"); sw.WriteLine(" public partial class ProtoMsgHandler"); sw.WriteLine(" {"); sw.WriteLine(" private void PushToLua(IntPtr L, ushort uType, IExtensible msg, Action<IntPtr, ushort> beforAction, Action<IntPtr> afterAction)"); sw.WriteLine(" {"); sw.WriteLine(); sw.WriteLine(" switch ((MessageType)uType)"); sw.WriteLine(" {"); Dictionary <uint, string> dctTypeToMsg = m_reader.GetTypeToExcludeLuaMsg(); foreach (var v in dctTypeToMsg) { string msgType = v.Value; int nIndex = v.Value.IndexOf('.'); if (nIndex != -1) { msgType = v.Value.Substring(nIndex + 1); } sw.WriteLine(" case MessageType.{0}:", msgType); sw.WriteLine(" {"); sw.WriteLine(" var cmsg = msg as {0};", v.Value); sw.WriteLine(" if (cmsg != null)"); sw.WriteLine(" {"); sw.WriteLine(" if(beforAction != null && afterAction != null)"); sw.WriteLine(" {"); sw.WriteLine(" beforAction.Invoke(L, uType);"); sw.WriteLine(" cmsg.PushToLua(this.m_luaEnv.L);"); sw.WriteLine(" afterAction.Invoke(L);"); sw.WriteLine(" }"); sw.WriteLine(" }"); sw.WriteLine(" }"); sw.WriteLine(" break;"); } sw.WriteLine(" default:"); sw.WriteLine(" break;"); sw.WriteLine(" }"); sw.WriteLine(" }"); sw.WriteLine(" }"); sw.WriteLine("}"); } } }