飞腾俊辰实时动态>浏览文章

unity3d教程 免费 Jenkins做unity远程自动打包机下篇

0人浏览0评论

编写批处理自动打包命令。

一、在Assets\Editor目录下放个脚本

using UnityEngine;

using UnityEditor;

using System;

using System.IO;

using System.Collections.Generic;

 

/// <summary>

/// 命令行批处理工具类

/// </summary>

public class Batchmode {

    static List<string> levels = new List<string>();

    static string keystoreFile = @"D:\keystore.txt";

    public static void BuildAndroid() {

        if(!File.Exists(keystoreFile))

            throw new Exception("Not find keystore file");

        StreamReader sr = File.OpenText(keystoreFile);

        string password = sr.ReadToEnd().Trim();

        PlayerSettings.Android.keystorePass = password;

        PlayerSettings.Android.keyaliasPass = password;

        foreach ( EditorBuildSettingsScene scene in EditorBuildSettings.scenes ) {

            if ( !scene.enabled ) continue;

            levels.Add( scene.path );

        }

EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget.Android);

        string res = BuildPipeline.BuildPlayer( levels.ToArray(), "android.apk", BuildTarget.Android, BuildOptions.None );

        if (res.Length > 0)

            throw new Exception("BuildPlayer failure: " + res);

    }

}


二、写个批处理(路径改成自己的工程路径)

@echo off

@set unity="C:\Program Files\Unity\Editor\Unity.exe"

echo 正在生成APK文件...

%unity%  -batchmode -quit -nographics -executeMethod Batchmode.BuildAndroid  -logFile D:\Editor.log -projectPath "D:\China\2014-11-12_client_wushen_android" 

echo APK文件生成完毕!

pause

以上步骤完成,就可以利用批处理进行打包,下面一篇讲解远程打包机的部署配置。

飞腾俊辰VR科技更多unity3d学习QQ群:852250305

直播地址:http://www.ftjcvr.com/live/lv-1460.aspx


关键字:unity3d教程
网友评论
 
热门文章