unity打包后运行出错_配置管理员使用Jenkins完成U3D打包

目的:安排配置管理人员对产品进行版本包的管理工作,使开发人员无需频繁进行打包工作,也有利于进行产品的版本控制。

方法:使用Jenkins,该工具能完成不限于unity3d的各种编译工具的打包工作。

详细步骤:(windows环境下)

1、进入主页,可以看到常规的用户界面,一共分为三大块;

abb8ba4cd32f7888dabe809b7bdd8bf8.png

2、新建一个项目,选中该项目,可以进入项目配置界面;

60f113616cd14e29a25048d86efbdfeb.png

3、进行配置界面的脚本编写工作,可以看到项目的脚本编辑界面;

1b67eee66429f0042727238d3abad73b.png

重点是Build模块,build environment需要设置项目名称等,其他模块采用默认就行。

4、重头戏Build模块代码编写;

Execute windows batch command分三部分,也可以合并为一部分

获取用户名称的代码块

exit 0

if not exist %customer% (
   mkdir %customer%
)
cd  %customer%
if not exist %version% (
   mkdir "%version%"
) else (
   rd /s/q %version%
   mkdir "%version%"
)
cd %version%

exit 0

通过svn进行版本代码下载的代码块

exit 0
::获取log版本号下载最新或某个版本代码

cd %customer%%version%
if "%log%" == "true" (
    svn checkout -r %revision% %repository%  
) else (
    svn checkout %repository%
)
set svnURL= %repository%
svn info %svnURL% | findstr "Rev:"  > Version.txt
for /f "tokens=4 delims= " %%i in (Version.txt) do set revision=%%i
echo %revision%

exit 0

执行unity3d打包的代码块

::exit 0

::判断Unity是否运行中
TASKLIST /V /S localhost /U %username%>tmp_process_list.txt
TYPE tmp_process_list.txt |FIND "Unity.exe"

IF ERRORLEVEL 0 (GOTO UNITY_IS_RUNNING)
ELSE (GOTO START_UNITY)
:UNITY_IS_RUNNING
::杀掉Unity
TASKKILL /F /IM Unity.exe
::停1秒
PING 127.0.0.1 -n 1 >NUL

set UNITY_Version=%version%
set SVNRevision=%revision%
set PROJECT_PATH=E:jenkinsworkspaceBIM%customer%     ::这里是uniyt3d项目工程的存放位置
set UNITY_OUT_PATH=E:JenkinsProducts%customer%         ::这里是产品输出的路径存放位置
set UNITY_PATH=F:GameDevelopU3D_Hub2019.1.8f1Editor  ::这里是uniyt3d的安装位置
set UNITY_LOG_PATH=%cd%unity_log.txt
echo lunch unity.exe ,please wait a moment...
GOTO START_UNITY
:START_UNITY
f:  
::进入了F盘,因为unity3d安装在F盘
cd %UNITY_PATH%
.Unity.exe -projectPath %PROJECT_PATH% -logFile %UNITY_LOG_PATH% -quit -batchmode -executeMethod BatCall.UnityBuild  --version=%UNITY_Version% --name=%SVNRevision% --outpath=%UNITY_OUT_PATH%
echo "Build exe done"
::执行打包工作
pause

5、在unity3d项目的Editor文件夹下,需要加入下面的脚本

using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
/// <summary>
/// 供批处理打包pc端项目调用
/// </summary>
public class BatCall : MonoBehaviour {

    [MenuItem("Tools/Build")]
    public static void UnityBuild()
    {        
        Debug.logger.logEnabled = true;

        List<string> args = new List<string>();
        foreach (string item in System.Environment.GetCommandLineArgs())
        {
            if (item.StartsWith("--")) {
                string arg = item.Split('=')[1];
                args.Add(arg);
                Debug.Log("arg: "+arg);
            }
        }
        //按照顺序三个参数依次是version, SVNRevision, UNITY_OUT_PATH
        string outputPath = args[2] + @"" + args[0] + "_" + args[1] + ".exe";
        //string outputPath = args[1] + @"" + args[0] + "_hhh.exe";
        Debug.Log("outputPath :"+outputPath);

        //string NowPath =  "D:BatBuildBuild_CamCam.exe";       
        BuildPipeline.BuildPlayer(GetBuildScenes(), outputPath, BuildTarget.StandaloneWindows64, BuildOptions.None);        
    }
    static string[] GetBuildScenes()
    {
        List<string> pathList = new List<string>();
        foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
        {
            if (scene.enabled)
            {
                pathList.Add(scene.path);
                Debug.Log(scene.path);
            }
        }
        return pathList.ToArray();
    }   

}

6、回到项目的配置功能界面,点击Release等待项目自动编译打包;

df20647c1059758794b2df72e438e8f6.png

提示Success则大功告成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值