Unity编辑器调用外部exe程序 和 windows文件夹

直接来,1个脚本

复制代码
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEditor;
using Debug = UnityEngine.Debug;

public class Excel2LuaEditor : EditorWindow
{
    [MenuItem("工具/生成Lua Card")]
    static void GenLuaCard()
    {
        Debug.Log("生成卡牌 Lua");
        ProcessCommand(@"D:\UnitySSDProject\GameTRPG\GameTRPG\工具\Excel2Lua\Excel2Lua\Lua生成器\cardexe\bin\Excel2Lua.exe", null);
    }
    
    [MenuItem("工具/生成Lua Buff")]
    static void GenLuaBuff()
    {
        Debug.Log("生成Buff Lua");
        ProcessCommand(@"D:\UnitySSDProject\GameTRPG\GameTRPG\工具\Excel2Lua\Excel2Lua\Lua生成器\buffexe\bin\Excel2Lua.exe", null);
    }
    
    
    
    private static void ProcessCommand(string command, string argument){
        ProcessStartInfo start = new ProcessStartInfo(command);
        start.Arguments = argument;
        start.CreateNoWindow = false;
        start.ErrorDialog = true;
        start.UseShellExecute = true;
 
        if(start.UseShellExecute){
            start.RedirectStandardOutput = false;
            start.RedirectStandardError = false;
            start.RedirectStandardInput = false;
        } else{
            start.RedirectStandardOutput = true;
            start.RedirectStandardError = true;
            start.RedirectStandardInput = true;
            start.StandardOutputEncoding = System.Text.UTF8Encoding.UTF8;
            start.StandardErrorEncoding = System.Text.UTF8Encoding.UTF8;
        }
 
        Process p = Process.Start(start);
 
        if(!start.UseShellExecute){
            Debug.Log(p.StandardOutput);
            Debug.Log(p.StandardError);
        }
 
        p.WaitForExit();
        p.Close();
    }
}
复制代码

 

打开文件夹

    [MenuItem("工具/打开Excel文件夹")]
    static void OpenFolder()
    {
        string path = @"D:\UnitySSDProject\GameTRPG\GameTRPG\Assets\StreamingAssets\Excel\COC7th";
        System.Diagnostics.Process.Start("explorer.exe", path);
    }

 

 

参考资料:

https://www.jianshu.com/p/3f4120a7c7f6

posted @   三页菌  阅读(880)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示