码迷,mamicode.com
首页 > 编程语言 > 详细

Unity编辑器调用外部exe程序

时间:2021-01-05 11:22:10      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:code   generic   win   nbsp   sys   output   gen   card   eric   

直接来,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();
    }
}

 

参考资料:

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

Unity编辑器调用外部exe程序

标签:code   generic   win   nbsp   sys   output   gen   card   eric   

原文地址:https://www.cnblogs.com/sanyejun/p/14221085.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!