Unity3D若何挪用外部的exe文件呢?若何傳遞多個參數到exe呢?。簡單幾步,讓你輕松解決。
 1. 打開Unity3D軟件,新建工程如下圖所示
 2. 建立Scene場景如下圖所示,雙擊劇本,打開該劇本。
 
 3. 籌辦一個exe文件如下圖所示(用于被挪用執行,此中需要傳入的參數有三個),并將文件夾拖拽到【Project】面板下,如下圖所示
 
 4. 在【RunExeFileTest】劇本中輸入下面代碼。并將該劇本拖拽到MainCamera對象下。
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEngine;
public class RunExeFileTest : MonoBehaviour {
// Use this for initialization
void Start () {
string s = Application.dataPath + "/SeamlessCloneTest/";
string exeFilePath = s + "SeamlessCloneTest.exe";
//設置參數-多參數利用空格鍵進行分隔
string param0 = s + "xiangjiao_ori.jpg";
string param1 = s + "xiangjiao_ori_bg.jpg";
string param2 = s + "xiangjiao.jpg";
try
{
Process process = new Process();
process.StartInfo.FileName = exeFilePath;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.Arguments = param0 + " "+ param1+ " "+ param2;
process.EnableRaisingEvents = true;
process.Start();
process.WaitForExit();
UnityEngine.Debug.Log("exe已經運行封閉了");
int ExitCode = process.ExitCode;
//print(ExitCode);
}
catch (Exception e)
{
print(e);
}
}
}
 5. 點擊軟件的運行按鈕后,執行了exe文件,其計較顯示成果如下圖所示,且Unity3D線程工作期待狀況,節制臺無輸出。
 6. 步調5中,在exe彈出的噴鼻蕉圖片窗口中,點擊肆意鍵(空格鍵亦可)會封閉該窗口,后會進入到Unity的線程,而且節制臺輸出動靜如下圖所示。工程源碼見注重事項。
 若是您感覺有效,記得鄙人方點擊投票、點贊、存眷、留言,小編會按期奉上更多的驚喜哦,您的撐持才是小編繼續盡力的動力,么么噠。
0 篇文章
如果覺得我的文章對您有用,請隨意打賞。你的支持將鼓勵我繼續創作!