首先判断Unity是否运行中,如果运行中,则先杀掉Unity,然后启动Unity并执行某个Editor的静态函数
ps -ef|grep Unity|grep -v grep|cut -c 9-15|xargs kill -9
也可能是
ps -ef|grep Unity|grep -v grep|cut -c 8-12|xargs kill -9
说明:
“cut -c 9-15”是截取输入行的第9个字符到第15个字符,而这正好是进程号PID。
“xargs kill -15”中的xargs命令是用来把前面命令的输出结果(PID)作为“kill -15”命令的参数,并执行该令。
另外,我们也可以使用python的osutil库来获取进程信息,并通关os.kill来杀掉进程,例:
import os
import psutil
import signal
for proc in psutil.process_iter():
pinfo = proc.as_dict(attrs=['pid', 'name'])
if 'Unity' in pinfo['name']:
print(pinfo)
os.kill(pinfo["pid"], signal.SIGINT)
shell
ANDROID_PROJECT_PATH="/Users/XXX/jenkins/workspace/bfyd-unity-android/proj"
ANDROID_BUILD_LOG_PATH="/Users/XXX/jenkins/workspace/bfyd-unity-android/proj"
ANDROID_DESTINATION_PATH="/Users/XXX/jenkins/workspace/bfyd-unity-android/build/AbBuild"
echo "$ANDROID_PROJECT_PATH ANDROID_PROJECT_PATH"
echo "$ANDROID_BUILD_LOG_PATH ANDROID_BUILD_LOG_PATH"
$UNITY_PATH -quit -batchmode -projectPath $ANDROID_PROJECT_PATH -executeMethod AssetBundleUtility.BuildAB -destinationPath $ANDROID_DESTINATION_PATH
在Unity中的Editor目录中新建一个MyEditorScript.cs脚本,如下
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class BuildTools
{
[MenuItem("Pack/BuildApp")]
public static void BuildApp()
{
var levels = new string[] { "Assets/Scenes/SampleScene.unity" };
BuildPipeline.BuildPlayer(levels, "Build/test.apk" + appName, BuildTarget.Android, BuildOptions.None);
Debug.Log("end build");
}
}