我們可以在unity中調(diào)用自己寫的或者別的軟件現(xiàn)成的dll或者exe來做一些事。
例如用7z來壓縮或者解壓文件。
直接上代碼
public class ExcuteCMD
{
//把命令行參數(shù)傳入
public static void DoCMD(string command)
{
using (Process p = new Process())
{
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
//"/c" 代表執(zhí)行接下來指定的命令,執(zhí)行完后停止,會退出。例如:
//了解更多cmd參數(shù)請進(jìn)https://www.cnblogs.com/mq0036/p/5244892.html
p.StartInfo.Arguments = "/c " + command;
//開始進(jìn)程
p.Start();
//如果10秒后還沒執(zhí)行完成,那么結(jié)束這個(gè)進(jìn)程
p.WaitForExit(10000);
//輸出進(jìn)程輸出的內(nèi)容
Debug.Log(p.StandardOutput.ReadToEnd());
}
}
}
public class DeleteBuildConfig
{
[MenuItem("Tools/刪除BuildConfig")]
private static void Excute()
{
//定義操作根目錄
string rootPath = Application.dataPath + "/Plugins/Android/libs/";
//定義輸出目錄
string outPath = rootPath + "test";
//定義壓縮文件路徑
string filePath = rootPath + "test.jar";
//定義7z提供的exe
string exePath = "\"D:/Softwares/Program Files/7-Zip/7z.exe\" ";
//解壓命令
string unZipStr = exePath + "x -o" + outPath + " " + filePath;
//解壓
ExcuteCMD.DoCMD(unZipStr);
//刪除原壓縮文件,
File.Delete(filePath);
//刪除BuildConfig文件
string buildConfigPath = outPath + "/com/zjlbest/SDK_Demo/BuildConfig.class";
if (File.Exists(buildConfigPath))
{
File.Delete(buildConfigPath);
//壓縮命令
string zipStr = exePath + "a " + filePath + " " + outPath + "/com/";
//壓縮
ExcuteCMD.DoCMD(zipStr);
}
//刪除輸出目錄
Directory.Delete(outPath, true);
//刷新游戲
AssetDatabase.Refresh();
}
}
以上就是一個(gè)簡單的案例