|
@@ -109,7 +109,7 @@ namespace VEngine.Editor.Builds
|
|
|
bundle = bundle.Substring(0, i);
|
|
|
bundle = bundle.ToLower();
|
|
|
|
|
|
-
|
|
|
+ //以文件名标识分组
|
|
|
for (int j = 0; j < buildSetting.dirTypeList.Count; j++)
|
|
|
{
|
|
|
string str = buildSetting.dirTypeList[j];
|
|
@@ -127,6 +127,7 @@ namespace VEngine.Editor.Builds
|
|
|
}
|
|
|
|
|
|
});
|
|
|
+ //以子文件夹为单位分组
|
|
|
foreach (var dir in dirBundleList)
|
|
|
{
|
|
|
var dirPath = Path.Combine(Environment.CurrentDirectory, dir);
|
|
@@ -165,6 +166,7 @@ namespace VEngine.Editor.Builds
|
|
|
for (var i = 0; i < bundledAssets.Count; i++)
|
|
|
{
|
|
|
var asset = bundledAssets[i];
|
|
|
+ //去重
|
|
|
if (!pathWithAssets.TryGetValue(asset.path, out var ba))
|
|
|
{
|
|
|
pathWithAssets[asset.path] = asset;
|
|
@@ -183,6 +185,7 @@ namespace VEngine.Editor.Builds
|
|
|
{
|
|
|
var bundles = new List<ManifestBundle>();
|
|
|
var dictionary = new Dictionary<string, List<string>>();
|
|
|
+ //分组
|
|
|
foreach (var asset in bundledAssets)
|
|
|
{
|
|
|
if (!dictionary.TryGetValue(asset.bundle, out var assets))
|
|
@@ -199,9 +202,13 @@ namespace VEngine.Editor.Builds
|
|
|
assets.Add(asset.path);
|
|
|
}
|
|
|
|
|
|
- var outputPath = Settings.PlatformBuildPath;
|
|
|
+ var unityBuildPath = Settings.PlatformBuildPath;
|
|
|
+ if (!string.IsNullOrEmpty(GFGGame.LauncherConfig.resKey))
|
|
|
+ {
|
|
|
+ unityBuildPath = Settings.UnityBuildPath;
|
|
|
+ }
|
|
|
if (bundles.Count <= 0) return;
|
|
|
- var manifest = BuildPipeline.BuildAssetBundles(outputPath, bundles.ConvertAll(bundle =>
|
|
|
+ var manifest = BuildPipeline.BuildAssetBundles(unityBuildPath, bundles.ConvertAll(bundle =>
|
|
|
new AssetBundleBuild
|
|
|
{
|
|
|
assetNames = bundle.assets.ToArray(),
|
|
@@ -215,10 +222,11 @@ namespace VEngine.Editor.Builds
|
|
|
Debug.LogErrorFormat("Failed to build {0}.", name);
|
|
|
return;
|
|
|
}
|
|
|
- if (!string.IsNullOrEmpty(GFGGame.LauncherConfig.resKey))
|
|
|
- {
|
|
|
- CreateEncryptAssets(outputPath, outputPath, manifest, GFGGame.LauncherConfig.resKey);
|
|
|
- }
|
|
|
+ //if (!string.IsNullOrEmpty(GFGGame.LauncherConfig.resKey))
|
|
|
+ //{
|
|
|
+ // string buildPath = Settings.PlatformBuildPath;
|
|
|
+ // CreateEncryptAssets(unityBuildPath, buildPath, manifest, GFGGame.LauncherConfig.resKey);
|
|
|
+ //}
|
|
|
AfterBuildBundles(bundles, manifest);
|
|
|
}
|
|
|
|
|
@@ -228,16 +236,16 @@ namespace VEngine.Editor.Builds
|
|
|
/// </summary>
|
|
|
public static void CreateEncryptAssets(string bundlePackagePath, string encryptAssetPath, AssetBundleManifest manifest, string secretKey)
|
|
|
{
|
|
|
+ if (!Directory.Exists(encryptAssetPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(encryptAssetPath);
|
|
|
+ }
|
|
|
string[] assetBundles = manifest.GetAllAssetBundles();
|
|
|
foreach (string assetBundle in assetBundles)
|
|
|
{
|
|
|
string bundlePath = Path.Combine(bundlePackagePath, assetBundle);
|
|
|
byte[] encryptBytes = EncryptHelper.CreateEncryptData(bundlePath, secretKey);
|
|
|
- if (!Directory.Exists(encryptAssetPath))
|
|
|
- {
|
|
|
- Directory.CreateDirectory(encryptAssetPath);
|
|
|
- }
|
|
|
- using (FileStream fs = new FileStream(Path.Combine(bundlePackagePath, assetBundle), FileMode.OpenOrCreate))
|
|
|
+ using (FileStream fs = new FileStream(Path.Combine(encryptAssetPath, assetBundle), FileMode.OpenOrCreate))
|
|
|
{
|
|
|
fs.SetLength(0);
|
|
|
fs.Write(encryptBytes, 0, encryptBytes.Length);
|
|
@@ -245,6 +253,23 @@ namespace VEngine.Editor.Builds
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 创建加密的AssetBundle
|
|
|
+ /// </summary>
|
|
|
+ public static void CreateEncryptAsset(string unityBundlesPath, string bundlesPath, string unityBundle, string secretKey)
|
|
|
+ {
|
|
|
+ if (!Directory.Exists(bundlesPath))
|
|
|
+ {
|
|
|
+ Directory.CreateDirectory(bundlesPath);
|
|
|
+ }
|
|
|
+ string unityBundlePath = Path.Combine(unityBundlesPath, unityBundle);
|
|
|
+ byte[] encryptBytes = EncryptHelper.CreateEncryptData(unityBundlePath, secretKey);
|
|
|
+ using (FileStream fs = new FileStream(Path.Combine(bundlesPath, unityBundle), FileMode.OpenOrCreate))
|
|
|
+ {
|
|
|
+ fs.SetLength(0);
|
|
|
+ fs.Write(encryptBytes, 0, encryptBytes.Length);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private string GetOriginBundle(string assetBundle)
|
|
|
{
|
|
@@ -273,22 +298,12 @@ namespace VEngine.Editor.Builds
|
|
|
foreach (var assetBundle in assetBundles)
|
|
|
{
|
|
|
var originBundle = GetOriginBundle(assetBundle);
|
|
|
- var dependencies =
|
|
|
- Array.ConvertAll(manifest.GetAllDependencies(assetBundle), GetOriginBundle);
|
|
|
+ var dependencies = Array.ConvertAll(manifest.GetAllDependencies(assetBundle), GetOriginBundle);
|
|
|
if (nameWithBundles.TryGetValue(originBundle, out var manifestBundle))
|
|
|
{
|
|
|
manifestBundle.nameWithAppendHash = assetBundle;
|
|
|
- manifestBundle.dependencies =
|
|
|
- Array.ConvertAll(dependencies, input => nameWithBundles[input].id);
|
|
|
- var file = Settings.GetBuildPath(assetBundle);
|
|
|
- if (File.Exists(file))
|
|
|
- using (var stream = File.OpenRead(file))
|
|
|
- {
|
|
|
- manifestBundle.size = stream.Length;
|
|
|
- manifestBundle.crc = Utility.ComputeCRC32(stream);
|
|
|
- }
|
|
|
- else
|
|
|
- Debug.LogErrorFormat("File not found: {0}", file);
|
|
|
+ manifestBundle.dependencies = Array.ConvertAll(dependencies, input => nameWithBundles[input].id);
|
|
|
+
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -313,6 +328,20 @@ namespace VEngine.Editor.Builds
|
|
|
value.nameWithAppendHash != bundle.nameWithAppendHash)
|
|
|
{
|
|
|
newFiles.Add(bundle.nameWithAppendHash);
|
|
|
+ if (!string.IsNullOrEmpty(GFGGame.LauncherConfig.resKey))
|
|
|
+ {
|
|
|
+ string buildPath = Settings.PlatformBuildPath;
|
|
|
+ CreateEncryptAsset(Settings.UnityBuildPath, buildPath, bundle.nameWithAppendHash, GFGGame.LauncherConfig.resKey);
|
|
|
+ }
|
|
|
+ var file = Settings.GetBuildPath(bundle.nameWithAppendHash);
|
|
|
+ if (File.Exists(file))
|
|
|
+ using (var stream = File.OpenRead(file))
|
|
|
+ {
|
|
|
+ bundle.size = stream.Length;
|
|
|
+ bundle.crc = Utility.ComputeCRC32(stream);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ Debug.LogErrorFormat("File not found: {0}", file);
|
|
|
newSize += bundle.size;
|
|
|
}
|
|
|
|