CmdTools必须在Editor文件夹内
打开CMD,输入以下命令
"C:\Program Files\Unity2018.4.16f1\Editor\Unity.exe" -projectPath "E:\Demo\CMDTest" -executeMethod CMD.CmdTools.CallByCmd GetCommandLineArgs 你好 132456 abcdefa
代码
using System;
using System.Diagnostics;
using UnityEditor;
using UnityEngine;
using Debug = UnityEngine.Debug;
namespace CMD
{
public class CmdTools : Editor
{
/// 外部命令行调起来
/// </summary>
public static void CallByCmd()
{
//得到命令行传入的参数
string[] arguments = Environment.GetCommandLineArgs();
Debug.LogError("参数数量:" + arguments.Length);
Process.Start(Application.dataPath);
}
}
}
![](https://img.haomeiwen.com/i2020966/89ecb0de5f3e3bb1.png)
参考:
https://docs.unity3d.com/Manual/CommandLineArguments.html
https://docs.unity3d.com/Manual/PlayerCommandLineArguments.html
网友评论