【工具】增加unity超时等待
parent
0f7451b127
commit
de3be6af10
|
|
@ -72,6 +72,7 @@ public class QuitAfterBuild
|
|||
static QuitAfterBuild()
|
||||
{
|
||||
EditorApplication.update += WaitForCompilation;
|
||||
EditorApplication.update += CheckForCompilationErrors;
|
||||
}
|
||||
|
||||
static void WaitForCompilation()
|
||||
|
|
@ -83,6 +84,17 @@ public class QuitAfterBuild
|
|||
EditorApplication.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void CheckForCompilationErrors()
|
||||
{
|
||||
// 检查Unity控制台是否有编译错误
|
||||
if (UnityEditorInternal.InternalEditorUtility.GetConsoleErrorPause())
|
||||
{
|
||||
Debug.Log("Compilation errors detected. Exiting Unity with error code.");
|
||||
EditorApplication.update -= CheckForCompilationErrors;
|
||||
EditorApplication.Exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
EOL
|
||||
|
||||
|
|
@ -97,11 +109,60 @@ UNITY_PID=$!
|
|||
echo "Unity started with PID: $UNITY_PID"
|
||||
echo "Waiting for Unity to complete compilation and exit..."
|
||||
|
||||
# 等待Unity进程结束
|
||||
# 设置最大等待时间(以秒为单位)
|
||||
MAX_WAIT_TIME=3000 # 50分钟
|
||||
START_TIME=$(date +%s)
|
||||
|
||||
# 等待Unity进程结束或超时
|
||||
while kill -0 $UNITY_PID 2>/dev/null; do
|
||||
# 检查是否超时
|
||||
CURRENT_TIME=$(date +%s)
|
||||
ELAPSED_TIME=$((CURRENT_TIME - START_TIME))
|
||||
|
||||
if [ $ELAPSED_TIME -gt $MAX_WAIT_TIME ]; then
|
||||
echo "Timeout reached after $MAX_WAIT_TIME seconds. Unity might be stuck."
|
||||
echo "Killing Unity process..."
|
||||
kill $UNITY_PID
|
||||
sleep 2
|
||||
# 如果进程仍然存在,强制终止
|
||||
if kill -0 $UNITY_PID 2>/dev/null; then
|
||||
kill -9 $UNITY_PID
|
||||
fi
|
||||
echo "Unity process was terminated due to timeout."
|
||||
rm -f "$TEMP_SCRIPT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查日志文件中是否有编译错误
|
||||
if [ -f "$LOG_FILE" ] && grep -q "CompilerErrorException" "$LOG_FILE"; then
|
||||
echo "Compilation errors detected in log file."
|
||||
echo "Killing Unity process..."
|
||||
kill $UNITY_PID
|
||||
sleep 2
|
||||
if kill -0 $UNITY_PID 2>/dev/null; then
|
||||
kill -9 $UNITY_PID
|
||||
fi
|
||||
echo "Unity process was terminated due to compilation errors."
|
||||
rm -f "$TEMP_SCRIPT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 每秒检查一次
|
||||
sleep 1
|
||||
done
|
||||
|
||||
# 获取Unity进程的退出状态
|
||||
wait $UNITY_PID
|
||||
EXIT_CODE=$?
|
||||
|
||||
# 删除临时编辑器脚本
|
||||
rm -f "$TEMP_SCRIPT"
|
||||
|
||||
echo "Unity process has exited."
|
||||
echo "Build log available at: $LOG_FILE"
|
||||
if [ $EXIT_CODE -ne 0 ]; then
|
||||
echo "Unity process exited with error code: $EXIT_CODE"
|
||||
echo "Check the build log for errors: $LOG_FILE"
|
||||
exit $EXIT_CODE
|
||||
else
|
||||
echo "Unity process has exited successfully."
|
||||
echo "Build log available at: $LOG_FILE"
|
||||
fi
|
||||
Loading…
Reference in New Issue