proto轉lua表

EErrorCode.proto

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章