打包工具脚本提交
parent
efc9ff9daf
commit
95c0618c33
|
@ -0,0 +1,104 @@
|
|||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System;
|
||||
|
||||
public class AutoPack : EditorWindow
|
||||
{
|
||||
bool isObb = false;
|
||||
bool isBuild = false;
|
||||
bool isZs = false;
|
||||
static string[] versionArr = new string[15];
|
||||
int verIndex = 0;
|
||||
static string curProjectDir;
|
||||
//打包数据
|
||||
[MenuItem("自动化打包/一键导出")]
|
||||
private static void EzBuildPack()
|
||||
{
|
||||
curProjectDir = Environment.CurrentDirectory.Replace('\\', '/');
|
||||
string[] _strArr = Directory.GetFiles(curProjectDir + "/AssetBundles/", "*.txt");
|
||||
for (int i = 0; i < _strArr.Length; i++)
|
||||
{
|
||||
string _str = _strArr[i].Split('/')[4];
|
||||
versionArr[i] = _str;
|
||||
}
|
||||
Debug.Log("versionArr :" + versionArr.Length + versionArr[0]);
|
||||
//创建窗口
|
||||
Rect wr = new Rect(0, 0, 400, 500);
|
||||
var buildWin = GetWindowWithRect<AutoPack>(wr, true);
|
||||
buildWin.titleContent = new GUIContent("打包工具");
|
||||
buildWin.Show();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
EditorGUILayout.BeginVertical();
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.Space();
|
||||
verIndex = EditorGUILayout.Popup("选择version配置文件:", verIndex, versionArr);
|
||||
EditorGUILayout.Space();
|
||||
isObb = EditorGUILayout.ToggleLeft("是否导出obb包", isObb);
|
||||
isBuild = EditorGUILayout.ToggleLeft("是否需要build资源", isBuild);
|
||||
isZs = EditorGUILayout.ToggleLeft("是否从正式场景导出", isZs);
|
||||
EditorGUILayout.Space();
|
||||
if (GUILayout.Button("导出Android工程", GUILayout.Height(40f)))
|
||||
{
|
||||
Debug.Log("开始导出工程");
|
||||
string targetPath = Application.dataPath + "/Resources/version.txt";
|
||||
string copyPath = curProjectDir + "/AssetBundles/" + versionArr[verIndex];
|
||||
if (File.Exists(targetPath))
|
||||
{
|
||||
File.Delete(targetPath);
|
||||
}
|
||||
File.Copy(copyPath, targetPath, true);
|
||||
if (isBuild)
|
||||
{
|
||||
Debug.Log("开始build资源");
|
||||
//打包游戏
|
||||
GameEditor.FrameTool.FrameTool.BuildGameAssetBundles();
|
||||
//拷贝AssetBundle到流媒体目录
|
||||
GameEditor.FrameTool.FrameTool.CopyAssetBundleToStreamingAssets();
|
||||
//刷新资源配置
|
||||
GameEditor.ResourcesPathEditor.CreateResourcePathConfig();
|
||||
Debug.Log("完成build资源");
|
||||
}
|
||||
string sceneName = "Assets/LuaFramework/Scenes/LogoHwTest.unity";
|
||||
if (isZs)
|
||||
{
|
||||
sceneName = "Assets/LuaFramework/Scenes/LogoHwRelease.unity";
|
||||
}
|
||||
ExportAS(isObb, sceneName);
|
||||
}
|
||||
|
||||
}
|
||||
public static void ExportAS(bool _isobb, string _sceneName)
|
||||
{
|
||||
PlayerSettings.productName = "ex_android_jl";
|
||||
PlayerSettings.Android.useAPKExpansionFiles = _isobb;
|
||||
string outPath = "D:/exAndroid/unity_ex_as";
|
||||
if (_isobb)
|
||||
{
|
||||
outPath = "D:/exAndroid/unity_ex_obb";
|
||||
}
|
||||
if (Directory.Exists(outPath + "/ex_android_jl"))
|
||||
{
|
||||
Directory.Delete(outPath + "/ex_android_jl/", true);
|
||||
}
|
||||
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
||||
// 设置需要打包的场景
|
||||
string launchScene = _sceneName;
|
||||
Debug.Log("打包场景:" + launchScene);
|
||||
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
|
||||
buildPlayerOptions.locationPathName = outPath;
|
||||
buildPlayerOptions.options = BuildOptions.None;
|
||||
buildPlayerOptions.options |= BuildOptions.AcceptExternalModificationsToPlayer;
|
||||
buildPlayerOptions.scenes = new[] { launchScene };
|
||||
buildPlayerOptions.target = BuildTarget.Android;
|
||||
// 调用开始打包
|
||||
BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
Debug.Log("导出完成");
|
||||
///打开python工具所在路径
|
||||
GameEditor.Core.DataConfig.ConfigExportWindow.OpenDirectory("C:/Users/aaa/Desktop/pythonPack");
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7dac5b57cfa6901449b0ee731230096f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,69 @@
|
|||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.IO;
|
||||
using System;
|
||||
//using System.Diagnostics;
|
||||
/// <summary>
|
||||
/// 安卓打包(接口都由python外部通过cmd命令调用)
|
||||
/// </summary>
|
||||
public class CommandBuilder : EditorWindow
|
||||
{
|
||||
|
||||
public static void BuildData()
|
||||
{
|
||||
GameEditor.Core.DataConfig.ConfigExportWindow.PyCallBuildData();
|
||||
}
|
||||
//打包资源和热更代码
|
||||
public static void BuildAssets()
|
||||
{
|
||||
//打包游戏
|
||||
GameEditor.FrameTool.FrameTool.BuildGameAssetBundles();
|
||||
//拷贝AssetBundle到流媒体目录
|
||||
GameEditor.FrameTool.FrameTool.CopyAssetBundleToStreamingAssets();
|
||||
//刷新资源配置
|
||||
GameEditor.ResourcesPathEditor.CreateResourcePathConfig();
|
||||
}
|
||||
|
||||
public static void BuildAS()
|
||||
{
|
||||
string[] s = System.Environment.GetCommandLineArgs();//获取命令行参数
|
||||
//----------设置config文件-----------------
|
||||
|
||||
int index = s.Length - 1;
|
||||
string str = s[index];
|
||||
string[]arr = str.Split('#');
|
||||
string targetPath = Application.dataPath + "/Resources/version.txt";
|
||||
string _str = System.Environment.CurrentDirectory.Replace('\\', '/');
|
||||
string copyPath = _str + "/AssetBundles/" + arr[0];
|
||||
if (File.Exists(targetPath))
|
||||
{
|
||||
File.Delete(targetPath);
|
||||
}
|
||||
File.Copy(copyPath, targetPath, true);
|
||||
//----------设置打包场景准备导出android-----------------
|
||||
PlayerSettings.productName = "ex_android_jl";
|
||||
//设置是否导出obb
|
||||
PlayerSettings.Android.useAPKExpansionFiles = arr[2] == "1";
|
||||
|
||||
string outPath = "D:/exAndroid/unity_ex_as";
|
||||
if (Directory.Exists(outPath + "/ex_android_jl"))
|
||||
{
|
||||
Directory.Delete(outPath + "/ex_android_jl/", true);
|
||||
}
|
||||
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
|
||||
// 设置需要打包的场景
|
||||
string launchScene = arr[1];
|
||||
Debug.Log("打包场景:" + launchScene);
|
||||
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
|
||||
buildPlayerOptions.locationPathName = outPath;
|
||||
buildPlayerOptions.options = BuildOptions.None;
|
||||
buildPlayerOptions.options |= BuildOptions.AcceptExternalModificationsToPlayer;
|
||||
buildPlayerOptions.scenes = new[] { launchScene };
|
||||
buildPlayerOptions.target = BuildTarget.Android;
|
||||
// 调用开始打包
|
||||
BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9d27d235b2eeb334fb11346fc776b23b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -29,7 +29,14 @@ namespace GameEditor.Core.DataConfig
|
|||
win.titleContent = new GUIContent("Export");
|
||||
win.Show();
|
||||
}
|
||||
|
||||
//提供给打包工具调用的一键导表接口
|
||||
public static void PyCallBuildData()
|
||||
{
|
||||
string[] s = System.Environment.GetCommandLineArgs();//获取命令行参数
|
||||
int _index = s.Length - 1;
|
||||
// 导表
|
||||
DataConfigWindow.excelALLConfig(false, "E:/Git/data_execl/" + s[_index] + "/base_data");
|
||||
}
|
||||
|
||||
private static void LoadDic()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue