C#脚本
using UnityEngine; using UnityEditor; public class TestClass { // 要调用的函数 public static void TestFunc() { Debug.Log("************* TestFunc ******************"); startTime = Time.realtimeSinceStartup; EditorApplication.update += Run; } static float startTime; static int[] array; [MenuItem("Test Menu/Run")] public static void Run() { var leftTime = Time.realtimeSinceStartup - startTime; if(leftTime > 3) //3秒后退出 { EditorApplication.Exit(0); } try { Debug.Log("######### Run ######### leftTime:" + leftTime.ToString()); //Debug.Log(array[0]); } catch (System.Exception) { EditorApplication.Exit(0); } } }
bat 命令
@echo off TASKKILL /F /IM Unity.exe set UNITY_PATH="D:\Program Files\Unity 2021.3.25f1\Editor\Unity.exe" echo UNITY_PATH=%UNITY_PATH% set PROJECT_PATH="F:\JCTest2" echo PROJECT_PATH=%PROJECT_PATH% set LOG_PATH=%cd%\unity_log.txt echo LOG_PATH=%LOG_PATH% set METHOD_NAME="TestClass.TestFunc" echo METHOD_NAME=%METHOD_NAME% %UNITY_PATH% -batchmode -logFile %LOG_PATH% -projectPath %PROJECT_PATH% -executeMethod %METHOD_NAME% ::if %errorlevel% == 0 (echo 调用成功) else (echo 调用失败,请查看unity_log.txt) pause
注意unity命令行中不要使用 -quit 参数,那种只适用于同步执行的函数
文章评论