208 lines
6.9 KiB
C#
208 lines
6.9 KiB
C#
using System.IO;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using BFEditor.Resource;
|
|
using System.Collections.Generic;
|
|
|
|
namespace BFEditor.Build
|
|
{
|
|
public static class BuildMenu
|
|
{
|
|
[MenuItem("打包工具/编译并加密lua代码", priority = 1)]
|
|
static void CompileLuaManually()
|
|
{
|
|
var succ = CompileScriptsUtils.CompileAndEncryptLua(true);
|
|
if (succ)
|
|
{
|
|
EditorUtility.DisplayDialog("提示", "编译并加密Lua成功", "确定");
|
|
}
|
|
else
|
|
{
|
|
EditorUtility.DisplayDialog("提示", "编译Lua失败", "确定");
|
|
}
|
|
}
|
|
|
|
[MenuItem("打包工具/打包前准备", priority = 101)]
|
|
static void PrepareForBuild()
|
|
{
|
|
CompileScriptsUtils.RegenerateXLuaCode(true); // 重新生产XLua
|
|
MainAtlasTools.UpdateMainAtlas(); // 更新atlas
|
|
LanguageAtlasTools.UpdateLanguageAtlas(); // 更新多语言atlas
|
|
MaterialTools.ClearFbxDefaultMaterial(); // 清理fbx默认材质
|
|
ShaderDependenciesTools.ClearAllShaderDependencies(); // 清理shader依赖资源
|
|
ShaderVariantsTools.GenerateVariantCollection(); // 收集shader变体
|
|
CompileScriptsUtils.CompileAndEncryptLua(true); // 编译并且加密lua代码
|
|
AssetBundleUtils.SetAllAssetsBundleName(); // 设置abName
|
|
}
|
|
|
|
[MenuItem("打包工具/AssetBundles/设置ABName", priority = 201)]
|
|
public static void SetAssetsInfoExcludeLua()
|
|
{
|
|
AssetBundleUtils.SetAllAssetsBundleName();
|
|
EditorUtility.DisplayDialog("提示", "设置ABName成功", "确定");
|
|
}
|
|
|
|
[MenuItem("打包工具/AssetBundles/AB Build(Debug)", priority = 202)]
|
|
public static void BuildAssetBundlesDebug()
|
|
{
|
|
var outputPath = Application.streamingAssetsPath;
|
|
var success = AssetBundleUtils.BuildAssetBundles(EditorUserBuildSettings.activeBuildTarget, outputPath, false,
|
|
BuildAssetBundleOptions.ChunkBasedCompression, new BF.BFLanguageInfo(new List<string> { "en", "cn"}));
|
|
if (success)
|
|
{
|
|
EditorUtility.DisplayDialog("提示", "Build AB(Debug)成功", "确定");
|
|
}
|
|
else
|
|
{
|
|
EditorUtility.DisplayDialog("提示", "Build AB(Debug)失败", "确定");
|
|
}
|
|
}
|
|
|
|
[MenuItem("打包工具/AssetBundles/AB Build(Release)", priority = 203)]
|
|
public static void BuildAssetBundlesRelease()
|
|
{
|
|
var outputPath = Application.streamingAssetsPath;
|
|
var success = AssetBundleUtils.BuildAssetBundles(EditorUserBuildSettings.activeBuildTarget, outputPath, true,
|
|
BuildAssetBundleOptions.ChunkBasedCompression, new BF.BFLanguageInfo(new List<string> { "en", "cn"}));
|
|
if (success)
|
|
{
|
|
EditorUtility.DisplayDialog("提示", "Build AB(Release)成功", "确定");
|
|
}
|
|
else
|
|
{
|
|
EditorUtility.DisplayDialog("提示", "Build AB(Release)失败", "确定");
|
|
}
|
|
}
|
|
|
|
[MenuItem("打包工具/AssetBundles/生成AB Config", priority = 204)]
|
|
static void GenerateABConfig()
|
|
{
|
|
var outputPath = Application.streamingAssetsPath;
|
|
AssetBundleUtils.GenerateAssetBundleConfig(outputPath, new BF.BFLanguageInfo(new List<string> { "en", "cn"}));
|
|
EditorUtility.DisplayDialog("提示", "生成配置文件", "确定");
|
|
}
|
|
|
|
[MenuItem("打包工具/AssetBundles/检查循环依赖", priority = 205)]
|
|
static void CheckABCycleDepend()
|
|
{
|
|
if (!ABCycleDependUtils.CheckABCycleDepend(Application.streamingAssetsPath))
|
|
{
|
|
EditorUtility.DisplayDialog("提示", "存在循环依赖", "确定");
|
|
}
|
|
else
|
|
{
|
|
EditorUtility.DisplayDialog("提示", "不存在循环依赖", "确定");
|
|
}
|
|
}
|
|
|
|
[MenuItem("打包工具/AssetBundles/生成热更资源", priority = 206)]
|
|
static void GenUpdateRes()
|
|
{
|
|
if(!Directory.Exists(Application.streamingAssetsPath))
|
|
{
|
|
Debug.Log("streamingAssets 不存在");
|
|
return;
|
|
}
|
|
|
|
var abccPath = Path.Combine(Application.streamingAssetsPath, "ab_config.bytes");
|
|
if (!File.Exists(abccPath))
|
|
{
|
|
Debug.LogError("ab_config.bytes不存在");
|
|
return;
|
|
}
|
|
|
|
var bytes = File.ReadAllBytes(abccPath);
|
|
var json = BF.AssetBundleConfigCollection.Decompress(bytes);
|
|
var abcc = BF.AssetBundleConfigCollection.Create(json);
|
|
var dirInfo = new DirectoryInfo(Application.streamingAssetsPath);
|
|
var files = dirInfo.GetFiles("*.*", SearchOption.AllDirectories);
|
|
var assetFiles = new List<string>();
|
|
var dirPath = Path.Combine(Application.streamingAssetsPath, "../../update");
|
|
if (!Directory.Exists(dirPath))
|
|
{
|
|
Directory.CreateDirectory(dirPath);
|
|
}
|
|
else
|
|
{
|
|
Directory.Delete(dirPath, true);
|
|
Directory.CreateDirectory(dirPath);
|
|
}
|
|
|
|
// 先设置版本号并保存下ab_config
|
|
abcc.version = "1.0.0";
|
|
var newJson = abcc.ToJson();
|
|
var newBytes = BF.AssetBundleConfigCollection.Compress(newJson);
|
|
File.WriteAllBytes(Path.Combine(dirPath, "ab_config.bytes"), newBytes);
|
|
|
|
// 初始化所有ab文件以及对应的md5
|
|
var mainConfig = abcc.mainConfigs;
|
|
Dictionary<string, string> md5Dict = new Dictionary<string, string>();
|
|
for (var i = 0; i < mainConfig.Count; ++i)
|
|
{
|
|
md5Dict.Add(mainConfig[i].assetBundlePath, mainConfig[i].md5);
|
|
}
|
|
|
|
int pathLength = Application.streamingAssetsPath.Length;
|
|
for (var i = 0; i < files.Length; ++i)
|
|
{
|
|
var fileInfo = files[i];
|
|
if (fileInfo.Extension.ToLower() == ".meta")
|
|
{
|
|
continue;
|
|
}
|
|
if (fileInfo.Name.EndsWith(".DS_Store"))
|
|
{
|
|
continue;
|
|
}
|
|
if (fileInfo.Name.CompareTo("ab_config.bytes") == 0)
|
|
{
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
var md5 = BF.GameLaunchUtils.GetFileMD5(fileInfo.FullName);
|
|
var fileName = fileInfo.FullName.Substring(pathLength + 1).Replace("\\", "/");
|
|
if (md5Dict.ContainsKey(fileName))
|
|
{
|
|
if (md5Dict[fileName].CompareTo(md5) == 0)
|
|
{
|
|
md5Dict.Remove(fileName);
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
File.Copy(fileInfo.FullName, Path.Combine(dirPath, md5));
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("md5校验失败:" + fileName);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (md5Dict.Count <= 0)
|
|
{
|
|
Debug.Log("热更资源生成完毕,版本号:" + abcc.version);
|
|
}
|
|
else
|
|
{
|
|
Directory.Delete(dirPath, true);
|
|
Debug.Log("热更资源生成失败,版本号:" + abcc.version);
|
|
}
|
|
}
|
|
|
|
[MenuItem("打包工具/打包窗口", priority = 301)]
|
|
static void ShowBuildWindow()
|
|
{
|
|
BuildProjectWindow.ShowWindow();
|
|
}
|
|
|
|
[MenuItem("打包工具/Android转换为AAB工程", priority = 401)]
|
|
static void ConvertAndroidStudioToAAB()
|
|
{
|
|
BuildAndroidUtils.ConvertToAAB();
|
|
}
|
|
}
|
|
}
|