美文网首页
CMD命令启动unity并调用类和函数,执行代码逻辑

CMD命令启动unity并调用类和函数,执行代码逻辑

作者: 好怕怕 | 来源:发表于2023-03-29 16:03 被阅读0次

    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);
            }
        }
    }
    
    
    image.png

    参考:
    https://docs.unity3d.com/Manual/CommandLineArguments.html
    https://docs.unity3d.com/Manual/PlayerCommandLineArguments.html

    相关文章

      网友评论

          本文标题:CMD命令启动unity并调用类和函数,执行代码逻辑

          本文链接:https://www.haomeiwen.com/subject/duvfddtx.html