参考链接:http://www.jianshu.com/p/a9261113b4ac

照着链接的方法并没有正确生成APK,IPA没有测试过,不过大致的方法是正确的,修改如下:

Environment.bat

:: set your own Unity path
set unity="D:\Program Files\Unity\Editor\Unity.exe"
:: -debug or -release
set debugParam=-release set projectPath="E:\mycode\test\testpro"

UnityToApk.bat

call Environment.bat

echo "Start Build Unity to Apk"

%unity% -batchmode -projectPath %projectPath% -executeMethod CommandBuilder.PreBuild %debugParam% -quit -logFile ./PreBuild.log
%unity% -batchmode -projectPath %projectPath% -executeMethod CommandBuilder.Build %debugParam% -android -quit -logFile ./BuildApk.log echo "End Build,please see log PreBuild.log and BuildApk.log"

cs脚本,放在Editor目录下

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO; public class CommandBuilder { private static string[] build_scenes = { "Assets/ddd.unity" }; private static bool ms_isDebugBuild = false;
private static BuildTarget ms_buildTarget = BuildTarget.Android; private static string XCODE_PROJECT_NAME = "XCodeProject";
private static string BUILD_OUTPUT_ANDROID = Application.dataPath + "/Bin/Android/"; private static void UpdateBuildFlag()
{
string[] args = System.Environment.GetCommandLineArgs();
foreach (string oneArg in args)
{
if (oneArg != null && oneArg.Length > )
{
if (oneArg.ToLower().Contains("-debug"))
{
Debug.Log("\"-debug\" is detected, switch to debug build.");
ms_isDebugBuild = true;
return;
}
else if (oneArg.ToLower().Contains("-release"))
{
Debug.Log("\"-release\" is detected, switch to release build.");
ms_isDebugBuild = false;
return;
}
}
} if (ms_isDebugBuild)
{
Debug.Log("neither \"-debug\" nor \"-release\" is detected, current is to debug build.");
}
else
{
Debug.Log("neither \"-debug\" nor \"-release\" is detected, current is to release build.");
} } private static void UpdateBuildTarget()
{
string[] args = System.Environment.GetCommandLineArgs();
foreach (string oneArg in args)
{
if (oneArg != null && oneArg.Length > )
{
if (oneArg.ToLower().Contains("-android"))
{
Debug.Log("\"-android\" is detected, switch build target to android.");
ms_buildTarget = BuildTarget.Android;
return;
}
else if (oneArg.ToLower().Contains("-iphone"))
{
Debug.Log("\"-iphone\" is detected, switch build target to iphone.");
ms_buildTarget = BuildTarget.iOS;
return;
}
else if (oneArg.ToLower().Contains("-ios"))
{
Debug.Log("\"-ios\" is detected, switch build target to iphone.");
ms_buildTarget = BuildTarget.iOS;
return;
}
}
} Debug.Log("neither \"-android\", \"-ios\" nor \"-iphone\" is detected, current build target is: " + ms_buildTarget);
} public static void PreBuild()
{
Debug.Log("PreBuild");
UpdateBuildFlag();
}
public static void Build()
{
Debug.Log("Build");
UpdateBuildTarget(); BuildOptions buildOption = BuildOptions.None;
if (ms_isDebugBuild)
{
buildOption |= BuildOptions.Development;
buildOption |= BuildOptions.AllowDebugging;
buildOption |= BuildOptions.ConnectWithProfiler;
}
else
{
buildOption |= BuildOptions.None;
} string locationPathName;
if (BuildTarget.iOS == ms_buildTarget)
{
locationPathName = XCODE_PROJECT_NAME;
}
else
{
locationPathName = BUILD_OUTPUT_ANDROID;    //原链接此处没有生成目录,而是使用rmdir mkdir生成,实际测试时无法将APK复制进目录中,所以讲目录修改如下
if (Directory.Exists(locationPathName))
Directory.Delete(locationPathName, true); Directory.CreateDirectory(locationPathName); System.DateTime time = System.DateTime.Now;
locationPathName += "test_" + time.Month.ToString("D2") + time.Day.ToString("D2") +
"_" + time.Hour.ToString("D2") + time.Minute.ToString("D2") + ".apk";
}
BuildPipeline.BuildPlayer(build_scenes, locationPathName, ms_buildTarget, buildOption);
}
public static void PostBuild()
{
Debug.Log("PostBuild");
} }

最新文章

  1. ****LINUX命令(含GIT命令)个人总结
  2. Python 10 —— 杂
  3. Unity2.0容器自动注册机制
  4. Linux下LDAPSearch的例子
  5. WPF Button的背景图片设置
  6. windows 7 旗舰版 切换 中英文 界面
  7. Android系统--输入系统(十七)Dispatcher线程_分发dispatch
  8. vbs文件共享变量与函数的方法
  9. [poj2406]Power Strings_hash
  10. 想知道谁是你的最佳用户?基于Redis实现排行榜周期榜与最近N期榜
  11. 测者的性能测试手册:快速安装LoadRunner Linux上的Generator
  12. js备战春招の四のDOM
  13. Linux (麒麟)系统 重启后无法登陆进图形界面
  14. 微信小程序大型系统架构中应用Redis缓存要点
  15. 【Luogu3602】Koishi Loves Segments(贪心)
  16. OpenLayers学习笔记(一)—在线加载谷歌影像地图&离线加载本地瓦片地图
  17. jmeter接口测试基础知识1.0
  18. Kubernetes部署SpringCloud(二) 部署ZUUL与服务 非host, 伸缩与负载均衡
  19. 逻辑回归 logit
  20. C#中泛型的解释(object,list,var,dynamic的区别)

热门文章

  1. websocket之二:WebSocket编程入门
  2. @SpringBootApplication注解分析
  3. C# FileStream Write追加写入文本
  4. JIRA 破解文件研究(Win 7环境)
  5. pow()函数的精度问题
  6. Gym - 100801H Hash Code Hacker (构造)
  7. 小议IT公司的组织架构
  8. Weekly Contest 113
  9. 转 BeanShell 简介与学习(一篇就够)
  10. JS动态append之后点击事件无效