using System;
using System.IO;
using UnityEditor;
using UnityEngine;

public class BuildPlayer : ScriptableObject
{
static string rootPath = Application.dataPath + Path.DirectorySeparatorChar;
static string rootParent = new DirectoryInfo(rootPath).Parent.FullName + Path.DirectorySeparatorChar;
static string projectName = new DirectoryInfo(rootPath).Parent.Name;
static string scenePath = Application.dataPath + Path.DirectorySeparatorChar + "Scenes" + Path.DirectorySeparatorChar;
static string apkNameDebug = rootParent + projectName + "_Debug_[Date].apk";
static string apkNameRelease = rootParent + projectName + "_Release_[Date].apk";

[MenuItem("Build Player/Build Android Debug", false, 101)]
static void BuildAndroidDebug()
{
AssetDatabase.Refresh();
// set build options and build player
BuildOptions options = BuildOptions.Development | BuildOptions.AllowDebugging | BuildOptions.ShowBuiltPlayer;
string[] allScenes = GetAllScenes();
BuildPipeline.BuildPlayer(allScenes, InsertDateString(apkNameDebug), BuildTarget.Android, options);
}

[MenuItem("Build Player/Build Android Debug(Auto Deploy)", false, 102)]
static void BuildAndroidDebugAutoDeploy()
{
AssetDatabase.Refresh();
// set build options and build player
BuildOptions options = BuildOptions.Development | BuildOptions.AutoRunPlayer | BuildOptions.AllowDebugging;
string[] allScenes = GetAllScenes();
BuildPipeline.BuildPlayer(allScenes, InsertDateString(apkNameDebug), BuildTarget.Android, options);
}

[MenuItem("Build Player/Build Android Debug(Auto Deploy And Connect Profiler)", false, 103)]
static void BuildAndroidDebugAutoDeployAndConnectProfiler()
{
AssetDatabase.Refresh();
// set build options and build player
BuildOptions options = BuildOptions.Development | BuildOptions.AutoRunPlayer | BuildOptions.ConnectWithProfiler | BuildOptions.AllowDebugging;
string[] allScenes = GetAllScenes();
BuildPipeline.BuildPlayer(allScenes, InsertDateString(apkNameDebug), BuildTarget.Android, options);
}

[MenuItem("Build Player/Build Android Release", false, 201)]
static void BuildAndroidRelease()
{
// rename all debug scripts to *.rem
RenameDebugScripts();
// set build options and build player
BuildOptions options = BuildOptions.ShowBuiltPlayer;
string[] allScenes = GetAllScenes();
BuildPipeline.BuildPlayer(allScenes, InsertDateString(apkNameRelease), BuildTarget.Android, options);
// restore all debug scripts' file names
RestoreDebugScripts();
}

[MenuItem("Build Player/Build Android Release(Auto Deploy)", false, 202)]
static void BuildAndroidReleaseAutoDeploy()
{
// rename all debug scripts to *.rem
RenameDebugScripts();
// set build options and build player
BuildOptions options = BuildOptions.AutoRunPlayer;
string[] allScenes = GetAllScenes();
BuildPipeline.BuildPlayer(allScenes, InsertDateString(apkNameRelease), BuildTarget.Android, options);
// restore all debug scripts' file names
RestoreDebugScripts();
}

static void RenameDebugScripts()
{
string[] allDebugDirectories = Directory.GetDirectories(rootPath, "_Debug", SearchOption.AllDirectories);
foreach (string directory in allDebugDirectories)
{
string[] scripts = Directory.GetFiles(directory, "*.cs", SearchOption.AllDirectories);
foreach (string script in scripts)
{
string newScriptName = script + ".rem";
File.Move(script, newScriptName);
File.Delete(script + ".meta");
}
}
AssetDatabase.Refresh();
}

static void RestoreDebugScripts()
{
string[] allDebugDirectories = Directory.GetDirectories(rootPath, "_Debug", SearchOption.AllDirectories);
foreach (string directory in allDebugDirectories)
{
string[] renamedScripts = Directory.GetFiles(directory, "*.rem", SearchOption.AllDirectories);
foreach (string renamedScript in renamedScripts)
{
string scriptName = renamedScript.Substring(0, renamedScript.Length - 3);
File.Move(renamedScript, scriptName);
File.Delete(renamedScript + ".meta");
}
}
AssetDatabase.Refresh();
}

static string[] GetAllScenes()
{
string[] allScenes = null;
DirectoryInfo dirInfo = new DirectoryInfo(scenePath);
FileInfo[] fileInfos = dirInfo.GetFiles("*.unity", SearchOption.AllDirectories);
allScenes = new string[fileInfos.Length];
int index = 0;
foreach (FileInfo fileInfo in fileInfos)
{
string scene = fileInfo.FullName.Replace(rootParent, "");
allScenes[index++] = scene;
}
return allScenes;
}

static string InsertDateString(string apkName)
{
DateTime now = DateTime.Now;
return apkName.Replace("[Date]", string.Format("[{0:d4}{1:d2}{2:d2}][{3:d2}{4:d2}{5:d2}]", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second));
}
}

转 代码修改buildoption的更多相关文章

  1. Android之vector代码修改颜色

    前言:google给了很多material design icon,在开发过程中,可以下载下来直接使用,下载地址为https://materialdesignicons.com/ . 1.下载图标,并 ...

  2. Asp.net使用代码修改配置文件的节点值

    使用代码修改配置文件的方法: 1.打开配置文件写入的权限 2.先按节点名称长到要修改的节点,然后删除,紧接着将有新值的节点添加回去 3.关闭配置文件写入的权限 修改Appsetting节点的值,修改其 ...

  3. am335x UART1输入u-boot 调试信息代码修改

    AM335x 调试信息UART1输出代码修改1. 关于pin_mux  的配置代码修改位置:/board/forlinx/ok335x/mux.c void enable_uart0_pin_mux( ...

  4. SharePoint开发 - 使用Session(代码修改webconfig)

    博客地址 http://blog.csdn.net/foxdave SharePoint启用Session可以使用Powershell,戳这里:可以修改webconfig. 本篇叙述的重点是通过fea ...

  5. Spring+SpringMVC+MyBatis整合进阶篇(四)RESTful实战(前端代码修改)

    前言 前文<RESTful API实战笔记(接口设计及Java后端实现)>中介绍了RESTful中后端开发的实现,主要是接口地址修改和返回数据的格式及规范的修改,本文则简单介绍一下,RES ...

  6. 在win7上跑基于任少卿作者代码修改的RPN+BF实验

    1.前言 之前在win10上成功的跑起来faster-rcnn的实验,并且跑了一下CaltechPedestrian的数据集,但是效果一直不理想,折腾了好久也没弄清楚到底原因出在哪里,直到读了Is F ...

  7. u-boot移植(十二)---代码修改---支持DM9000网卡

    一.准备工作 1.1 原理图 CONFIG_DM9000_BASE 片选信号是接在nGCS4引脚,若要确定网卡的基地址,则要根据片选信号的接口去确定. 在三星2440的DATASHEET中memory ...

  8. 开始玩qt,使用代码修改设计模式生成的菜单

    之前制作菜单时,不是纯代码便是用设计模式 直接图形化完成. 今天我就是想用代码修改已经存在的菜单项,如果是用代码生成的可以直接调用指针完成: 但通过设计模式完成的没有暴露指针给我,至少我没发现. 在几 ...

  9. master-worker常驻型程序代码修改哪些需要重启master或者worker

    之前在yii的项目里用redis作为消息队列,现在很多任务需要延迟需求,于是把之前redis的消息队列替换成了rabbitmq 于是使用yii的yii2-queue这个组件 但是由于提供的yii qu ...

随机推荐

  1. Bluetooth_FTP_SPEC: 蓝牙FTP介绍

    FTP(Bluetooth File Transfer Profile) defines howfolders and files on a server device can be browsed ...

  2. [转载]ADO.NET中的五个主要对象

    Connection:主要是开启程序和数据库之间的连接.没有利用连接对象将数据库打开,是无法从数据库中取得数据的.Close和Dispose的区别,Close以后还可以Open,Dispose以后则不 ...

  3. Spring P命名空间 02

    P命名空间 装配属性 使用<property> 元素为Bean 的属性装配值和引用并不太复杂.尽管如此,Spring 的命名空间p 提供了另一种Bean 属性的装配方式,该方式不需要配置如 ...

  4. PS火焰文字制作

    火焰文字制作: 最终效果 第一步: 新建图层,并输入文字(这里不做详细解说)

  5. SVN如何将版本库url访问地址中的https改为http

    1.选择控制台树中的根节点,右键选择“属性”. 2.切换至面板“网络”. 3.取消勾选项“使用安全连接协议(https://)”.

  6. MS11-050安全漏洞

    IE浏览器渗透攻击--MS11050安全漏洞 实验前准备 1.两台虚拟机,其中一台为kali,一台为windows xp sp3(包含IE7). 2.设置虚拟机网络为NAT模式,保证两台虚拟机可以相互 ...

  7. topcoder srm 435 div1

    problem1 link 遍历未被删除的叶子结点即可. problem2 link 首先,将所有的蛋白质原子编号,设为$[0,m-1]$,每个原子可能对应多个长度为3的$ACGT$.设$n$为DNA ...

  8. vue学习【第七篇】:Vue之导入Bootstrap

    Vue引入bootstrap主要有两种方法 方法一:在main.js中引入 此方法导入的bootstrap中对于html,body的一些预设置的css样式可能无效 引入jQuery 在当前项目的目录下 ...

  9. Docker 搭建Spark 依赖singularities/spark:2.2镜像

    singularities/spark:2.2版本中 Hadoop版本:2.8.2 Spark版本: 2.2.1 Scala版本:2.11.8 Java版本:1.8.0_151 拉取镜像: [root ...

  10. switch反汇编(C语言)

    在分支较多的时候,switch的效率比if高,在反汇编中我们即可看到效率高的原因 0x01分支结构不超过3个 #include <stdio.h> void main() { int x ...