EErrorCode.lua
using System;
using UnityEditor;
using UnityEngine;
using System;
using System.IO;
using System.Linq;
using System.Text;
public class TurnProtoToLua
{
[MenuItem("proto转Lua表")]
public static void ChangeProtoToLua(){
string protoPath = "协议路径(协议名字.proto)" ;
string Info = "";
if (File.Exists(protoPath)){//是否存在此文件
try {
StreamReader sr = File.OpenText(protoPath);//打开文件
string luaInfo="";
while( (luaInfo= sr.ReadLine())!=null){ //此行是否为空。为空换行显示
if (luaInfo.Contains("表名")){ Info += "表名 = {}";}//表名
else if (luaInfo.Contains("LL_")){
luaInfo = luaInfo.Trim();//Trim函数是去除读到的字符串中开头结尾的空格
Info += "表名[";
int index1=luaInfo.IndexOf("=");
luaInfo=luaInfo.Remove(0,index1+1);
luaInfo=luaInfo.Trim();
int index2=luaInfo.IndexOf(";");
Info += luaInfo.Substring(0, index2);
Info += "]=\"";
int index3=luaInfo.IndexOf("//");
luaInfo=luaInfo.Remove(0,index3+2);
luaInfo=luaInfo.Trim();
Info += luaInfo + "\"";
}
Info += "\n";
}
Info += "}";
string strPath = Application.dataPath + "生成lua表的路径(.lua)";
FileUtils.SaveStringFile(strPath, Info);//保存
sr.Dispose ();
} catch (Exception e) {Debug.Log ("转表失败 " + e); }
} else { Debug.Log("不存在此路径" + protoPath);}
}
}
using UnityEditor;
using UnityEngine;
using System;
using System.IO;
using System.Linq;
using System.Text;
public class TurnProtoToLua
{
[MenuItem("proto转Lua表")]
public static void ChangeProtoToLua(){
string protoPath = "协议路径(协议名字.proto)" ;
string Info = "";
if (File.Exists(protoPath)){//是否存在此文件
try {
StreamReader sr = File.OpenText(protoPath);//打开文件
string luaInfo="";
while( (luaInfo= sr.ReadLine())!=null){ //此行是否为空。为空换行显示
if (luaInfo.Contains("表名")){ Info += "表名 = {}";}//表名
else if (luaInfo.Contains("LL_")){
luaInfo = luaInfo.Trim();//Trim函数是去除读到的字符串中开头结尾的空格
Info += "表名[";
int index1=luaInfo.IndexOf("=");
luaInfo=luaInfo.Remove(0,index1+1);
luaInfo=luaInfo.Trim();
int index2=luaInfo.IndexOf(";");
Info += luaInfo.Substring(0, index2);
Info += "]=\"";
int index3=luaInfo.IndexOf("//");
luaInfo=luaInfo.Remove(0,index3+2);
luaInfo=luaInfo.Trim();
Info += luaInfo + "\"";
}
Info += "\n";
}
Info += "}";
string strPath = Application.dataPath + "生成lua表的路径(.lua)";
FileUtils.SaveStringFile(strPath, Info);//保存
sr.Dispose ();
} catch (Exception e) {Debug.Log ("转表失败 " + e); }
} else { Debug.Log("不存在此路径" + protoPath);}
}
}