準(zhǔn)備的工具:luac.exe?CSDNhttps://mp.csdn.net/mp_download/manage/download/UpDetailed文章來源:http://www.zghlxwxcb.cn/news/detail-665850.html
Unity版:文章來源地址http://www.zghlxwxcb.cn/news/detail-665850.html
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
public static class Batch_LuaToLuac
{
[UnityEditor.MenuItem("Tools/LuaToLuac")]
static void ToLuac()
{
//準(zhǔn)備進(jìn)程信息
string luacExe = "luac53.exe"; //luac.exe工具文件名
string luacExe_Dir = @"D:\workspace\Test\T4\PureProject_Develop\Development2020\Tools\Lua"; //luac.exe工具路徑
string luacExe_fullpath = Path.Combine(luacExe_Dir, luacExe); //luac.exe工具完整路徑
var processStartInfo = new System.Diagnostics.ProcessStartInfo();
processStartInfo.FileName = luacExe_fullpath;
processStartInfo.UseShellExecute = true;
processStartInfo.ErrorDialog = true;
processStartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
void DoExe(string srcFile, string outFile)
{
//執(zhí)行轉(zhuǎn)換進(jìn)程
try
{
string args = string.Format("-o {0} {1}", outFile, srcFile);
processStartInfo.Arguments = args;
var process = System.Diagnostics.Process.Start(processStartInfo);
process.WaitForExit();
}
catch (Exception ex)
{
Debug.LogError(ex.ToString());
}
}
//lua源文件路徑
var luaFileDir = Application.dataPath + "/LuaSource";
//生成的luac文件路徑
var outPutDir = Path.Combine(luaFileDir, "luac");
if (Directory.Exists(outPutDir)) Directory.Delete(outPutDir, true);
Directory.CreateDirectory(outPutDir);
var files = Directory.GetFiles(luaFileDir, "*.lua", SearchOption.TopDirectoryOnly);
foreach (var file in files)
{
if (file.Contains(".meta")) { continue; }
var outFile = Path.Combine(outPutDir, Path.GetFileNameWithoutExtension(file) + ".luac");
DoExe(file, outFile);
}
AssetDatabase.Refresh();
}
}
到了這里,關(guān)于Lua之Lua源文件批量轉(zhuǎn)換為luac字節(jié)碼文件的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!