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. django -- 修改admin 密码问题

    1.python manage.py shell 2.from django.contrib.auth.models import User 3.user=User.objects.get(usern ...

  2. vue 生命周期钩子的理解 watch computed

    一  理解vue的生命周期,首先需要注意几个关键字 1. el :选择器 2. $el:对应选择器的template模板(html代码) 3. render:也是vue实例中的一项,其参数更接近vue ...

  3. 第二节 JavaScript基础

    JavaScript组成及其兼容性: ECMAScript:解释器,翻译,用于实现机器语言和高级语言的翻译器:几乎没有兼容性问题 DOM(Document Object Model):文档对象模型,文 ...

  4. vivado 连接不上板子 There is no current hw_target

    前情提要: vivado连接板子点击auto connect报错 [Labtoolstcl 44-469] There is no current hw_target. 处理步骤: 首先排除硬件问题, ...

  5. 利用Python实现多线程聊天功能

    #-*- coding:utf-8 -*- from threading import Thread from socket import * #1.实现接收消息 def recvDate(): wh ...

  6. scrapy 日志处理

    Scrapy生成的调试信息非常有用,但是通常太啰嗦,你可以在Scrapy项目中的setting.py中设置日志显示等级: LOG_LEVEL = 'ERROR' 日志级别 Scrapy日志有五种等级, ...

  7. Docker学习笔记之镜像与容器

    0x00 概述 镜像和容器作为 Docker 里最基础的概念,我们很有必要了解 Docker 对它们的很多定义以及其他与它们有关的知识.在这一小节里,我们就专门针对镜像与容器两个概念展开,细致的梳理与 ...

  8. JVM结构及堆的划分

    一.JVM结构 1.类加载子系统与方法区 类加载子系统负责从文件系统或者网络中加载Class信息,加载的类信息存放于一块称为方法区的内存空间.除了类的信息外,方法区中可能还会存放运行时常量池信息,包括 ...

  9. Spring Boot(十四):spring boot整合shiro-登录认证和权限管理

    Spring Boot(十四):spring boot整合shiro-登录认证和权限管理 使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉 ...

  10. mysql 水平分表技术

    这里做的是我的一个笔记. 水平分表比较简单, 理解就是: 合并的表使用的必须是MyISAM引擎 表的结构必须一致,包括索引.字段类型.引擎和字符集 数据表 user1 CREATE TABLE `us ...