unity命令行打包

 

前面部分转自:http://www.cnblogs.com/gameprogram/archive/2012/05/11/2496303.html

本来是没想用这个命令行Build方式,可惜电脑不知道怎么的就没法可视化的Build的了。。一Build就蓝屏。

后面发现这个命令行Build还是一个很实用的东西,比如你可以在服务器上搞个脚本让它每天在深更半夜时帮你自动Build一个脚本。

Google查了一些资料:

http://unity3d.qatohost.com/questions/9382/build-from-script.html

buildIOS的脚本。

http://blog.seiji.me/blog/2012/02/04/build-for-ios-using-unity-editor-command-line/

Unity Command Line参数:

http://unity3d.com/support/documentation/Manual/Command%20Line%20Arguments.html

Build有错误,要注意看Editor.log

http://unity3d.com/support/documentation/Manual/Log%20Files.html

1.要写一个脚本。

要调用BuildPipeline这个类的BuildPlayer这个方法来实现的。

有关这个类的用法:

http://unity3d.com/support/documentation/ScriptReference/BuildPipeline.BuildPlayer.html

我编译androidapk时的代码:

/**

/Applications/Unity/Unity.app/Contents/MacOS/Unity\

 -batchmode \

 -quit \

 -projectPath $PROJECT_PATH \

 -executeMethod CommandBuild.BuildAndroid

*/

 

// Assets/Editor/CommandBuile.cs

using UnityEngine;

using UnityEditor;

 

public class CommandBuild

{

   public static void BuildAndroid()

   {

       string[] levels = {"Assets/Scene/1.unity","Assets/Scene/2.unity"};

       BuildPipeline.BuildPlayer(levels, "Sample.apk",BuildTarget.Android, BuildOptions.None);

   }

}

2.在命令行中不开启Unity调用1中写的方法:

先进到Unity.exe的目录下,然后在打命令。

C:\programfiles\Unity\Editor>Unity.exe -quit -batchmode -executeMethodCommandBuild.BuildAndroid

具体参数命令可以看:

http://unity3d.com/support/documentation/Manual/Command%20Line%20Arguments.html

 

 

添加:类说明

有关这个类的用法:

 

http://docs.unity3d.com/ScriptReference/BuildPipeline.BuildPlayer.html

 

BuidPipeline.BuildPlayer

public static stringBuildPlayer(string[]levels,stringlocationPathName,BuildTargettarget,BuildOptionsoptions);

 

参数:

levels: 需要buid哪些scenes

locationPathName:  build的包的路径及名称

target: BuildTarget类型,BuildTarget.Android编译一个安卓平台包,这是选择平台的

options: BuildOptions,类似于在使用unity界面build的时候,出现的右侧选择,例如:Development版本;一般选择None,按默认进行

 

返回值:

String类型,如果打包出错了,则返回错误信息

 

Description:

 

 

可能遇到的问题:

Error building Player:UnityException: Bundle Identifier has not been set up correctly

错误提示:

Error building Player:UnityException: Bundle Identifier has not been set up correctly
Please set the Bundle Identifier in the Player Settings. The value must followthe convention 'com.YourCompanyName.YourProductName' and can containalphanumeric characters and underscore.
Each segment must not start with a numeric character or underscore.

根据提示我们知道需要设置Bundle Identifier。

打开File=>build settings=> player settings=>属性面板找到Bundle Identifier 设置下名称,格式为:com.YourCompanyName.YourProductName

设置好重新发布即可

 

你可能感兴趣的:(unity3d)