美文网首页Unity跨平台技术分享
使用shell脚本来打包unity安卓工程

使用shell脚本来打包unity安卓工程

作者: BowenK | 来源:发表于2017-11-25 23:48 被阅读20次

如果你想实现快速打包,或者需要频繁的打包的操作,那么使用shell脚本来打包unity是非常正确的一个选择。
其实基本的操作流程unity的官方文档上面都有写
CommandLineArguments

这里介绍一下,一个简单的打包写法:
首先要在unity工程里面创建一个Editor文件夹,并且创建一个脚本

using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class BuildAndroid {

    static void Build () {
        var levels = new List<string>();
        for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
        {
            if (EditorBuildSettings.scenes[i].enabled)
                levels.Add(EditorBuildSettings.scenes[i].path);
        }
        if (levels.Count == 0)
            levels.Add(EditorApplication.currentScene);

        var path = Application.dataPath.Remove(Application.dataPath.Length - "Assets".Length)+Application.bundleIdentifier;

        BuildPipeline.BuildPlayer(levels.ToArray(), path, BuildTarget.Android, BuildOptions.None);
    }
}

保存脚本并且关闭unity,直接下来就是shell写shell脚本了

#!/bin/sh

workspace="/Users/bowenk/Bowenk/Workspace/demo"  #unity的工程目录 (这是我的项目路径)


/Applications/Unity\ ${unityVersion}/Unity.app/Contents/MacOS/Unity  -quit  -batchmode  -projectPath  "${workspace}" \
-buildTarget "android"  -executeMethod  BuildAndroid.Build  -silent-crashes \

是不是很简单,当然也有很多拓展 可以自己去研究,而且可以通过外部传递参数进来进行各种操作,这里就不介绍了,可以自己去尝试下。

相关文章

网友评论

    本文标题:使用shell脚本来打包unity安卓工程

    本文链接:https://www.haomeiwen.com/subject/cxucbxtx.html