命令行给unity传参

windows命令行与sh语法区别很大,注意下

.bat脚本

@echo on

set UNITY3D_PROJECT_PATH=d:happyGitstareditor

set UNITY3D_BUILD_METHOD=Build.Test

echo %UNITY3D_PROJECT_PATH%

D:softUnityEditor2019.3.13f1EditorUnity.exe -quit -batchmode -executeMethod %UNITY3D_BUILD_METHOD% -projectPath %UNITY3D_PROJECT_PATH% -logFile D:uild.log -uuu: something

pause

 用空格区别参数

unity c#

public static void Test() 
    {
        string[] strs = System.Environment.GetCommandLineArgs();


        IoBuffer bi = new IoBuffer();

        foreach (var s in strs)
        {
           
            bi.PutString(s);
            
            if (s.Contains("-uuu:"))
            {
                ///string arg = s.Split(':')[1];
                //处理参数//
                Debug.Log("gogogogogo--->s:"+s);
                string a = "tx";
                
            }
        }

        byte[] bs = bi.ToArray();
        WriteBytes2File("d://testCmd.txt", bs);
        bi.Clear();
    }

  

string[] strs = System.Environment.GetCommandLineArgs();
获取到的就是
-quit
-batchmode
-executeMethod
%UNITY3D_BUILD_METHOD%
-projectPath
%UNITY3D_PROJECT_PATH%
-logFile
D:uild.log
-uuu:
something

另外生成的log build.log中可以看到c#的log
原文地址:https://www.cnblogs.com/nafio/p/12890186.html