miduo_client/Assets/Editor/AutoPack.cs

195 lines
8.1 KiB
C#
Raw Normal View History

2020-09-10 11:47:18 +08:00
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
2020-09-18 17:44:02 +08:00
using GameEditor.FrameTool;
2020-09-10 11:47:18 +08:00
public class AutoPack : EditorWindow
{
2020-09-14 16:20:36 +08:00
static bool isObb = false;
2020-09-10 11:47:18 +08:00
bool isBuild = false;
2020-09-14 16:20:36 +08:00
static bool isZs = false;
2020-09-10 11:47:18 +08:00
static string[] versionArr = new string[15];
2020-09-18 17:44:02 +08:00
static int verIndex = 0;
2020-09-10 11:47:18 +08:00
static string curProjectDir;
2020-09-18 17:44:02 +08:00
static string m_ExcelPath;
static string[] excelArr;
static int excelIndex=0;
2020-09-10 11:47:18 +08:00
//打包数据
[MenuItem("自动化打包/一键导出")]
private static void EzBuildPack()
{
2020-09-18 17:44:02 +08:00
curProjectDir = Environment.CurrentDirectory.Replace('\\', '/');
verIndex = EditorPrefs.GetInt("verIndex");
m_ExcelPath = EditorPrefs.GetString("m_ExcelPath");
excelArr = Directory.GetDirectories(m_ExcelPath, "master_*");
Debug.Log(EditorPrefs.GetString("m_Bench"));
if (excelArr!=null)
{
for (int i = 0; i < excelArr.Length; i++)
{
if (excelArr[i]== EditorPrefs.GetString("m_Bench"))
{
excelIndex = i;
}
}
}
2020-09-10 11:47:18 +08:00
string[] _strArr = Directory.GetFiles(curProjectDir + "/AssetBundles/", "*.txt");
2020-09-14 16:20:36 +08:00
Debug.Log("version列表数量:"+_strArr.Length);
2020-09-10 11:47:18 +08:00
for (int i = 0; i < _strArr.Length; i++)
{
2020-09-14 16:20:36 +08:00
string[] pathSpl = _strArr[i].Split('/');
string _str = pathSpl[pathSpl.Length-1];
2020-09-10 11:47:18 +08:00
versionArr[i] = _str;
}
//创建窗口
Rect wr = new Rect(0, 0, 400, 500);
var buildWin = GetWindowWithRect<AutoPack>(wr, true);
buildWin.titleContent = new GUIContent("打包工具");
2020-09-18 17:44:02 +08:00
buildWin.Show();
2020-09-10 11:47:18 +08:00
}
private void OnGUI()
2020-09-18 17:44:02 +08:00
{
2020-09-10 11:47:18 +08:00
EditorGUILayout.BeginVertical();
EditorGUILayout.Space();
EditorGUILayout.Space();
2020-09-18 17:44:02 +08:00
if (excelArr!=null&& excelArr.Length>0)
{
excelIndex = EditorGUILayout.Popup("选择excel文件", excelIndex, excelArr);
EditorGUILayout.Space();
if (GUILayout.Button("一键导表", GUILayout.Height(40f)))
{
EditorPrefs.SetString("m_Bench", excelArr[excelIndex]);
GameEditor.Core.DataConfig.DataConfigWindow.excelALLConfig(false, excelArr[excelIndex] + "/base_data");
}
}
if (GUILayout.Button("单打lua资源", GUILayout.Height(40f)))
{
if (FrameTool.BuildLuaAssetBundles())
{
string exportPath = GameEditor.AssetBundle.AssetBundleConfig.GetExportPath(EditorUserBuildSettings.activeBuildTarget);
string targetPath = FrameTool.GetStreamingAssetPath(EditorUserBuildSettings.activeBuildTarget);
File.Copy(exportPath + "/lzma/luabytes.unity3d", targetPath + "/lzma/luabytes.unity3d", true);
File.Copy(exportPath + "/lzma/resconfigs.unity3d", targetPath + "/lzma/resconfigs.unity3d", true);
File.Copy(exportPath + "/files.unity3d", targetPath + "/files.unity3d", true);
}
}
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
EditorGUILayout.Space();
2020-09-10 11:47:18 +08:00
verIndex = EditorGUILayout.Popup("选择version配置文件", verIndex, versionArr);
EditorGUILayout.Space();
2020-09-14 16:20:36 +08:00
#if UNITY_ANDROID
2020-09-10 11:47:18 +08:00
isObb = EditorGUILayout.ToggleLeft("是否导出obb包", isObb);
2020-09-14 16:20:36 +08:00
#endif
2020-09-10 11:47:18 +08:00
isBuild = EditorGUILayout.ToggleLeft("是否需要build资源", isBuild);
isZs = EditorGUILayout.ToggleLeft("是否从正式场景导出", isZs);
EditorGUILayout.Space();
2020-09-14 16:20:36 +08:00
if (GUILayout.Button("导出工程", GUILayout.Height(40f)))
2020-09-10 11:47:18 +08:00
{
Debug.Log("开始导出工程");
2020-09-18 17:44:02 +08:00
EditorPrefs.SetInt("verIndex", verIndex);
2020-09-10 11:47:18 +08:00
string targetPath = Application.dataPath + "/Resources/version.txt";
string copyPath = curProjectDir + "/AssetBundles/" + versionArr[verIndex];
2020-09-14 18:11:55 +08:00
Debug.Log("version文件路径:" + copyPath);
2020-09-10 11:47:18 +08:00
if (File.Exists(targetPath))
{
File.Delete(targetPath);
}
File.Copy(copyPath, targetPath, true);
2020-09-17 12:08:08 +08:00
AssetDatabase.Refresh();
2020-09-10 11:47:18 +08:00
if (isBuild)
{
Debug.Log("开始build资源");
//打包游戏
2020-09-18 17:44:02 +08:00
FrameTool.BuildGameAssetBundles();
2020-09-10 11:47:18 +08:00
//拷贝AssetBundle到流媒体目录
2020-09-18 17:44:02 +08:00
FrameTool.CopyAssetBundleToStreamingAssets();
2020-09-10 11:47:18 +08:00
//刷新资源配置
GameEditor.ResourcesPathEditor.CreateResourcePathConfig();
Debug.Log("完成build资源");
}
2020-09-14 16:20:36 +08:00
#if UNITY_ANDROID
2020-09-10 11:47:18 +08:00
string sceneName = "Assets/LuaFramework/Scenes/LogoHwTest.unity";
if (isZs)
{
sceneName = "Assets/LuaFramework/Scenes/LogoHwRelease.unity";
}
2020-09-14 16:20:36 +08:00
ExportAS( sceneName);
#elif UNITY_IOS
string sceneName = "Assets/LuaFramework/Scenes/Logo.unity";
ExportXcode(sceneName);
#endif
2020-09-10 11:47:18 +08:00
}
}
2020-09-14 16:20:36 +08:00
public static void ExportAS( string _sceneName)
2020-09-10 11:47:18 +08:00
{
PlayerSettings.productName = "ex_android_jl";
2020-09-18 17:44:02 +08:00
PlayerSettings.Android.useAPKExpansionFiles = isObb;
2020-09-10 11:47:18 +08:00
string outPath = "D:/exAndroid/unity_ex_as";
2020-09-14 16:20:36 +08:00
if (isObb)
2020-09-10 11:47:18 +08:00
{
outPath = "D:/exAndroid/unity_ex_obb";
}
if (Directory.Exists(outPath + "/ex_android_jl"))
{
Directory.Delete(outPath + "/ex_android_jl/", true);
}
EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
2020-09-17 12:08:08 +08:00
EditorUserBuildSettings.androidBuildSystem = AndroidBuildSystem.Gradle;
2020-09-10 11:47:18 +08:00
// 设置需要打包的场景
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);
2020-09-14 18:11:55 +08:00
Debug.Log("android工程导出路径"+ outPath + "/ex_android_jl");
2020-09-10 11:47:18 +08:00
Debug.Log("导出完成");
///打开python工具所在路径
GameEditor.Core.DataConfig.ConfigExportWindow.OpenDirectory("C:/Users/aaa/Desktop/pythonPack");
2020-09-14 16:20:36 +08:00
}
2020-09-10 11:47:18 +08:00
2020-09-14 16:20:36 +08:00
private static void ExportXcode(string _sceneName)
{
PlayerSettings.productName = "太初行";
string mainXcodePath =
isZs? "/Volumes/ELEMENTS/JieLing/Packager/IOS/MHT_HW_RELEASE": "/Volumes/ELEMENTS/JieLing/Packager/IOS/MHT_HW_TEST";
string outPath = isZs?"/Volumes/ELEMENTS/JieLing/Packager/IOS/exXcodePro_Release":"/Volumes/ELEMENTS/JieLing/Packager/IOS/exXcodePro_Test";
if (Directory.Exists(outPath))
{
Directory.Delete(outPath, 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.iOS;
// 调用开始打包
BuildPipeline.BuildPlayer(buildPlayerOptions);
2020-09-14 20:04:06 +08:00
Debug.Log("打包完成");
Debug.Log("导出工程路径:"+ outPath);
2020-09-18 17:44:02 +08:00
if (Directory.Exists(mainXcodePath)&& Directory.Exists(outPath))
2020-09-14 16:20:36 +08:00
{
Debug.Log("替换xcode资源");
Directory.Delete(mainXcodePath+"/Data", true);
Directory.Move(outPath+"/Data",mainXcodePath+"/Data");
Directory.Delete(mainXcodePath+"/Classes/Native", true);
Directory.Move(outPath+"/Classes/Native",mainXcodePath+"/Classes/Native");
}
2020-09-10 11:47:18 +08:00
}
}