mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
yoo2.2,9
yoo2.2,9
This commit is contained in:
@@ -49,8 +49,8 @@ namespace GameMain
|
||||
var downloader = GameModule.Resource.Downloader;
|
||||
|
||||
// 注册下载回调
|
||||
downloader.OnDownloadErrorCallback = OnDownloadErrorCallback;
|
||||
downloader.OnDownloadProgressCallback = OnDownloadProgressCallback;
|
||||
downloader.DownloadErrorCallback = OnDownloadErrorCallback;
|
||||
downloader.DownloadUpdateCallback = OnDownloadProgressCallback;
|
||||
downloader.BeginDownload();
|
||||
await downloader;
|
||||
|
||||
@@ -61,23 +61,23 @@ namespace GameMain
|
||||
ChangeState<ProcedureDownloadOver>(_procedureOwner);
|
||||
}
|
||||
|
||||
private void OnDownloadErrorCallback(string fileName, string error)
|
||||
private void OnDownloadErrorCallback(DownloadErrorData downloadErrorData)
|
||||
{
|
||||
UILoadTip.ShowMessageBox($"Failed to download file : {fileName}", MessageShowType.TwoButton,
|
||||
UILoadTip.ShowMessageBox($"Failed to download file : {downloadErrorData.FileName}", MessageShowType.TwoButton,
|
||||
LoadStyle.StyleEnum.Style_Default,
|
||||
() => { ChangeState<ProcedureCreateDownloader>(_procedureOwner); }, UnityEngine.Application.Quit);
|
||||
}
|
||||
|
||||
private void OnDownloadProgressCallback(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes)
|
||||
private void OnDownloadProgressCallback(DownloadUpdateData downloadUpdateData/*int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes*/)
|
||||
{
|
||||
string currentSizeMb = (currentDownloadBytes / 1048576f).ToString("f1");
|
||||
string totalSizeMb = (totalDownloadBytes / 1048576f).ToString("f1");
|
||||
string currentSizeMb = (downloadUpdateData.CurrentDownloadBytes / 1048576f).ToString("f1");
|
||||
string totalSizeMb = (downloadUpdateData.TotalDownloadBytes / 1048576f).ToString("f1");
|
||||
float progressPercentage = GameModule.Resource.Downloader.Progress * 100;
|
||||
string speed = Utility.File.GetLengthString((int)CurrentSpeed);
|
||||
|
||||
string line1 = Utility.Text.Format("正在更新,已更新 {0}/{1} ({2:F2}%)", currentDownloadCount, totalDownloadCount, progressPercentage);
|
||||
string line1 = Utility.Text.Format("正在更新,已更新 {0}/{1} ({2:F2}%)", downloadUpdateData.CurrentDownloadCount, downloadUpdateData.TotalDownloadCount, progressPercentage);
|
||||
string line2 = Utility.Text.Format("已更新大小 {0}MB/{1}MB", currentSizeMb, totalSizeMb);
|
||||
string line3 = Utility.Text.Format("当前网速 {0}/s,剩余时间 {1}", speed, GetRemainingTime(totalDownloadBytes, currentDownloadBytes, CurrentSpeed));
|
||||
string line3 = Utility.Text.Format("当前网速 {0}/s,剩余时间 {1}", speed, GetRemainingTime(downloadUpdateData.TotalDownloadBytes, downloadUpdateData.CurrentDownloadBytes, CurrentSpeed));
|
||||
|
||||
LoadUpdateLogic.Instance.DownProgressAction?.Invoke(GameModule.Resource.Downloader.Progress);
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, $"{line1}\n{line2}\n{line3}");
|
||||
|
@@ -73,7 +73,8 @@ namespace GameMain
|
||||
else if (playMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
Log.Info("Package resource mode detected.");
|
||||
ChangeState<ProcedureInitResources>(procedureOwner);
|
||||
// ChangeState<ProcedureInitResources>(procedureOwner);
|
||||
ChangeState<ProcedureUpdateVersion>(procedureOwner);
|
||||
}
|
||||
// 可更新模式。
|
||||
else if (playMode == EPlayMode.HostPlayMode ||
|
||||
|
@@ -34,7 +34,7 @@ namespace GameMain
|
||||
{
|
||||
//更新成功
|
||||
//注意:保存资源版本号作为下次默认启动的版本!
|
||||
operation.SavePackageVersion();
|
||||
// operation.SavePackageVersion();
|
||||
|
||||
if (GameModule.Resource.PlayMode == EPlayMode.WebPlayMode ||
|
||||
GameModule.Resource.UpdatableWhilePlaying)
|
||||
|
@@ -24,6 +24,10 @@ namespace GameMain
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, $"更新静态版本文件...");
|
||||
|
||||
EPlayMode playMode = GameModule.Resource.PlayMode;
|
||||
|
||||
if (playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
//检查设备是否能够访问互联网
|
||||
if (Application.internetReachability == NetworkReachability.NotReachable)
|
||||
{
|
||||
@@ -34,6 +38,7 @@ namespace GameMain
|
||||
GetStaticVersion().Forget,
|
||||
() => { ChangeState<ProcedureInitResources>(procedureOwner); });
|
||||
}
|
||||
}
|
||||
|
||||
UILoadMgr.Show(UIDefine.UILoadUpdate, LoadText.Instance.Label_RequestVersionIng);
|
||||
|
||||
@@ -45,8 +50,12 @@ namespace GameMain
|
||||
/// 向用户尝试更新静态版本。
|
||||
/// </summary>
|
||||
private async UniTaskVoid GetStaticVersion()
|
||||
{
|
||||
EPlayMode playMode = GameModule.Resource.PlayMode;
|
||||
if (playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(0.5f));
|
||||
}
|
||||
|
||||
var operation = GameModule.Resource.UpdatePackageVersionAsync();
|
||||
|
||||
@@ -59,9 +68,17 @@ namespace GameMain
|
||||
//线上最新版本operation.PackageVersion
|
||||
GameModule.Resource.PackageVersion = operation.PackageVersion;
|
||||
Log.Debug($"Updated package Version : from {GameModule.Resource.GetPackageVersion()} to {operation.PackageVersion}");
|
||||
|
||||
if (playMode == EPlayMode.HostPlayMode || playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
ChangeState<ProcedureUpdateManifest>(_procedureOwner);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChangeState<ProcedureInitResources>(_procedureOwner);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
OnGetStaticVersionError(operation.Error);
|
||||
}
|
||||
|
@@ -16,16 +16,8 @@ namespace TEngine.Editor.Inspector
|
||||
"WebPlayMode (WebGL运行模式)"
|
||||
};
|
||||
|
||||
private static readonly string[] _verifyLevelNames = new string[]
|
||||
{
|
||||
"Low (验证文件存在)",
|
||||
"Middle (验证文件大小)",
|
||||
"High (验证文件大小和CRC)"
|
||||
};
|
||||
|
||||
private SerializedProperty m_PlayMode = null;
|
||||
private SerializedProperty m_UpdatableWhilePlaying = null;
|
||||
private SerializedProperty m_VerifyLevel = null;
|
||||
private SerializedProperty m_Milliseconds = null;
|
||||
private SerializedProperty m_ReadWritePathType = null;
|
||||
private SerializedProperty m_MinUnloadUnusedAssetsInterval = null;
|
||||
@@ -39,7 +31,6 @@ namespace TEngine.Editor.Inspector
|
||||
private SerializedProperty m_FailedTryAgain = null;
|
||||
private SerializedProperty m_PackageName = null;
|
||||
private int m_ResourceModeIndex = 0;
|
||||
private int m_VerifyIndex = 0;
|
||||
|
||||
private int m_PackageNameIndex = 0;
|
||||
private string[] m_PackageNames;
|
||||
@@ -56,8 +47,6 @@ namespace TEngine.Editor.Inspector
|
||||
if (EditorApplication.isPlaying && IsPrefabInHierarchy(t.gameObject))
|
||||
{
|
||||
EditorGUILayout.EnumPopup("Resource Mode", t.PlayMode);
|
||||
|
||||
EditorGUILayout.EnumPopup("VerifyLevel", t.VerifyLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -67,13 +56,6 @@ namespace TEngine.Editor.Inspector
|
||||
m_ResourceModeIndex = selectedIndex;
|
||||
m_PlayMode.enumValueIndex = selectedIndex;
|
||||
}
|
||||
|
||||
int selectedVerifyIndex = EditorGUILayout.Popup("VerifyLevel", m_VerifyIndex, _verifyLevelNames);
|
||||
if (selectedVerifyIndex != m_VerifyIndex)
|
||||
{
|
||||
m_VerifyIndex = selectedVerifyIndex;
|
||||
m_VerifyLevel.enumValueIndex = selectedVerifyIndex;
|
||||
}
|
||||
}
|
||||
|
||||
m_ReadWritePathType.enumValueIndex = (int)(ReadWritePathType)EditorGUILayout.EnumPopup("Read-Write Path Type", t.ReadWritePathType);
|
||||
@@ -244,7 +226,6 @@ namespace TEngine.Editor.Inspector
|
||||
{
|
||||
m_PlayMode = serializedObject.FindProperty("playMode");
|
||||
m_UpdatableWhilePlaying = serializedObject.FindProperty("m_UpdatableWhilePlaying");
|
||||
m_VerifyLevel = serializedObject.FindProperty("VerifyLevel");
|
||||
m_Milliseconds = serializedObject.FindProperty("Milliseconds");
|
||||
m_ReadWritePathType = serializedObject.FindProperty("m_ReadWritePathType");
|
||||
m_MinUnloadUnusedAssetsInterval = serializedObject.FindProperty("m_MinUnloadUnusedAssetsInterval");
|
||||
@@ -265,7 +246,6 @@ namespace TEngine.Editor.Inspector
|
||||
private void RefreshModes()
|
||||
{
|
||||
m_ResourceModeIndex = m_PlayMode.enumValueIndex > 0 ? m_PlayMode.enumValueIndex : 0;
|
||||
m_VerifyIndex = m_VerifyLevel.enumValueIndex > 0 ? m_VerifyLevel.enumValueIndex : 0;
|
||||
}
|
||||
|
||||
private void RefreshTypeNames()
|
||||
|
@@ -136,7 +136,6 @@ namespace TEngine.Editor
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = buildPipeline.ToString();
|
||||
buildParameters.BuildTarget = buildTarget;
|
||||
buildParameters.BuildMode = EBuildMode.IncrementalBuild;
|
||||
buildParameters.PackageName = "DefaultPackage";
|
||||
buildParameters.PackageVersion = packageVersion;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
|
@@ -16,7 +16,7 @@ public class FileOffsetEncryption : IEncryptionServices
|
||||
}
|
||||
|
||||
int offset = 32;
|
||||
byte[] fileData = File.ReadAllBytes(fileInfo.FilePath);
|
||||
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||
var encryptedData = new byte[fileData.Length + offset];
|
||||
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class FileStreamEncryption : IEncryptionServices
|
||||
|
||||
}
|
||||
|
||||
var fileData = File.ReadAllBytes(fileInfo.FilePath);
|
||||
var fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||
for (int i = 0; i < fileData.Length; i++)
|
||||
{
|
||||
fileData[i] ^= BundleStream.KEY;
|
||||
|
@@ -26,11 +26,6 @@ namespace TEngine
|
||||
/// </summary>
|
||||
EPlayMode PlayMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 缓存系统启动时的验证级别。
|
||||
/// </summary>
|
||||
EVerifyLevel VerifyLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 同时下载的最大数目。
|
||||
/// </summary>
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using GameFramework.Runtime;
|
||||
using UnityEngine;
|
||||
@@ -21,10 +22,12 @@ namespace TEngine
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
}
|
||||
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_defaultHostServer}/{fileName}";
|
||||
}
|
||||
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_fallbackHostServer}/{fileName}";
|
||||
@@ -34,28 +37,48 @@ namespace TEngine
|
||||
/// <summary>
|
||||
/// 资源文件流加载解密类
|
||||
/// </summary>
|
||||
private class FileStreamDecryption : IDecryptionServices
|
||||
public class FileStreamDecryption : IDecryptionServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 同步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundle IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
managedStream = bundleStream;
|
||||
return AssetBundle.LoadFromStream(bundleStream, fileInfo.ConentCRC, GetManagedReadBufferSize());
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = bundleStream;
|
||||
decryptResult.Result = AssetBundle.LoadFromStream(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundleCreateRequest IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
||||
{
|
||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
managedStream = bundleStream;
|
||||
return AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.ConentCRC, GetManagedReadBufferSize());
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = bundleStream;
|
||||
decryptResult.CreateRequest = AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private static uint GetManagedReadBufferSize()
|
||||
@@ -64,29 +87,68 @@ namespace TEngine
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件偏移加密方式
|
||||
/// </summary>
|
||||
public class FileOffsetEncryption : IEncryptionServices
|
||||
{
|
||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||
{
|
||||
int offset = 32;
|
||||
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||
var encryptedData = new byte[fileData.Length + offset];
|
||||
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
|
||||
|
||||
EncryptResult result = new EncryptResult();
|
||||
result.Encrypted = true;
|
||||
result.EncryptedData = encryptedData;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件偏移加载解密类
|
||||
/// </summary>
|
||||
private class FileOffsetDecryption : IDecryptionServices
|
||||
public class FileOffsetDecryption : IDecryptionServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 同步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundle IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
||||
{
|
||||
managedStream = null;
|
||||
return AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.ConentCRC, GetFileOffset());
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = null;
|
||||
decryptResult.Result = AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步方式获取解密的资源包对象
|
||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||
/// </summary>
|
||||
AssetBundleCreateRequest IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo, out Stream managedStream)
|
||||
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
||||
{
|
||||
managedStream = null;
|
||||
return AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.ConentCRC, GetFileOffset());
|
||||
DecryptResult decryptResult = new DecryptResult();
|
||||
decryptResult.ManagedStream = null;
|
||||
decryptResult.CreateRequest = AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||
return decryptResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的字节数据
|
||||
/// </summary>
|
||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取解密的文本数据
|
||||
/// </summary>
|
||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private static ulong GetFileOffset()
|
||||
@@ -122,176 +184,4 @@ namespace TEngine
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件查询服务类
|
||||
/// </summary>
|
||||
public class GameQueryServices : IBuildinQueryServices
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询内置文件的时候,是否比对文件哈希值
|
||||
/// </summary>
|
||||
public static bool CompareFileCRC = false;
|
||||
|
||||
public bool Query(string packageName, string fileName, string fileCRC)
|
||||
{
|
||||
// 注意:fileName包含文件格式
|
||||
return StreamingAssetsHelper.FileExists(packageName, fileName, fileCRC);
|
||||
}
|
||||
}
|
||||
|
||||
public class StreamingAssetsDefine
|
||||
{
|
||||
/// <summary>
|
||||
/// 根目录名称(保持和YooAssets资源系统一致)
|
||||
/// </summary>
|
||||
public const string RootFolderName = "package";
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public sealed class StreamingAssetsHelper
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
}
|
||||
|
||||
public static bool FileExists(string packageName, string fileName, string fileCRC)
|
||||
{
|
||||
string filePath = Path.Combine(Application.streamingAssetsPath, StreamingAssetsDefine.RootFolderName, packageName, fileName);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
if (GameQueryServices.CompareFileCRC)
|
||||
{
|
||||
string crc32 = YooAsset.HashUtility.FileCRC32(filePath);
|
||||
return crc32 == fileCRC;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
public sealed class StreamingAssetsHelper
|
||||
{
|
||||
private class PackageQuery
|
||||
{
|
||||
public readonly Dictionary<string, BuildinFileManifest.Element> Elements = new Dictionary<string, BuildinFileManifest.Element>(1000);
|
||||
}
|
||||
|
||||
private static bool _isInit = false;
|
||||
private static readonly Dictionary<string, PackageQuery> _packages = new Dictionary<string, PackageQuery>(10);
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public static void Init()
|
||||
{
|
||||
if (_isInit == false)
|
||||
{
|
||||
_isInit = true;
|
||||
|
||||
var manifest = Resources.Load<BuildinFileManifest>("BuildinFileManifest");
|
||||
if (manifest != null)
|
||||
{
|
||||
foreach (var element in manifest.BuildinFiles)
|
||||
{
|
||||
if (_packages.TryGetValue(element.PackageName, out PackageQuery package) == false)
|
||||
{
|
||||
package = new PackageQuery();
|
||||
_packages.Add(element.PackageName, package);
|
||||
}
|
||||
package.Elements.Add(element.FileName, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件查询方法
|
||||
/// </summary>
|
||||
public static bool FileExists(string packageName, string fileName, string fileCRC32)
|
||||
{
|
||||
if (_isInit == false)
|
||||
Init();
|
||||
|
||||
if (_packages.TryGetValue(packageName, out PackageQuery package) == false)
|
||||
return false;
|
||||
|
||||
if (package.Elements.TryGetValue(fileName, out var element) == false)
|
||||
return false;
|
||||
|
||||
if (GameQueryServices.CompareFileCRC)
|
||||
{
|
||||
return element.FileCRC32 == fileCRC32;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
internal class PreprocessBuild : UnityEditor.Build.IPreprocessBuildWithReport
|
||||
{
|
||||
public int callbackOrder
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在构建应用程序前处理
|
||||
/// 原理:在构建APP之前,搜索StreamingAssets目录下的所有资源文件,然后将这些文件信息写入内置清单,内置清单存储在Resources文件夹下。
|
||||
/// </summary>
|
||||
public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
|
||||
{
|
||||
string saveFilePath = "Assets/AATemp/Resources/BuildinFileManifest.asset";
|
||||
if (File.Exists(saveFilePath))
|
||||
{
|
||||
File.Delete(saveFilePath);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
}
|
||||
|
||||
string folderPath = $"{Application.dataPath}/StreamingAssets/{StreamingAssetsDefine.RootFolderName}";
|
||||
DirectoryInfo root = new DirectoryInfo(folderPath);
|
||||
if (root.Exists == false)
|
||||
{
|
||||
Debug.LogWarning($"没有发现YooAsset内置目录 : {folderPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
var manifest = ScriptableObject.CreateInstance<BuildinFileManifest>();
|
||||
FileInfo[] files = root.GetFiles("*", SearchOption.AllDirectories);
|
||||
foreach (var fileInfo in files)
|
||||
{
|
||||
if (fileInfo.Extension == ".meta")
|
||||
continue;
|
||||
if (fileInfo.Name.StartsWith("PackageManifest_"))
|
||||
continue;
|
||||
|
||||
BuildinFileManifest.Element element = new BuildinFileManifest.Element();
|
||||
element.PackageName = fileInfo.Directory.Name;
|
||||
element.FileCRC32 = YooAsset.HashUtility.FileCRC32(fileInfo.FullName);
|
||||
element.FileName = fileInfo.Name;
|
||||
manifest.BuildinFiles.Add(element);
|
||||
}
|
||||
|
||||
if (Directory.Exists("Assets/AATemp/Resources") == false)
|
||||
Directory.CreateDirectory("Assets/AATemp/Resources");
|
||||
UnityEditor.AssetDatabase.CreateAsset(manifest, saveFilePath);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
Debug.Log($"一共{manifest.BuildinFiles.Count}个内置文件,内置资源清单保存成功 : {saveFilePath}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
@@ -29,11 +29,6 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public EPlayMode PlayMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件校验等级。
|
||||
/// </summary>
|
||||
public EVerifyLevel VerifyLevel { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
|
||||
/// </summary>
|
||||
@@ -210,9 +205,11 @@ namespace TEngine
|
||||
InitializationOperation initializationOperation = null;
|
||||
if (playMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
var buildResult = EditorSimulateModeHelper.SimulateBuild(packageName);
|
||||
var packageRoot = buildResult.PackageRootDirectory;
|
||||
var createParameters = new EditorSimulateModeParameters();
|
||||
createParameters.CacheBootVerifyLevel = VerifyLevel;
|
||||
createParameters.SimulateManifestFilePath = EditorSimulateModeHelper.SimulateBuild(EDefaultBuildPipeline.BuiltinBuildPipeline, packageName);
|
||||
createParameters.EditorFileSystemParameters = FileSystemParameters.CreateDefaultEditorFileSystemParameters(packageRoot);
|
||||
createParameters.EditorFileSystemParameters.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES,new FileOffsetEncryption());
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
@@ -220,8 +217,7 @@ namespace TEngine
|
||||
if (playMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
var createParameters = new OfflinePlayModeParameters();
|
||||
createParameters.CacheBootVerifyLevel = VerifyLevel;
|
||||
createParameters.DecryptionServices = new FileStreamDecryption();
|
||||
createParameters.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
@@ -230,31 +226,30 @@ namespace TEngine
|
||||
{
|
||||
string defaultHostServer = HostServerURL;
|
||||
string fallbackHostServer = FallbackHostServerURL;
|
||||
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
var createParameters = new HostPlayModeParameters();
|
||||
createParameters.CacheBootVerifyLevel = VerifyLevel;
|
||||
createParameters.DecryptionServices = new FileStreamDecryption();
|
||||
createParameters.BuildinQueryServices = new GameQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
createParameters.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters();
|
||||
createParameters.CacheFileSystemParameters = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices);
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
// WebGL运行模式
|
||||
if (playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
string defaultHostServer = HostServerURL;
|
||||
string fallbackHostServer = FallbackHostServerURL;
|
||||
var createParameters = new WebPlayModeParameters();
|
||||
createParameters.CacheBootVerifyLevel = VerifyLevel;
|
||||
createParameters.DecryptionServices = new FileStreamDecryption();
|
||||
createParameters.BuildinQueryServices = new GameQueryServices();
|
||||
createParameters.RemoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
#if UNITY_WEBGL && WEIXINMINIGAME && !UNITY_EDITOR
|
||||
string defaultHostServer = GetHostServerURL();
|
||||
string fallbackHostServer = GetHostServerURL();
|
||||
IRemoteServices remoteServices = new RemoteServices(defaultHostServer, fallbackHostServer);
|
||||
createParameters.WebServerFileSystemParameters = WechatFileSystemCreater.CreateWechatFileSystemParameters(remoteServices);
|
||||
#else
|
||||
createParameters.WebServerFileSystemParameters = FileSystemParameters.CreateDefaultWebServerFileSystemParameters();
|
||||
#endif
|
||||
initializationOperation = package.InitializeAsync(createParameters);
|
||||
}
|
||||
|
||||
await initializationOperation.ToUniTask();
|
||||
|
||||
Log.Info($"Init resource package version : {initializationOperation?.PackageVersion}");
|
||||
|
||||
return initializationOperation;
|
||||
}
|
||||
|
||||
@@ -268,9 +263,6 @@ namespace TEngine
|
||||
m_AssetPool = null;
|
||||
_assetLoadingList.Clear();
|
||||
_assetInfoMap.Clear();
|
||||
#if !UNITY_WEBGL
|
||||
YooAssets.Destroy();
|
||||
#endif
|
||||
}
|
||||
|
||||
#region Public Methods
|
||||
@@ -950,7 +942,7 @@ namespace TEngine
|
||||
{
|
||||
if (package is { InitializeStatus: EOperationStatus.Succeed })
|
||||
{
|
||||
package.UnloadUnusedAssets();
|
||||
package.UnloadUnusedAssetsAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -966,7 +958,7 @@ namespace TEngine
|
||||
{
|
||||
if (package is { InitializeStatus: EOperationStatus.Succeed })
|
||||
{
|
||||
package.ForceUnloadAllAssets();
|
||||
package.UnloadAllAssetsAsync();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@@ -95,11 +95,6 @@ namespace TEngine
|
||||
/// </summary>
|
||||
public bool UpdatableWhilePlaying => m_UpdatableWhilePlaying;
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件校验等级。
|
||||
/// </summary>
|
||||
public EVerifyLevel VerifyLevel = EVerifyLevel.Middle;
|
||||
|
||||
[SerializeField] private ReadWritePathType m_ReadWritePathType = ReadWritePathType.Unspecified;
|
||||
|
||||
/// <summary>
|
||||
@@ -297,7 +292,6 @@ namespace TEngine
|
||||
|
||||
m_ResourceManager.DefaultPackageName = PackageName;
|
||||
m_ResourceManager.PlayMode = PlayMode;
|
||||
m_ResourceManager.VerifyLevel = VerifyLevel;
|
||||
m_ResourceManager.Milliseconds = Milliseconds;
|
||||
m_ResourceManager.InstanceRoot = transform;
|
||||
m_ResourceManager.HostServerURL = SettingsUtils.GetResDownLoadPath();
|
||||
@@ -350,29 +344,27 @@ namespace TEngine
|
||||
/// <param name="timeout">超时时间。</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
/// <returns>请求远端包裹的最新版本操作句柄。</returns>
|
||||
public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = false, int timeout = 60,
|
||||
public RequestPackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = false, int timeout = 60,
|
||||
string customPackageName = "")
|
||||
{
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(PackageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
return package.UpdatePackageVersionAsync(appendTimeTicks, timeout);
|
||||
return package.RequestPackageVersionAsync(appendTimeTicks, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求并更新清单
|
||||
/// </summary>
|
||||
/// <param name="packageVersion">更新的包裹版本</param>
|
||||
/// <param name="autoSaveVersion">更新成功后自动保存版本号,作为下次初始化的版本。</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion,
|
||||
bool autoSaveVersion = true, int timeout = 60, string customPackageName = "")
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60, string customPackageName = "")
|
||||
{
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(PackageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
return package.UpdatePackageManifestAsync(packageVersion, autoSaveVersion, timeout);
|
||||
return package.UpdatePackageManifestAsync(packageVersion, timeout);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -404,12 +396,12 @@ namespace TEngine
|
||||
/// 清理包裹未使用的缓存文件。
|
||||
/// </summary>
|
||||
/// <param name="customPackageName">指定资源包的名称。不传使用默认资源包</param>
|
||||
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync(string customPackageName = "")
|
||||
public ClearCacheFilesOperation ClearUnusedCacheFilesAsync(string customPackageName = "")
|
||||
{
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(PackageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
return package.ClearUnusedCacheFilesAsync();
|
||||
return package.ClearCacheFilesAsync(EFileClearMode.ClearUnusedBundleFiles);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -421,7 +413,7 @@ namespace TEngine
|
||||
var package = string.IsNullOrEmpty(customPackageName)
|
||||
? YooAssets.GetPackage(PackageName)
|
||||
: YooAssets.GetPackage(customPackageName);
|
||||
package.ClearPackageSandbox();
|
||||
package.ClearCacheFilesAsync(EFileClearMode.ClearAllBundleFiles);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@@ -43,13 +43,6 @@ namespace TEngine
|
||||
/// <returns>是否操作成功。</returns>
|
||||
public bool UnSuspend(string location);
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否主场景。</returns>
|
||||
public bool IsMainScene(string location);
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景。
|
||||
/// </summary>
|
||||
|
@@ -84,16 +84,6 @@ namespace TEngine
|
||||
return _sceneModule.UnSuspend(location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否主场景。</returns>
|
||||
public bool IsMainScene(string location)
|
||||
{
|
||||
return _sceneModule.IsMainScene(location);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景。
|
||||
/// </summary>
|
||||
|
@@ -63,7 +63,7 @@ namespace TEngine
|
||||
Log.Warning($"Could not load subScene while already loaded. Scene: {location}");
|
||||
return subScene;
|
||||
}
|
||||
subScene = YooAssets.LoadSceneAsync(location, sceneMode, suspendLoad, (uint)priority);
|
||||
subScene = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None,suspendLoad, (uint)priority);
|
||||
|
||||
if (callBack != null)
|
||||
{
|
||||
@@ -88,7 +88,7 @@ namespace TEngine
|
||||
|
||||
_currentMainSceneName = location;
|
||||
|
||||
_currentMainScene = YooAssets.LoadSceneAsync(location, sceneMode, suspendLoad, (uint)priority);
|
||||
_currentMainScene = YooAssets.LoadSceneAsync(location, sceneMode, LocalPhysicsMode.None, suspendLoad, (uint)priority);
|
||||
|
||||
if (callBack != null)
|
||||
{
|
||||
@@ -169,30 +169,6 @@ namespace TEngine
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为主场景。
|
||||
/// </summary>
|
||||
/// <param name="location">场景资源定位地址。</param>
|
||||
/// <returns>是否主场景。</returns>
|
||||
public bool IsMainScene(string location)
|
||||
{
|
||||
if (_currentMainSceneName.Equals(location))
|
||||
{
|
||||
if (_currentMainScene != null)
|
||||
{
|
||||
return _currentMainScene.IsMainScene();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
_subScenes.TryGetValue(location, out SceneHandle subScene);
|
||||
if (subScene != null)
|
||||
{
|
||||
return subScene.IsMainScene();
|
||||
}
|
||||
Log.Warning($"IsMainScene invalid location:{location}");
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步卸载子场景。
|
||||
/// </summary>
|
||||
|
@@ -2,6 +2,496 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [2.2.9] - 2025-01-14
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#438) 修复了纯血鸿蒙加载本地文件失败的问题。
|
||||
- (#445) 修复了小游戏扩展文件系统脚本编译错误。
|
||||
|
||||
### Changed
|
||||
|
||||
- EditorSimulateModeHelper.SimulateBuild()方法变更
|
||||
|
||||
```csharp
|
||||
public static PackageInvokeBuildResult SimulateBuild(string packageName);
|
||||
```
|
||||
|
||||
## [2.2.8-preview] - 2025-01-03
|
||||
|
||||
新增了单元测试用例。
|
||||
|
||||
### Improvements
|
||||
|
||||
- EditorSimulateModeHelper.SimulateBuild()方法提供指定自定义构建类
|
||||
|
||||
```csharp
|
||||
public class EditorSimulateBuildParam
|
||||
{
|
||||
/// <summary>
|
||||
/// 模拟构建类所属程序集名称
|
||||
/// </summary>
|
||||
public string InvokeAssmeblyName = "YooAsset.Editor";
|
||||
|
||||
/// <summary>
|
||||
/// 模拟构建执行的类名全称
|
||||
/// 注意:类名必须包含命名空间!
|
||||
/// </summary>
|
||||
public string InvokeClassFullName = "YooAsset.Editor.AssetBundleSimulateBuilder";
|
||||
|
||||
/// <summary>
|
||||
/// 模拟构建执行的方法名称
|
||||
/// 注意:执行方法必须满足 BindingFlags.Public | BindingFlags.Static
|
||||
/// </summary>
|
||||
public string InvokeMethodName = "SimulateBuild";
|
||||
}
|
||||
```
|
||||
|
||||
- 文件清理方式新增清理缓存清单。
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 文件清理方式
|
||||
/// </summary>
|
||||
public enum EFileClearMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理所有清单
|
||||
/// </summary>
|
||||
ClearAllManifestFiles,
|
||||
|
||||
/// <summary>
|
||||
/// 清理未在使用的清单
|
||||
/// </summary>
|
||||
ClearUnusedManifestFiles,
|
||||
}
|
||||
```
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#426) 修复了鸿蒙next平台加载内置文件路径报错的问题。
|
||||
- (#428) 修复了鸿蒙next平台加载内置文件路径报错的问题。
|
||||
- (#434) 修复了2.2版本 catalog文件对Json格式原生文件不记录的问题。
|
||||
- (#435) 修复了WebGL平台调用MD5算法触发异常的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了视频打包规则。
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 打包视频文件
|
||||
/// </summary>
|
||||
[DisplayName("打包视频文件")]
|
||||
public class PackVideoFile : IPackRule
|
||||
```
|
||||
|
||||
### Changed
|
||||
|
||||
- 重命名FileSystemParameters.RootDirectory字段为PackageRoot
|
||||
- 重命名ResourcePackage.ClearCacheBundleFilesAsync()方法为ClearCacheFilesAsync()
|
||||
|
||||
## [2.2.7-preview] - 2024-12-30
|
||||
|
||||
### Improvements
|
||||
|
||||
- 重构了下载器的委托方法。
|
||||
|
||||
- YooAssetSettings配置文件新增Package Manifest Prefix参数。
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 资源清单前缀名称(默认为空)
|
||||
/// </summary>
|
||||
public string PackageManifestPrefix = string.Empty;
|
||||
```
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#422) 修复了同步加载场景的NotImplementedException异常报错。
|
||||
- (#418) 修复了web远程文件系统初始化不正确的问题
|
||||
- (#392) 修复了引擎版本代码兼容相关的警告。
|
||||
- (#332) 修复了当用户的设备中有特殊字符时,URL路径无法被正确识别的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增代码字段:AsyncOperationBase.PackageName
|
||||
|
||||
### Changed
|
||||
|
||||
- 重命名DownloaderOperation.OnDownloadOver()方法为DownloaderFinish()
|
||||
- 重命名DownloaderOperation.OnDownloadProgress()方法为DownloadUpdate()
|
||||
- 重命名DownloaderOperation.OnDownloadError()方法为DownloadError()
|
||||
- 重命名DownloaderOperation.OnStartDownloadFile()方法为DownloadFileBegin()
|
||||
|
||||
## [2.2.6-preview] - 2024-12-27
|
||||
|
||||
### Improvements
|
||||
|
||||
- 增强了对Steam平台DLC拓展包的支持。
|
||||
|
||||
```csharp
|
||||
// 新增参数关闭Catalog目录查询内置文件的功能
|
||||
var fileSystemParams = CreateDefaultBuildinFileSystemParameters();
|
||||
fileSystemParams .AddParameter(FileSystemParametersDefine.DISABLE_CATALOG_FILE, true);
|
||||
```
|
||||
|
||||
- 资源句柄基类提供了统一的Release方法。
|
||||
|
||||
```csharp
|
||||
public abstract class HandleBase : IEnumerator, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Release();
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源句柄
|
||||
/// </summary>
|
||||
public void Dispose();
|
||||
}
|
||||
```
|
||||
|
||||
- 优化了场景卸载逻辑。
|
||||
|
||||
```csharp
|
||||
//框架内不在区分主场景和附加场景。
|
||||
//场景卸载后自动释放资源句柄。
|
||||
```
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了Unity2020版本提示的脚本编译错误。
|
||||
- (#417) 修复了DefaultWebServerFileSystem文件系统内Catalog未起效的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增示例文件 GetCacheBundleSizeOperation.cs
|
||||
|
||||
可以获取指定Package的缓存资源总大小。
|
||||
|
||||
### Removed
|
||||
|
||||
- 移除了SceneHandle.IsMainScene()方法。
|
||||
|
||||
## [2.2.5-preview] - 2024-12-25
|
||||
|
||||
依赖的ScriptableBuildPipeline (SBP) 插件库版本切换为1.21.25版本!
|
||||
|
||||
重构了ResourceManager相关的核心代码,方便借助文件系统扩展和支持更复杂的需求!
|
||||
|
||||
### Editor
|
||||
|
||||
- 新增了编辑器模拟构建管线 EditorSimulateBuildPipeline
|
||||
- 移除了EBuildMode枚举类型,构建界面有变动。
|
||||
- IActiveRule分组激活接口新增GroupData类。
|
||||
|
||||
### Improvements
|
||||
|
||||
- 增加抖音小游戏文件系统,见扩展示例代码。
|
||||
|
||||
- 微信小游戏文件系统支持删除无用缓存文件和全部缓存文件。
|
||||
|
||||
- 资源构建管线现在默认剔除了Gizmos和编辑器资源。
|
||||
|
||||
- 优化了资源构建管线里资源收集速度。
|
||||
|
||||
资源收集速度提升100倍!
|
||||
|
||||
```csharp
|
||||
class BuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用资源依赖缓存数据库
|
||||
/// 说明:开启此项可以极大提高资源收集速度
|
||||
/// </summary>
|
||||
public bool UseAssetDependencyDB = false;
|
||||
}
|
||||
```
|
||||
|
||||
- WebPlayMode支持跨域加载。
|
||||
|
||||
```csharp
|
||||
// 创建默认的WebServer文件系统参数
|
||||
public static FileSystemParameters CreateDefaultWebServerFileSystemParameters(bool disableUnityWebCache = false)
|
||||
|
||||
// 创建默认的WebRemote文件系统参数(支持跨域加载)
|
||||
public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteServices remoteServices, bool disableUnityWebCache = false)
|
||||
```
|
||||
|
||||
- 编辑器模拟文件系统新增初始化参数:支持异步模拟加载帧数。
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 异步模拟加载最小帧数
|
||||
/// </summary>
|
||||
FileSystemParametersDefine.ASYNC_SIMULATE_MIN_FRAME
|
||||
|
||||
/// <summary>
|
||||
/// 异步模拟加载最大帧数
|
||||
/// </summary>
|
||||
FileSystemParametersDefine.ASYNC_SIMULATE_MAX_FRAME
|
||||
```
|
||||
|
||||
- 缓存文件系统新增初始化参数:支持设置下载器最大并发连接数和单帧最大请求数
|
||||
|
||||
```csharp
|
||||
var fileSystremParams = FileSystemParameters.CreateDefaultCacheFileSystemParameters();
|
||||
fileSystremParams .AddParameter(FileSystemParametersDefine.DOWNLOAD_MAX_CONCURRENCY, 99);
|
||||
fileSystremParams .AddParameter(FileSystemParametersDefine.DOWNLOAD_MAX_REQUEST_PER_FRAME, 10);
|
||||
```
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#349) 修复了在加载清单的时候,即使本地存在缓存文件还会去远端下载。
|
||||
- (#361) 修复了协程里等待的asset handle被release,会无限等待并输出警告信息。
|
||||
- (#359) 修复了SubAssetsHandle.GetSubAssetObject会获取到同名的主资源。
|
||||
- (#387) 修复了加密后文件哈希冲突的时候没有抛出异常错误。
|
||||
- (#404) 修复了Unity2022.3.8版本提示编译错误:Cannot resolve symbol 'AsyncInstantiateOperation'
|
||||
|
||||
### Added
|
||||
|
||||
- 新增示例文件 CopyBuildinManifestOperation.cs
|
||||
|
||||
- 新增示例文件 LoadGameObjectOperation.cs
|
||||
|
||||
- 新增了获取配置清单详情的方法
|
||||
|
||||
```csharp
|
||||
class ResourcePackage
|
||||
{
|
||||
public PackageDetails GetPackageDetails()
|
||||
}
|
||||
```
|
||||
|
||||
- 新增了获取所有资源信息的方法
|
||||
|
||||
```csharp
|
||||
class ResourcePackage
|
||||
{
|
||||
public AssetInfo[] GetAllAssetInfos()
|
||||
}
|
||||
```
|
||||
|
||||
- 新增了清理缓存文件的通用方法
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 文件清理方式
|
||||
/// </summary>
|
||||
public enum EFileClearMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理所有文件
|
||||
/// </summary>
|
||||
ClearAllBundleFiles = 1,
|
||||
/// <summary>
|
||||
/// 清理未在使用的文件
|
||||
/// </summary>
|
||||
ClearUnusedBundleFiles = 2,
|
||||
/// <summary>
|
||||
/// 清理指定标签的文件
|
||||
/// 说明:需要指定参数,可选:string, string[], List<string>
|
||||
/// </summary>
|
||||
ClearBundleFilesByTags = 3,
|
||||
}
|
||||
class ResourcePackage
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
/// <param name="clearMode">清理方式</param>
|
||||
/// <param name="clearParam">执行参数</param>
|
||||
public ClearCacheBundleFilesOperation ClearCacheBundleFilesAsync(EFileClearMode clearMode, object clearParam = null)
|
||||
}
|
||||
```
|
||||
|
||||
### Changed
|
||||
|
||||
- 修改了EditorSimulateModeHelper.SimulateBuild()方法
|
||||
|
||||
- 重命名ResourcePackage.GetAssetsInfoByTags()方法为GetAssetInfosByTags()
|
||||
|
||||
- 实例化对象方法增加激活参数。
|
||||
|
||||
```csharp
|
||||
public InstantiateOperation InstantiateAsync(bool actived = true)
|
||||
```
|
||||
|
||||
- 清单文件的版本提升到2.2.5版本
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 资源包裹的备注信息
|
||||
/// </summary>
|
||||
public string PackageNote;
|
||||
```
|
||||
|
||||
|
||||
### Removed
|
||||
|
||||
- 移除了HostPlayModeParameters.DeliveryFileSystemParameters字段
|
||||
- 移除了ResourcePackage.ClearAllBundleFilesAsync()方法
|
||||
- 移除了ResourcePackage.ClearUnusedBundleFilesAsync()方法
|
||||
- 移除了FileSystemParameters.CreateDefaultBuildinRawFileSystemParameters()方法
|
||||
- 移除了FileSystemParameters.CreateDefaultCacheRawFileSystemParameters()方法
|
||||
- 移除了枚举类型:EDefaultBuildPipeline
|
||||
- 移除了配置参数:YooAssetSettings.ManifestFileName
|
||||
|
||||
## [2.2.4-preview] - 2024-08-15
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了HostPlayMode初始化卡死的问题。
|
||||
|
||||
## [2.2.3-preview] - 2024-08-13
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#311) 修复了断点续传下载器极小概率报错 : “416 Range Not Satisfiable”
|
||||
|
||||
### Improvements
|
||||
|
||||
- 原生文件构建管线支持原生文件加密。
|
||||
|
||||
- HostPlayMode模式下内置文件系统初始化参数可以为空。
|
||||
|
||||
- 场景加载增加了LocalPhysicsMode参数来控制物理运行模式。
|
||||
|
||||
- 默认的内置文件系统和缓存文件系统增加解密方法。
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 创建默认的内置文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">内置文件的根路径</param>
|
||||
public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(IDecryptionServices decryptionServices, EFileVerifyLevel verifyLevel, string rootDirectory);
|
||||
|
||||
/// <summary>
|
||||
/// 创建默认的缓存文件系统参数
|
||||
/// </summary>
|
||||
/// <param name="remoteServices">远端资源地址查询服务类</param>
|
||||
/// <param name="decryptionServices">加密文件解密服务类</param>
|
||||
/// <param name="verifyLevel">缓存文件的校验等级</param>
|
||||
/// <param name="rootDirectory">文件系统的根目录</param>
|
||||
public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, IDecryptionServices decryptionServices, EFileVerifyLevel verifyLevel, string rootDirectory);
|
||||
```
|
||||
|
||||
## [2.2.2-preview] - 2024-07-31
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#321) 修复了在Unity2022里编辑器下离线模式运行失败的问题。
|
||||
- (#325) 修复了在Unity2019里编译报错问题。
|
||||
|
||||
## [2.2.1-preview] - 2024-07-10
|
||||
|
||||
统一了所有PlayMode的初始化逻辑,EditorSimulateMode和OfflinePlayMode初始化不再主动加载资源清单!
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了IFileSystem.ReadFileData方法,支持原生文件自定义获取文本和二进制数据。
|
||||
|
||||
### Improvements
|
||||
|
||||
- 优化了DefaultWebFileSystem和DefaultBuildFileSystem文件系统的内部初始化逻辑。
|
||||
|
||||
## [2.2.0-preview] - 2024-07-07
|
||||
|
||||
重构了运行时代码,新增了文件系统接口(IFileSystem)方便开发者扩展特殊需求。
|
||||
|
||||
新增微信小游戏文件系统示例代码,详细见Extension Sample/Runtime/WechatFileSystem
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了ResourcePackage.DestroyAsync方法
|
||||
|
||||
- 新增了FileSystemParameters类帮助初始化文件系统
|
||||
|
||||
内置了编辑器文件系统参数,内置文件系统参数,缓存文件系统参数,Web文件系统参数。
|
||||
|
||||
```csharp
|
||||
public class FileSystemParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件系统类
|
||||
/// </summary>
|
||||
public string FileSystemClass { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件系统的根目录
|
||||
/// </summary>
|
||||
public string RootDirectory { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 添加自定义参数
|
||||
/// </summary>
|
||||
public void AddParameter(string name, object value)
|
||||
}
|
||||
```
|
||||
|
||||
### Changed
|
||||
|
||||
- 重构了InitializeParameters初始化参数
|
||||
- 重命名YooAssets.DestroyPackage方法为RemovePackage
|
||||
- 重命名ResourcePackage.UpdatePackageVersionAsync方法为RequestPackageVersionAsync
|
||||
- 重命名ResourcePackage.UnloadUnusedAssets方法为UnloadUnusedAssetsAsync
|
||||
- 重命名ResourcePackage.ForceUnloadAllAssets方法为UnloadAllAssetsAsync
|
||||
- 重命名ResourcePackage.ClearUnusedCacheFilesAsync方法为ClearUnusedBundleFilesAsync
|
||||
- 重命名ResourcePackage.ClearAllCacheFilesAsync方法为ClearAllBundleFilesAsync
|
||||
|
||||
### Removed
|
||||
|
||||
- 移除了YooAssets.Destroy方法
|
||||
- 移除了YooAssets.SetDownloadSystemClearFileResponseCode方法
|
||||
- 移除了YooAssets.SetCacheSystemDisableCacheOnWebGL方法
|
||||
- 移除了ResourcePackage.GetPackageBuildinRootDirectory方法
|
||||
- 移除了ResourcePackage.GetPackageSandboxRootDirectory方法
|
||||
- 移除了ResourcePackage.ClearPackageSandbox方法
|
||||
- 移除了IBuildinQueryServices接口
|
||||
- 移除了IDeliveryLoadServices接口
|
||||
- 移除了IDeliveryQueryServices接口
|
||||
|
||||
|
||||
## [2.1.2] - 2024-05-16
|
||||
|
||||
SBP库依赖版本升级至2.1.3
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#236) 修复了资源配置界面AutoCollectShader复选框没有刷新的问题。
|
||||
- (#244) 修复了导入器在安卓平台导入本地下载的资源失败的问题。
|
||||
- (#268) 修复了挂起场景未解除状态前无法卸载的问题。
|
||||
- (#269) 优化场景挂起流程,支持中途取消挂起操作。
|
||||
- (#276) 修复了HostPlayMode模式下,如果内置清单是最新版本,每次运行都会触发拷贝行为。
|
||||
- (#289) 修复了Unity2019版本脚本IWebRequester编译报错。
|
||||
- (#295) 解决了在安卓移动平台,华为和三星真机上有极小概率加载资源包失败 : Unable to open archive file
|
||||
|
||||
### Added
|
||||
|
||||
- 新增GetAllCacheFileInfosOperation()获取缓存文件信息的方法。
|
||||
|
||||
- 新增LoadSceneSync()同步加载场景的方法。
|
||||
|
||||
- 新增IIgnoreRule接口,资源收集流程可以自定义。
|
||||
|
||||
- 新增IWechatQueryServices接口,用于微信平台本地文件查询。
|
||||
|
||||
后续将会通过虚拟文件系统来支持!
|
||||
|
||||
### Changed
|
||||
|
||||
- 调整了UnloadSceneOperation代码里场景的卸载顺序。
|
||||
|
||||
### Improvements
|
||||
|
||||
- 优化了资源清单的解析过程。
|
||||
- 移除资源包名里的空格字符。
|
||||
- 支持华为鸿蒙系统。
|
||||
|
||||
## [2.1.1] - 2024-01-17
|
||||
|
||||
### Fixed
|
||||
|
@@ -22,7 +22,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public static string GetStreamingAssetsRoot()
|
||||
{
|
||||
return $"{Application.dataPath}/StreamingAssets/{YooAssetSettingsData.Setting.DefaultYooFolderName}/";
|
||||
return YooAssetSettingsData.GetYooEditorBuildinRoot();
|
||||
}
|
||||
}
|
||||
}
|
@@ -18,18 +18,6 @@ namespace YooAsset.Editor
|
||||
EditorPrefs.SetInt(key, (int)buildPipeline);
|
||||
}
|
||||
|
||||
// EBuildMode
|
||||
public static EBuildMode GetPackageBuildMode(string packageName, EBuildPipeline buildPipeline)
|
||||
{
|
||||
string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EBuildMode)}";
|
||||
return (EBuildMode)EditorPrefs.GetInt(key, (int)EBuildMode.ForceRebuild);
|
||||
}
|
||||
public static void SetPackageBuildMode(string packageName, EBuildPipeline buildPipeline, EBuildMode buildMode)
|
||||
{
|
||||
string key = $"{Application.productName}_{packageName}_{buildPipeline}_{nameof(EBuildMode)}";
|
||||
EditorPrefs.SetInt(key, (int)buildMode);
|
||||
}
|
||||
|
||||
// ECompressOption
|
||||
public static ECompressOption GetPackageCompressOption(string packageName, EBuildPipeline buildPipeline)
|
||||
{
|
||||
@@ -89,5 +77,29 @@ namespace YooAsset.Editor
|
||||
string key = $"{Application.productName}_{packageName}_{buildPipeline}_EncyptionClassName";
|
||||
EditorPrefs.SetString(key, encyptionClassName);
|
||||
}
|
||||
|
||||
// ClearBuildCache
|
||||
public static bool GetPackageClearBuildCache(string packageName, EBuildPipeline buildPipeline)
|
||||
{
|
||||
string key = $"{Application.productName}_{packageName}_{buildPipeline}_ClearBuildCache";
|
||||
return EditorPrefs.GetInt(key, 0) > 0;
|
||||
}
|
||||
public static void SetPackageClearBuildCache(string packageName, EBuildPipeline buildPipeline, bool clearBuildCache)
|
||||
{
|
||||
string key = $"{Application.productName}_{packageName}_{buildPipeline}_ClearBuildCache";
|
||||
EditorPrefs.SetInt(key, clearBuildCache ? 1 : 0);
|
||||
}
|
||||
|
||||
// UseAssetDependencyDB
|
||||
public static bool GetPackageUseAssetDependencyDB(string packageName, EBuildPipeline buildPipeline)
|
||||
{
|
||||
string key = $"{Application.productName}_{packageName}_{buildPipeline}_UseAssetDependencyDB";
|
||||
return EditorPrefs.GetInt(key, 0) > 0;
|
||||
}
|
||||
public static void SetPackageUseAssetDependencyDB(string packageName, EBuildPipeline buildPipeline, bool useAssetDependencyDB)
|
||||
{
|
||||
string key = $"{Application.productName}_{packageName}_{buildPipeline}_UseAssetDependencyDB";
|
||||
EditorPrefs.SetInt(key, useAssetDependencyDB ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
@@ -69,6 +69,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
_pipelineMenu = new ToolbarMenu();
|
||||
_pipelineMenu.style.width = 200;
|
||||
_pipelineMenu.menu.AppendAction(EBuildPipeline.EditorSimulateBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.EditorSimulateBuildPipeline);
|
||||
_pipelineMenu.menu.AppendAction(EBuildPipeline.BuiltinBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.BuiltinBuildPipeline);
|
||||
_pipelineMenu.menu.AppendAction(EBuildPipeline.ScriptableBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.ScriptableBuildPipeline);
|
||||
_pipelineMenu.menu.AppendAction(EBuildPipeline.RawFileBuildPipeline.ToString(), PipelineMenuAction, PipelineMenuFun, EBuildPipeline.RawFileBuildPipeline);
|
||||
@@ -93,7 +94,11 @@ namespace YooAsset.Editor
|
||||
_pipelineMenu.text = _buildPipeline.ToString();
|
||||
|
||||
var buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
if (_buildPipeline == EBuildPipeline.BuiltinBuildPipeline)
|
||||
if (_buildPipeline == EBuildPipeline.EditorSimulateBuildPipeline)
|
||||
{
|
||||
var viewer = new EditorSimulateBuildPipelineViewer(_buildPackage, buildTarget, _container);
|
||||
}
|
||||
else if (_buildPipeline == EBuildPipeline.BuiltinBuildPipeline)
|
||||
{
|
||||
var viewer = new BuiltinBuildPipelineViewer(_buildPackage, buildTarget, _container);
|
||||
}
|
||||
|
@@ -8,87 +8,37 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 模拟构建
|
||||
/// </summary>
|
||||
public static string SimulateBuild(string buildPipelineName, string packageName)
|
||||
public static PackageInvokeBuildResult SimulateBuild(PackageInvokeBuildParam buildParam)
|
||||
{
|
||||
if (buildPipelineName == EBuildPipeline.BuiltinBuildPipeline.ToString())
|
||||
string packageName = buildParam.PackageName;
|
||||
string buildPipelineName = buildParam.BuildPipelineName;
|
||||
|
||||
if (buildPipelineName == "EditorSimulateBuildPipeline")
|
||||
{
|
||||
BuiltinBuildParameters buildParameters = new BuiltinBuildParameters();
|
||||
var buildParameters = new EditorSimulateBuildParameters();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = buildPipelineName;
|
||||
buildParameters.BuildPipeline = EBuildPipeline.EditorSimulateBuildPipeline.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle;
|
||||
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
buildParameters.BuildMode = EBuildMode.SimulateBuild;
|
||||
buildParameters.PackageName = packageName;
|
||||
buildParameters.PackageVersion = "Simulate";
|
||||
buildParameters.FileNameStyle = EFileNameStyle.HashName;
|
||||
buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None;
|
||||
buildParameters.BuildinFileCopyParams = string.Empty;
|
||||
|
||||
BuiltinBuildPipeline pipeline = new BuiltinBuildPipeline();
|
||||
var buildResult = pipeline.Run(buildParameters, false);
|
||||
var pipeline = new EditorSimulateBuildPipeline();
|
||||
BuildResult buildResult = pipeline.Run(buildParameters, false);
|
||||
if (buildResult.Success)
|
||||
{
|
||||
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string manifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}";
|
||||
return manifestFilePath;
|
||||
var reulst = new PackageInvokeBuildResult();
|
||||
reulst.PackageRootDirectory = buildResult.OutputPackageDirectory;
|
||||
return reulst;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (buildPipelineName == EBuildPipeline.ScriptableBuildPipeline.ToString())
|
||||
{
|
||||
ScriptableBuildParameters buildParameters = new ScriptableBuildParameters();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = buildPipelineName;
|
||||
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
buildParameters.BuildMode = EBuildMode.SimulateBuild;
|
||||
buildParameters.PackageName = packageName;
|
||||
buildParameters.PackageVersion = "Simulate";
|
||||
buildParameters.FileNameStyle = EFileNameStyle.HashName;
|
||||
buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None;
|
||||
buildParameters.BuildinFileCopyParams = string.Empty;
|
||||
|
||||
ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline();
|
||||
var buildResult = pipeline.Run(buildParameters, true);
|
||||
if (buildResult.Success)
|
||||
{
|
||||
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string manifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}";
|
||||
return manifestFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (buildPipelineName == EBuildPipeline.RawFileBuildPipeline.ToString())
|
||||
{
|
||||
RawFileBuildParameters buildParameters = new RawFileBuildParameters();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = buildPipelineName;
|
||||
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
buildParameters.BuildMode = EBuildMode.SimulateBuild;
|
||||
buildParameters.PackageName = packageName;
|
||||
buildParameters.PackageVersion = "Simulate";
|
||||
buildParameters.FileNameStyle = EFileNameStyle.HashName;
|
||||
buildParameters.BuildinFileCopyOption = EBuildinFileCopyOption.None;
|
||||
buildParameters.BuildinFileCopyParams = string.Empty;
|
||||
|
||||
RawFileBuildPipeline pipeline = new RawFileBuildPipeline();
|
||||
var buildResult = pipeline.Run(buildParameters, true);
|
||||
if (buildResult.Success)
|
||||
{
|
||||
string manifestFileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string manifestFilePath = $"{buildResult.OutputPackageDirectory}/{manifestFileName}";
|
||||
return manifestFilePath;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
Debug.LogError(buildResult.ErrorInfo);
|
||||
throw new System.Exception($"{nameof(EditorSimulateBuildPipeline)} build failed !");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@@ -56,6 +56,7 @@ namespace YooAsset.Editor
|
||||
public string EncryptedFilePath { set; get; }
|
||||
#endregion
|
||||
|
||||
private readonly HashSet<string> _assetPaths = new HashSet<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 参与构建的资源列表
|
||||
@@ -84,9 +85,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public void PackAsset(BuildAssetInfo buildAsset)
|
||||
{
|
||||
if (IsContainsAsset(buildAsset.AssetInfo.AssetPath))
|
||||
throw new System.Exception($"Should never get here ! Asset is existed : {buildAsset.AssetInfo.AssetPath}");
|
||||
string assetPath = buildAsset.AssetInfo.AssetPath;
|
||||
if (_assetPaths.Contains(assetPath))
|
||||
throw new System.Exception($"Should never get here ! Asset is existed : {assetPath}");
|
||||
|
||||
_assetPaths.Add(assetPath);
|
||||
MainAssets.Add(buildAsset);
|
||||
}
|
||||
|
||||
@@ -95,14 +98,7 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IsContainsAsset(string assetPath)
|
||||
{
|
||||
foreach (var buildAsset in MainAssets)
|
||||
{
|
||||
if (buildAsset.AssetInfo.AssetPath == assetPath)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return _assetPaths.Contains(assetPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -22,20 +22,20 @@ namespace YooAsset.Editor
|
||||
public string BuildinFileRoot;
|
||||
|
||||
/// <summary>
|
||||
/// 构建管线
|
||||
/// 构建管线名称
|
||||
/// </summary>
|
||||
public string BuildPipeline;
|
||||
|
||||
/// <summary>
|
||||
/// 构建资源包类型
|
||||
/// </summary>
|
||||
public int BuildBundleType;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的平台
|
||||
/// </summary>
|
||||
public BuildTarget BuildTarget;
|
||||
|
||||
/// <summary>
|
||||
/// 构建模式
|
||||
/// </summary>
|
||||
public EBuildMode BuildMode;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的包裹名称
|
||||
/// </summary>
|
||||
@@ -46,9 +46,24 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string PackageVersion;
|
||||
|
||||
/// <summary>
|
||||
/// 构建的包裹备注
|
||||
/// </summary>
|
||||
public string PackageNote;
|
||||
|
||||
/// <summary>
|
||||
/// 是否启用共享资源打包
|
||||
/// 清空构建缓存文件
|
||||
/// </summary>
|
||||
public bool ClearBuildCacheFiles = false;
|
||||
|
||||
/// <summary>
|
||||
/// 使用资源依赖缓存数据库
|
||||
/// 说明:开启此项可以极大提高资源收集速度
|
||||
/// </summary>
|
||||
public bool UseAssetDependencyDB = false;
|
||||
|
||||
/// <summary>
|
||||
/// 启用共享资源打包
|
||||
/// </summary>
|
||||
public bool EnableSharePackRule = false;
|
||||
|
||||
@@ -60,12 +75,12 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 资源包名称样式
|
||||
/// </summary>
|
||||
public EFileNameStyle FileNameStyle;
|
||||
public EFileNameStyle FileNameStyle = EFileNameStyle.HashName;
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件的拷贝选项
|
||||
/// </summary>
|
||||
public EBuildinFileCopyOption BuildinFileCopyOption;
|
||||
public EBuildinFileCopyOption BuildinFileCopyOption = EBuildinFileCopyOption.None;
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件的拷贝参数
|
||||
@@ -95,32 +110,12 @@ namespace YooAsset.Editor
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
// 检测是否有未保存场景
|
||||
if (BuildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
if (EditorTools.HasDirtyScenes())
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.FoundUnsavedScene, "Found unsaved scene !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
|
||||
// 检测构建参数合法性
|
||||
if (BuildTarget == BuildTarget.NoTarget)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.NoBuildTarget, "Please select the build target platform !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (string.IsNullOrEmpty(PackageName))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageNameIsNullOrEmpty, "Package name is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (string.IsNullOrEmpty(PackageVersion))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageVersionIsNullOrEmpty, "Package version is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (string.IsNullOrEmpty(BuildOutputRoot))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildOutputRootIsNullOrEmpty, "Build output root is null or empty !");
|
||||
@@ -131,33 +126,31 @@ namespace YooAsset.Editor
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildinFileRootIsNullOrEmpty, "Buildin file root is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
// 强制构建删除包裹目录
|
||||
if (BuildMode == EBuildMode.ForceRebuild)
|
||||
if (string.IsNullOrEmpty(BuildPipeline))
|
||||
{
|
||||
string packageRootDirectory = GetPackageRootDirectory();
|
||||
if (EditorTools.DeleteDirectory(packageRootDirectory))
|
||||
{
|
||||
BuildLogger.Log($"Delete package root directory: {packageRootDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
// 检测包裹输出目录是否存在
|
||||
if (BuildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
string packageOutputDirectory = GetPackageOutputDirectory();
|
||||
if (Directory.Exists(packageOutputDirectory))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageOutputDirectoryExists, $"Package outout directory exists: {packageOutputDirectory}");
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineIsNullOrEmpty, "Build pipeline is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (BuildBundleType == (int)EBuildBundleType.Unknown)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildBundleTypeIsUnknown, $"Build bundle type is unknown {BuildBundleType} !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (string.IsNullOrEmpty(PackageName))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageNameIsNullOrEmpty, "Package name is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (string.IsNullOrEmpty(PackageVersion))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageVersionIsNullOrEmpty, "Package version is null or empty !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
// 如果输出目录不存在
|
||||
string pipelineOutputDirectory = GetPipelineOutputDirectory();
|
||||
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
|
||||
// 设置默认备注信息
|
||||
if (string.IsNullOrEmpty(PackageNote))
|
||||
{
|
||||
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
|
||||
PackageNote = DateTime.Now.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -12,19 +12,22 @@ namespace YooAsset.Editor
|
||||
|
||||
public abstract class TaskCreateManifest
|
||||
{
|
||||
private readonly Dictionary<string, int> _cachedBundleID = new Dictionary<string, int>(10000);
|
||||
private readonly Dictionary<string, int> _cachedBundleIndexIDs = new Dictionary<string, int>(10000);
|
||||
private readonly Dictionary<int, HashSet<string>> _cacheBundleTags = new Dictionary<int, HashSet<string>>(10000);
|
||||
|
||||
/// <summary>
|
||||
/// 创建补丁清单文件到输出目录
|
||||
/// </summary>
|
||||
protected void CreateManifestFile(BuildContext context)
|
||||
protected void CreateManifestFile(bool processBundleDepends, bool processBundleTags, BuildContext context)
|
||||
{
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
|
||||
// 检测资源包哈希冲突
|
||||
CheckBundleHashConflict(buildMapContext);
|
||||
|
||||
// 创建新补丁清单
|
||||
PackageManifest manifest = new PackageManifest();
|
||||
manifest.FileVersion = YooAssetSettings.ManifestFileVersion;
|
||||
@@ -32,20 +35,24 @@ namespace YooAsset.Editor
|
||||
manifest.LocationToLower = buildMapContext.Command.LocationToLower;
|
||||
manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
|
||||
manifest.OutputNameStyle = (int)buildParameters.FileNameStyle;
|
||||
manifest.BuildBundleType = buildParameters.BuildBundleType;
|
||||
manifest.BuildPipeline = buildParameters.BuildPipeline;
|
||||
manifest.PackageName = buildParameters.PackageName;
|
||||
manifest.PackageVersion = buildParameters.PackageVersion;
|
||||
manifest.BundleList = GetAllPackageBundle(buildMapContext);
|
||||
manifest.AssetList = GetAllPackageAsset(buildMapContext);
|
||||
manifest.PackageNote = buildParameters.PackageNote;
|
||||
manifest.AssetList = CreatePackageAssetList(buildMapContext);
|
||||
manifest.BundleList = CreatePackageBundleList(buildMapContext);
|
||||
|
||||
// 处理资源清单的ID数据
|
||||
ProcessPacakgeIDs(manifest);
|
||||
|
||||
if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
// 处理资源包的依赖列表
|
||||
if (processBundleDepends)
|
||||
ProcessBundleDepends(context, manifest);
|
||||
|
||||
// 处理资源包的标签集合
|
||||
if (processBundleTags)
|
||||
ProcessBundleTags(manifest);
|
||||
}
|
||||
|
||||
// 创建补丁清单文本文件
|
||||
{
|
||||
@@ -61,7 +68,7 @@ namespace YooAsset.Editor
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
ManifestTools.SerializeToBinary(filePath, manifest);
|
||||
packageHash = HashUtility.FileMD5(filePath);
|
||||
packageHash = HashUtility.FileCRC32(filePath);
|
||||
BuildLogger.Log($"Create package manifest file: {filePath}");
|
||||
|
||||
ManifestContext manifestContext = new ManifestContext();
|
||||
@@ -87,15 +94,37 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测资源包哈希冲突
|
||||
/// </summary>
|
||||
private void CheckBundleHashConflict(BuildMapContext buildMapContext)
|
||||
{
|
||||
// 说明:在特殊情况下,例如某些文件加密算法会导致加密后的文件哈希值冲突!
|
||||
// 说明:二进制完全相同的原生文件也会冲突!
|
||||
HashSet<string> guids = new HashSet<string>();
|
||||
foreach (var bundleInfo in buildMapContext.Collection)
|
||||
{
|
||||
if (guids.Contains(bundleInfo.PackageFileHash))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BundleHashConflict, $"Bundle hash conflict : {bundleInfo.BundleName}");
|
||||
throw new Exception(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
guids.Add(bundleInfo.PackageFileHash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包的依赖集合
|
||||
/// </summary>
|
||||
protected abstract string[] GetBundleDepends(BuildContext context, string bundleName);
|
||||
|
||||
/// <summary>
|
||||
/// 获取主资源对象列表
|
||||
/// 创建资源对象列表
|
||||
/// </summary>
|
||||
private List<PackageAsset> GetAllPackageAsset(BuildMapContext buildMapContext)
|
||||
private List<PackageAsset> CreatePackageAssetList(BuildMapContext buildMapContext)
|
||||
{
|
||||
List<PackageAsset> result = new List<PackageAsset>(1000);
|
||||
foreach (var bundleInfo in buildMapContext.Collection)
|
||||
@@ -108,17 +137,20 @@ namespace YooAsset.Editor
|
||||
packageAsset.AssetPath = assetInfo.AssetInfo.AssetPath;
|
||||
packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetInfo.AssetGUID : string.Empty;
|
||||
packageAsset.AssetTags = assetInfo.AssetTags.ToArray();
|
||||
packageAsset.BundleID = GetCachedBundleID(assetInfo.BundleName);
|
||||
packageAsset.BundleNameInEditor = assetInfo.BundleName;
|
||||
result.Add(packageAsset);
|
||||
}
|
||||
}
|
||||
|
||||
// 按照AssetPath排序
|
||||
result.Sort((a, b) => a.AssetPath.CompareTo(b.AssetPath));
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包列表
|
||||
/// 创建资源包列表
|
||||
/// </summary>
|
||||
private List<PackageBundle> GetAllPackageBundle(BuildMapContext buildMapContext)
|
||||
private List<PackageBundle> CreatePackageBundleList(BuildMapContext buildMapContext)
|
||||
{
|
||||
List<PackageBundle> result = new List<PackageBundle>(1000);
|
||||
foreach (var bundleInfo in buildMapContext.Collection)
|
||||
@@ -127,14 +159,28 @@ namespace YooAsset.Editor
|
||||
result.Add(packageBundle);
|
||||
}
|
||||
|
||||
// 注意:缓存资源包索引
|
||||
for (int index = 0; index < result.Count; index++)
|
||||
{
|
||||
string bundleName = result[index].BundleName;
|
||||
_cachedBundleID.Add(bundleName, index);
|
||||
// 按照BundleName排序
|
||||
result.Sort((a, b) => a.BundleName.CompareTo(b.BundleName));
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
/// <summary>
|
||||
/// 处理资源清单的ID数据
|
||||
/// </summary>
|
||||
private void ProcessPacakgeIDs(PackageManifest manifest)
|
||||
{
|
||||
// 注意:优先缓存资源包索引
|
||||
for (int index = 0; index < manifest.BundleList.Count; index++)
|
||||
{
|
||||
string bundleName = manifest.BundleList[index].BundleName;
|
||||
_cachedBundleIndexIDs.Add(bundleName, index);
|
||||
}
|
||||
|
||||
foreach (var packageAsset in manifest.AssetList)
|
||||
{
|
||||
string bundleName = packageAsset.BundleNameInEditor;
|
||||
packageAsset.BundleID = GetCachedBundleIndexID(bundleName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,12 +191,12 @@ namespace YooAsset.Editor
|
||||
// 查询引擎生成的资源包依赖关系,然后记录到清单
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
int mainBundleID = GetCachedBundleID(packageBundle.BundleName);
|
||||
int mainBundleID = GetCachedBundleIndexID(packageBundle.BundleName);
|
||||
var depends = GetBundleDepends(context, packageBundle.BundleName);
|
||||
List<int> dependIDs = new List<int>(depends.Length);
|
||||
foreach (var dependBundleName in depends)
|
||||
{
|
||||
int bundleID = GetCachedBundleID(dependBundleName);
|
||||
int bundleID = GetCachedBundleIndexID(dependBundleName);
|
||||
if (bundleID != mainBundleID)
|
||||
dependIDs.Add(bundleID);
|
||||
}
|
||||
@@ -171,18 +217,21 @@ namespace YooAsset.Editor
|
||||
CacheBundleTags(bundleID, assetTags);
|
||||
|
||||
var packageBundle = manifest.BundleList[bundleID];
|
||||
if (packageBundle.DependIDs != null)
|
||||
{
|
||||
foreach (var dependBundleID in packageBundle.DependIDs)
|
||||
{
|
||||
CacheBundleTags(dependBundleID, assetTags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int index = 0; index < manifest.BundleList.Count; index++)
|
||||
{
|
||||
var packageBundle = manifest.BundleList[index];
|
||||
if (_cacheBundleTags.ContainsKey(index))
|
||||
if (_cacheBundleTags.TryGetValue(index, out var value))
|
||||
{
|
||||
packageBundle.Tags = _cacheBundleTags[index].ToArray();
|
||||
packageBundle.Tags = value.ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -205,13 +254,13 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源包的索引ID
|
||||
/// 获取缓存的资源包的索引ID
|
||||
/// </summary>
|
||||
private int GetCachedBundleID(string bundleName)
|
||||
private int GetCachedBundleIndexID(string bundleName)
|
||||
{
|
||||
if (_cachedBundleID.TryGetValue(bundleName, out int value) == false)
|
||||
if (_cachedBundleIndexIDs.TryGetValue(bundleName, out int value) == false)
|
||||
{
|
||||
throw new Exception($"Should never get here ! Not found bundle ID : {bundleName}");
|
||||
throw new Exception($"Should never get here ! Not found bundle index ID : {bundleName}");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
@@ -28,9 +28,10 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.BuildSeconds = BuildRunner.TotalSeconds;
|
||||
buildReport.Summary.BuildTarget = buildParameters.BuildTarget;
|
||||
buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline;
|
||||
buildReport.Summary.BuildMode = buildParameters.BuildMode;
|
||||
buildReport.Summary.BuildBundleType = buildParameters.BuildBundleType;
|
||||
buildReport.Summary.BuildPackageName = buildParameters.PackageName;
|
||||
buildReport.Summary.BuildPackageVersion = buildParameters.PackageVersion;
|
||||
buildReport.Summary.BuildPackageNote = buildParameters.PackageNote;
|
||||
|
||||
// 收集器配置
|
||||
buildReport.Summary.UniqueBundleName = buildMapContext.Command.UniqueBundleName;
|
||||
@@ -41,6 +42,8 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
|
||||
|
||||
// 构建参数
|
||||
buildReport.Summary.ClearBuildCacheFiles = buildParameters.ClearBuildCacheFiles;
|
||||
buildReport.Summary.UseAssetDependencyDB = buildParameters.UseAssetDependencyDB;
|
||||
buildReport.Summary.EnableSharePackRule = buildParameters.EnableSharePackRule;
|
||||
buildReport.Summary.EncryptionClassName = buildParameters.EncryptionServices == null ? "null" : buildParameters.EncryptionServices.GetType().FullName;
|
||||
if (buildParameters.BuildPipeline == nameof(BuiltinBuildPipeline))
|
||||
@@ -113,7 +116,7 @@ namespace YooAsset.Editor
|
||||
buildReport.IndependAssets = new List<ReportIndependAsset>(buildMapContext.IndependAssets);
|
||||
|
||||
// 序列化文件
|
||||
string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string fileName = YooAssetSettingsData.GetBuildReportFileName(buildParameters.PackageName, buildParameters.PackageVersion);
|
||||
string filePath = $"{packageOutputDirectory}/{fileName}";
|
||||
BuildReport.Serialize(filePath, buildReport);
|
||||
BuildLogger.Log($"Create build report file: {filePath}");
|
||||
@@ -130,6 +133,7 @@ namespace YooAsset.Editor
|
||||
string dependBundleName = manifest.BundleList[index].BundleName;
|
||||
dependBundles.Add(dependBundleName);
|
||||
}
|
||||
dependBundles.Sort();
|
||||
return dependBundles;
|
||||
}
|
||||
|
||||
@@ -159,6 +163,7 @@ namespace YooAsset.Editor
|
||||
result.Add(dependAssetInfo.AssetInfo.AssetPath);
|
||||
}
|
||||
}
|
||||
result.Sort();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -168,7 +173,9 @@ namespace YooAsset.Editor
|
||||
private List<string> GetAllBuiltinAssets(BuildMapContext buildMapContext, string bundleName)
|
||||
{
|
||||
var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
|
||||
return bundleInfo.GetAllBuiltinAssetPaths();
|
||||
List<string> result = bundleInfo.GetAllBuiltinAssetPaths();
|
||||
result.Sort();
|
||||
return result;
|
||||
}
|
||||
|
||||
private int GetMainAssetCount(PackageManifest manifest)
|
||||
|
@@ -26,7 +26,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
EncryptFileInfo fileInfo = new EncryptFileInfo();
|
||||
fileInfo.BundleName = bundleInfo.BundleName;
|
||||
fileInfo.FilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
fileInfo.FileLoadPath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
var encryptResult = encryptionServices.Encrypt(fileInfo);
|
||||
if (encryptResult.Encrypted)
|
||||
{
|
||||
|
@@ -12,16 +12,16 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 生成资源构建上下文
|
||||
/// </summary>
|
||||
public BuildMapContext CreateBuildMap(BuildParameters buildParameters)
|
||||
public BuildMapContext CreateBuildMap(bool simulateBuild, BuildParameters buildParameters)
|
||||
{
|
||||
BuildMapContext context = new BuildMapContext();
|
||||
var buildMode = buildParameters.BuildMode;
|
||||
var packageName = buildParameters.PackageName;
|
||||
|
||||
Dictionary<string, BuildAssetInfo> allBuildAssetInfos = new Dictionary<string, BuildAssetInfo>(1000);
|
||||
|
||||
// 1. 获取所有收集器收集的资源
|
||||
var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
|
||||
bool useAssetDependencyDB = buildParameters.UseAssetDependencyDB;
|
||||
var collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(simulateBuild, useAssetDependencyDB, packageName);
|
||||
List<CollectAssetInfo> allCollectAssets = collectResult.CollectAssets;
|
||||
|
||||
// 2. 剔除未被引用的依赖项资源
|
||||
@@ -56,9 +56,9 @@ namespace YooAsset.Editor
|
||||
string bundleName = collectAssetInfo.BundleName;
|
||||
foreach (var dependAsset in collectAssetInfo.DependAssets)
|
||||
{
|
||||
if (allBuildAssetInfos.ContainsKey(dependAsset.AssetPath))
|
||||
if (allBuildAssetInfos.TryGetValue(dependAsset.AssetPath, out var value))
|
||||
{
|
||||
allBuildAssetInfos[dependAsset.AssetPath].AddReferenceBundleName(bundleName);
|
||||
value.AddReferenceBundleName(bundleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -65,32 +65,5 @@ namespace YooAsset.Editor
|
||||
protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
|
||||
protected abstract string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
|
||||
protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
|
||||
|
||||
protected string GetFilePathTempHash(string filePath)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(filePath);
|
||||
return HashUtility.BytesMD5(bytes);
|
||||
|
||||
// 注意:在文件路径的哈希值冲突的情况下,可以使用下面的方法
|
||||
//return $"{HashUtility.BytesMD5(bytes)}-{Guid.NewGuid():N}";
|
||||
}
|
||||
protected long GetBundleTempSize(BuildBundleInfo bundleInfo)
|
||||
{
|
||||
long tempSize = 0;
|
||||
|
||||
var assetPaths = bundleInfo.GetAllMainAssetPaths();
|
||||
foreach (var assetPath in assetPaths)
|
||||
{
|
||||
long size = FileUtility.GetFileSize(assetPath);
|
||||
tempSize += size;
|
||||
}
|
||||
|
||||
if (tempSize == 0)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BundleTempSizeIsZero, $"Bundle temp size is zero, check bundle main asset list : {bundleInfo.BundleName}");
|
||||
throw new Exception(message);
|
||||
}
|
||||
return tempSize;
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,11 +20,6 @@ namespace YooAsset.Editor
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var builtinBuildParameters = buildParametersContext.Parameters as BuiltinBuildParameters;
|
||||
|
||||
// 模拟构建模式下跳过引擎构建
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return;
|
||||
|
||||
// 开始构建
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
BuildAssetBundleOptions buildOptions = builtinBuildParameters.GetBundleBuildOptions();
|
||||
@@ -35,15 +30,13 @@ namespace YooAsset.Editor
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
// 检测输出目录
|
||||
string unityOutputManifestFilePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}";
|
||||
if (System.IO.File.Exists(unityOutputManifestFilePath) == false)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.UnityEngineBuildFatal, $"Not found output {nameof(AssetBundleManifest)} file : {unityOutputManifestFilePath}");
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
|
||||
BuildLogger.Log("UnityEngine build success !");
|
||||
BuildResultContext buildResultContext = new BuildResultContext();
|
||||
|
@@ -12,15 +12,10 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var manifestContext = context.GetContextObject<ManifestContext>();
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||
{
|
||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,7 +11,7 @@ namespace YooAsset.Editor
|
||||
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(context);
|
||||
CreateManifestFile(true, true, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
@@ -9,17 +9,13 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode != EBuildMode.SimulateBuild && buildMode != EBuildMode.DryRunBuild)
|
||||
{
|
||||
CreatePackageCatalog(buildParameters, buildMapContext);
|
||||
}
|
||||
CreatePackagePatch(buildParameters, buildMapContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝补丁文件到补丁包目录
|
||||
/// </summary>
|
||||
private void CreatePackageCatalog(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
private void CreatePackagePatch(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
{
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
|
@@ -13,12 +13,7 @@ namespace YooAsset.Editor
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var manifestContext = context.GetContextObject<ManifestContext>();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
CreateReportFile(buildParameters, buildMapContext, manifestContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskEncryption_BBP : TaskEncryption, IBuildTask
|
||||
@@ -12,12 +7,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
EncryptingBundleFiles(buildParameters, buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -12,7 +12,7 @@ namespace YooAsset.Editor
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = CreateBuildMap(buildParametersContext.Parameters);
|
||||
var buildMapContext = CreateBuildMap(false, buildParametersContext.Parameters);
|
||||
context.SetContextObject(buildMapContext);
|
||||
}
|
||||
}
|
||||
|
@@ -17,13 +17,42 @@ namespace YooAsset.Editor
|
||||
// 检测基础构建参数
|
||||
buildParametersContext.CheckBuildParameters();
|
||||
|
||||
// 检测是否有未保存场景
|
||||
if (EditorTools.HasDirtyScenes())
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.FoundUnsavedScene, "Found unsaved scene !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
// 删除包裹目录
|
||||
if (buildParameters.ClearBuildCacheFiles)
|
||||
{
|
||||
string packageRootDirectory = buildParameters.GetPackageRootDirectory();
|
||||
if (EditorTools.DeleteDirectory(packageRootDirectory))
|
||||
{
|
||||
BuildLogger.Log($"Delete package root directory: {packageRootDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
// 检测包裹输出目录是否存在
|
||||
string packageOutputDirectory = buildParameters.GetPackageOutputDirectory();
|
||||
if (Directory.Exists(packageOutputDirectory))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageOutputDirectoryExists, $"Package outout directory exists: {packageOutputDirectory}");
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
// 如果输出目录不存在
|
||||
string pipelineOutputDirectory = buildParameters.GetPipelineOutputDirectory();
|
||||
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
|
||||
{
|
||||
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
|
||||
}
|
||||
|
||||
// 检测Unity版本
|
||||
#if UNITY_2021_3_OR_NEWER
|
||||
if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.RecommendScriptBuildPipeline, $"Starting with UnityEngine2021, recommend use script build pipeline (SBP) !");
|
||||
BuildLogger.Warning(warning);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@@ -14,15 +14,6 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var parameters = buildParametersContext.Parameters;
|
||||
var buildMode = parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
{
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
}
|
||||
else
|
||||
{
|
||||
var buildResult = context.GetContextObject<TaskBuilding_BBP.BuildResultContext>();
|
||||
var hash = buildResult.UnityManifest.GetAssetBundleHash(bundleInfo.BundleName);
|
||||
@@ -36,17 +27,7 @@ namespace YooAsset.Editor
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var parameters = buildParametersContext.Parameters;
|
||||
var buildMode = parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = bundleInfo.BuildOutputFilePath;
|
||||
if (BuildPipeline.GetCRCForAssetBundle(filePath, out uint crc))
|
||||
@@ -59,32 +40,19 @@ namespace YooAsset.Editor
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return GetFilePathTempHash(filePath);
|
||||
else
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000"; //8位
|
||||
else
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
}
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
|
||||
return GetBundleTempSize(bundleInfo);
|
||||
else
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
}
|
||||
|
@@ -15,10 +15,6 @@ namespace YooAsset.Editor
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters as BuiltinBuildParameters;
|
||||
|
||||
// 模拟构建模式下跳过验证
|
||||
if (buildParameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
return;
|
||||
|
||||
// 验证构建结果
|
||||
if (buildParameters.VerifyBuildingResult)
|
||||
{
|
||||
@@ -32,15 +28,14 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
string[] unityCreateBundles = unityManifest.GetAllAssetBundles();
|
||||
string[] unityBuildContent = unityManifest.GetAllAssetBundles();
|
||||
|
||||
// 1. 过滤掉原生Bundle
|
||||
string[] mapBundles = buildMapContext.Collection.Select(t => t.BundleName).ToArray();
|
||||
// 1. 计划内容
|
||||
string[] planningContent = buildMapContext.Collection.Select(t => t.BundleName).ToArray();
|
||||
|
||||
// 2. 验证Bundle
|
||||
List<string> exceptBundleList1 = unityCreateBundles.Except(mapBundles).ToList();
|
||||
// 2. 验证差异
|
||||
List<string> exceptBundleList1 = unityBuildContent.Except(planningContent).ToList();
|
||||
if (exceptBundleList1.Count > 0)
|
||||
{
|
||||
foreach (var exceptBundle in exceptBundleList1)
|
||||
@@ -53,8 +48,8 @@ namespace YooAsset.Editor
|
||||
throw new Exception(exception);
|
||||
}
|
||||
|
||||
// 3. 验证Bundle
|
||||
List<string> exceptBundleList2 = mapBundles.Except(unityCreateBundles).ToList();
|
||||
// 3. 验证差异
|
||||
List<string> exceptBundleList2 = planningContent.Except(unityBuildContent).ToList();
|
||||
if (exceptBundleList2.Count > 0)
|
||||
{
|
||||
foreach (var exceptBundle in exceptBundleList2)
|
||||
|
@@ -34,18 +34,12 @@ namespace YooAsset.Editor
|
||||
BuildAssetBundleOptions opt = BuildAssetBundleOptions.None;
|
||||
opt |= BuildAssetBundleOptions.StrictMode; //Do not allow the build to succeed if any errors are reporting during it.
|
||||
|
||||
if (BuildMode == EBuildMode.DryRunBuild)
|
||||
{
|
||||
opt |= BuildAssetBundleOptions.DryRunBuild;
|
||||
return opt;
|
||||
}
|
||||
|
||||
if (CompressOption == ECompressOption.Uncompressed)
|
||||
opt |= BuildAssetBundleOptions.UncompressedAssetBundle;
|
||||
else if (CompressOption == ECompressOption.LZ4)
|
||||
opt |= BuildAssetBundleOptions.ChunkBasedCompression;
|
||||
|
||||
if (BuildMode == EBuildMode.ForceRebuild)
|
||||
if (ClearBuildCacheFiles)
|
||||
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
|
||||
if (DisableWriteTypeTree)
|
||||
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
|
||||
|
@@ -7,10 +7,17 @@ namespace YooAsset.Editor
|
||||
public class BuiltinBuildPipeline : IBuildPipeline
|
||||
{
|
||||
public BuildResult Run(BuildParameters buildParameters, bool enableLog)
|
||||
{
|
||||
if (buildParameters is BuiltinBuildParameters)
|
||||
{
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认的构建流程
|
||||
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0b4ccec8007a6047aade899b4b74fcf
|
||||
guid: 12f78ad22f0513c44b6037469dbd6363
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa6624433c5d8e445b1426dcdf0763ba
|
||||
guid: 1138888cdba447345abb498b0c89affa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
@@ -0,0 +1,18 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskCreateManifest_ESBP : TaskCreateManifest, IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(false, false, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff1eb84d9996ca1409e37f45617b1bdb
|
||||
guid: 120e126cc10604c4f811c3b6377f7452
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -0,0 +1,15 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskGetBuildMap_ESBP : TaskGetBuildMap, IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = CreateBuildMap(true, buildParametersContext.Parameters);
|
||||
context.SetContextObject(buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b6f2523a865e454d8fa3f48a2852d5a
|
||||
guid: 789c337b5b82f1c438a588982dfca346
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -0,0 +1,17 @@
|
||||
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskPrepare_ESBP : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
|
||||
// 检测基础构建参数
|
||||
buildParametersContext.CheckBuildParameters();
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ff3c700b7f108b48998aa1630a769e1
|
||||
guid: abbe56a7120e34349b10f20956ed51a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -0,0 +1,63 @@
|
||||
|
||||
using System.Text;
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskUpdateBundleInfo_ESBP : TaskUpdateBundleInfo, IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
UpdateBundleInfo(context);
|
||||
}
|
||||
|
||||
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
}
|
||||
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return GetFilePathTempHash(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
return "00000000"; //8位
|
||||
}
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
return GetBundleTempSize(bundleInfo);
|
||||
}
|
||||
|
||||
private string GetFilePathTempHash(string filePath)
|
||||
{
|
||||
byte[] bytes = Encoding.UTF8.GetBytes(filePath);
|
||||
return HashUtility.BytesMD5(bytes);
|
||||
|
||||
// 注意:在文件路径的哈希值冲突的情况下,可以使用下面的方法
|
||||
//return $"{HashUtility.BytesMD5(bytes)}-{Guid.NewGuid():N}";
|
||||
}
|
||||
private long GetBundleTempSize(BuildBundleInfo bundleInfo)
|
||||
{
|
||||
long tempSize = 0;
|
||||
|
||||
var assetPaths = bundleInfo.GetAllMainAssetPaths();
|
||||
foreach (var assetPath in assetPaths)
|
||||
{
|
||||
long size = FileUtility.GetFileSize(assetPath);
|
||||
tempSize += size;
|
||||
}
|
||||
|
||||
if (tempSize == 0)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BundleTempSizeIsZero, $"Bundle temp size is zero, check bundle main asset list : {bundleInfo.BundleName}");
|
||||
throw new Exception(message);
|
||||
}
|
||||
return tempSize;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 699068f8f637708409436199baa62c1f
|
||||
guid: 990b41f647b80a34ab666a3b0c1ba3f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
@@ -0,0 +1,7 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class EditorSimulateBuildParameters : BuildParameters
|
||||
{
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03ea37371e6dc644cb2e6eabf9e7e2ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,37 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class EditorSimulateBuildPipeline : IBuildPipeline
|
||||
{
|
||||
public BuildResult Run(BuildParameters buildParameters, bool enableLog)
|
||||
{
|
||||
if (buildParameters is EditorSimulateBuildParameters)
|
||||
{
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认的构建流程
|
||||
/// </summary>
|
||||
private List<IBuildTask> GetDefaultBuildPipeline()
|
||||
{
|
||||
List<IBuildTask> pipeline = new List<IBuildTask>
|
||||
{
|
||||
new TaskPrepare_ESBP(),
|
||||
new TaskGetBuildMap_ESBP(),
|
||||
new TaskUpdateBundleInfo_ESBP(),
|
||||
new TaskCreateManifest_ESBP()
|
||||
};
|
||||
return pipeline;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9caf8e4846ad8b64eb04a4d5179942ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -10,15 +10,9 @@ namespace YooAsset.Editor
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
CopyRawBundle(buildMapContext, buildParametersContext);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝原生文件
|
||||
|
@@ -13,14 +13,10 @@ namespace YooAsset.Editor
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
var manifestContext = context.GetContextObject<ManifestContext>();
|
||||
|
||||
if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
if (buildParameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||
{
|
||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,12 +9,12 @@ namespace YooAsset.Editor
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(context);
|
||||
CreateManifestFile(false, true, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
{
|
||||
return new string[] { };
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -9,17 +9,13 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
CreatePackageCatalog(buildParameters, buildMapContext);
|
||||
}
|
||||
CreatePackagePatch(buildParameters, buildMapContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝补丁文件到补丁包目录
|
||||
/// </summary>
|
||||
private void CreatePackageCatalog(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
private void CreatePackagePatch(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
{
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
BuildLogger.Log($"Start making patch package: {packageOutputDirectory}");
|
||||
|
@@ -13,12 +13,7 @@ namespace YooAsset.Editor
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var manifestContext = context.GetContextObject<ManifestContext>();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
CreateReportFile(buildParameters, buildMapContext, manifestContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskEncryption_RFBP : TaskEncryption, IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
EncryptingBundleFiles(buildParameters, buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3e156139dcc25f4c9440ec3d6cb96d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -12,7 +12,7 @@ namespace YooAsset.Editor
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = CreateBuildMap(buildParametersContext.Parameters);
|
||||
var buildMapContext = CreateBuildMap(true, buildParametersContext.Parameters);
|
||||
context.SetContextObject(buildMapContext);
|
||||
|
||||
// 检测构建结果
|
||||
|
@@ -16,23 +16,29 @@ namespace YooAsset.Editor
|
||||
// 检测基础构建参数
|
||||
buildParametersContext.CheckBuildParameters();
|
||||
|
||||
// 检测不被支持的参数
|
||||
if (buildParameters.EnableSharePackRule)
|
||||
// 删除包裹目录
|
||||
if (buildParameters.ClearBuildCacheFiles)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportSharePackRule, $"{nameof(EBuildPipeline.RawFileBuildPipeline)} not support share pack rule !");
|
||||
string packageRootDirectory = buildParameters.GetPackageRootDirectory();
|
||||
if (EditorTools.DeleteDirectory(packageRootDirectory))
|
||||
{
|
||||
BuildLogger.Log($"Delete package root directory: {packageRootDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
// 检测包裹输出目录是否存在
|
||||
string packageOutputDirectory = buildParameters.GetPackageOutputDirectory();
|
||||
if (Directory.Exists(packageOutputDirectory))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageOutputDirectoryExists, $"Package outout directory exists: {packageOutputDirectory}");
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
// 检测不被支持的构建模式
|
||||
if (buildParameters.BuildMode == EBuildMode.DryRunBuild)
|
||||
// 如果输出目录不存在
|
||||
string pipelineOutputDirectory = buildParameters.GetPipelineOutputDirectory();
|
||||
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportBuildMode, $"{nameof(EBuildPipeline.RawFileBuildPipeline)} not support {nameof(EBuildMode.DryRunBuild)} build mode !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (buildParameters.BuildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportBuildMode, $"{nameof(EBuildPipeline.RawFileBuildPipeline)} not support {nameof(EBuildMode.IncrementalBuild)} build mode !");
|
||||
throw new Exception(message);
|
||||
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -14,20 +14,10 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var parameters = buildParametersContext.Parameters;
|
||||
var buildMode = parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
{
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
}
|
||||
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return 0;
|
||||
@@ -35,28 +25,16 @@ namespace YooAsset.Editor
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return GetFilePathTempHash(filePath);
|
||||
else
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000"; //8位
|
||||
else
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
}
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return GetBundleTempSize(bundleInfo);
|
||||
else
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
}
|
||||
|
@@ -10,10 +10,17 @@ namespace YooAsset.Editor
|
||||
public class RawFileBuildPipeline : IBuildPipeline
|
||||
{
|
||||
public BuildResult Run(BuildParameters buildParameters, bool enableLog)
|
||||
{
|
||||
if (buildParameters is RawFileBuildParameters)
|
||||
{
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认的构建流程
|
||||
@@ -25,6 +32,7 @@ namespace YooAsset.Editor
|
||||
new TaskPrepare_RFBP(),
|
||||
new TaskGetBuildMap_RFBP(),
|
||||
new TaskBuilding_RFBP(),
|
||||
new TaskEncryption_RFBP(),
|
||||
new TaskUpdateBundleInfo_RFBP(),
|
||||
new TaskCreateManifest_RFBP(),
|
||||
new TaskCreateReport_RFBP(),
|
||||
|
@@ -21,18 +21,13 @@ namespace YooAsset.Editor
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
|
||||
// 模拟构建模式下跳过引擎构建
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return;
|
||||
|
||||
// 构建内容
|
||||
var buildContent = new BundleBuildContent(buildMapContext.GetPipelineBuilds());
|
||||
|
||||
// 开始构建
|
||||
IBundleBuildResults buildResults;
|
||||
var buildParameters = scriptableBuildParameters.GetBundleBuildParameters();
|
||||
var taskList = SBPBuildTasks.Create(buildMapContext.Command.ShadersBundleName);
|
||||
var taskList = SBPBuildTasks.Create(buildMapContext.Command.ShadersBundleName, null);
|
||||
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
|
||||
if (exitCode < 0)
|
||||
{
|
||||
|
@@ -12,15 +12,10 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var manifestContext = context.GetContextObject<ManifestContext>();
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
if (buildParametersContext.Parameters.BuildinFileCopyOption != EBuildinFileCopyOption.None)
|
||||
{
|
||||
CopyBuildinFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -13,7 +13,7 @@ namespace YooAsset.Editor
|
||||
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(context);
|
||||
CreateManifestFile(true, true, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
@@ -9,17 +9,13 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
CreatePackageCatalog(buildParameters, buildMapContext);
|
||||
}
|
||||
CreatePackagePatch(buildParameters, buildMapContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝补丁文件到补丁包目录
|
||||
/// </summary>
|
||||
private void CreatePackageCatalog(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
private void CreatePackagePatch(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
{
|
||||
var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
|
@@ -13,12 +13,7 @@ namespace YooAsset.Editor
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var manifestContext = context.GetContextObject<ManifestContext>();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode != EBuildMode.SimulateBuild)
|
||||
{
|
||||
CreateReportFile(buildParameters, buildMapContext, manifestContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class TaskEncryption_SBP : TaskEncryption, IBuildTask
|
||||
@@ -12,12 +7,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
EncryptingBundleFiles(buildParameters, buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -12,7 +12,7 @@ namespace YooAsset.Editor
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = CreateBuildMap(buildParametersContext.Parameters);
|
||||
var buildMapContext = CreateBuildMap(false, buildParametersContext.Parameters);
|
||||
context.SetContextObject(buildMapContext);
|
||||
}
|
||||
}
|
||||
|
@@ -16,17 +16,40 @@ namespace YooAsset.Editor
|
||||
// 检测基础构建参数
|
||||
buildParametersContext.CheckBuildParameters();
|
||||
|
||||
// 检测不被支持的构建模式
|
||||
if (buildParameters.BuildMode == EBuildMode.DryRunBuild)
|
||||
// 检测是否有未保存场景
|
||||
if (EditorTools.HasDirtyScenes())
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportBuildMode, $"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.DryRunBuild)} build mode !");
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.FoundUnsavedScene, "Found unsaved scene !");
|
||||
throw new Exception(message);
|
||||
}
|
||||
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
|
||||
|
||||
// 删除包裹目录
|
||||
if (buildParameters.ClearBuildCacheFiles)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineNotSupportBuildMode, $"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.ForceRebuild)} build mode !");
|
||||
// Deletes the build cache directory.
|
||||
UnityEditor.Build.Pipeline.Utilities.BuildCache.PurgeCache(false);
|
||||
|
||||
string packageRootDirectory = buildParameters.GetPackageRootDirectory();
|
||||
if (EditorTools.DeleteDirectory(packageRootDirectory))
|
||||
{
|
||||
BuildLogger.Log($"Delete package root directory: {packageRootDirectory}");
|
||||
}
|
||||
}
|
||||
|
||||
// 检测包裹输出目录是否存在
|
||||
string packageOutputDirectory = buildParameters.GetPackageOutputDirectory();
|
||||
if (Directory.Exists(packageOutputDirectory))
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.PackageOutputDirectoryExists, $"Package outout directory exists: {packageOutputDirectory}");
|
||||
throw new Exception(message);
|
||||
}
|
||||
|
||||
// 如果输出目录不存在
|
||||
string pipelineOutputDirectory = buildParameters.GetPipelineOutputDirectory();
|
||||
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
|
||||
{
|
||||
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,15 +14,6 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var parameters = buildParametersContext.Parameters;
|
||||
var buildMode = parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
{
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:当资源包的依赖列表发生变化的时候,ContentHash也会发生变化!
|
||||
var buildResult = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||
@@ -36,17 +27,7 @@ namespace YooAsset.Editor
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var parameters = buildParametersContext.Parameters;
|
||||
var buildMode = parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
var buildResult = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||
if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value))
|
||||
@@ -59,32 +40,19 @@ namespace YooAsset.Editor
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return GetFilePathTempHash(filePath);
|
||||
else
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return "00000000"; //8位
|
||||
else
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
}
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
var buildMode = buildParametersContext.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.SimulateBuild)
|
||||
return GetBundleTempSize(bundleInfo);
|
||||
else
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
}
|
||||
|
@@ -16,10 +16,6 @@ namespace YooAsset.Editor
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
|
||||
// 模拟构建模式下跳过验证
|
||||
if (buildParameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
return;
|
||||
|
||||
// 验证构建结果
|
||||
if (buildParameters.VerifyBuildingResult)
|
||||
{
|
||||
@@ -33,15 +29,14 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private void VerifyingBuildingResult(BuildContext context, IBundleBuildResults buildResults)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
List<string> unityCreateBundles = buildResults.BundleInfos.Keys.ToList();
|
||||
List<string> unityBuildContent = buildResults.BundleInfos.Keys.ToList();
|
||||
|
||||
// 1. 过滤掉原生Bundle
|
||||
List<string> expectBundles = buildMapContext.Collection.Select(t => t.BundleName).ToList();
|
||||
// 1. 计划内容
|
||||
List<string> planningContent = buildMapContext.Collection.Select(t => t.BundleName).ToList();
|
||||
|
||||
// 2. 验证Bundle
|
||||
List<string> exceptBundleList1 = unityCreateBundles.Except(expectBundles).ToList();
|
||||
// 2. 验证差异
|
||||
List<string> exceptBundleList1 = unityBuildContent.Except(planningContent).ToList();
|
||||
if (exceptBundleList1.Count > 0)
|
||||
{
|
||||
foreach (var exceptBundle in exceptBundleList1)
|
||||
@@ -54,8 +49,8 @@ namespace YooAsset.Editor
|
||||
throw new Exception(exception);
|
||||
}
|
||||
|
||||
// 3. 验证Bundle
|
||||
List<string> exceptBundleList2 = expectBundles.Except(unityCreateBundles).ToList();
|
||||
// 3. 验证差异
|
||||
List<string> exceptBundleList2 = planningContent.Except(unityBuildContent).ToList();
|
||||
if (exceptBundleList2.Count > 0)
|
||||
{
|
||||
foreach (var exceptBundle in exceptBundleList2)
|
||||
|
@@ -9,7 +9,7 @@ namespace UnityEditor.Build.Pipeline.Tasks
|
||||
{
|
||||
public static class SBPBuildTasks
|
||||
{
|
||||
public static IList<IBuildTask> Create(string builtInShaderBundleName)
|
||||
public static IList<IBuildTask> Create(string builtInShaderBundleName, string unityMonoScriptsBundleName)
|
||||
{
|
||||
var buildTasks = new List<IBuildTask>();
|
||||
|
||||
@@ -28,7 +28,10 @@ namespace UnityEditor.Build.Pipeline.Tasks
|
||||
#endif
|
||||
buildTasks.Add(new CalculateAssetDependencyData());
|
||||
buildTasks.Add(new StripUnusedSpriteSources());
|
||||
if (string.IsNullOrEmpty(builtInShaderBundleName) == false)
|
||||
buildTasks.Add(new CreateBuiltInShadersBundle(builtInShaderBundleName));
|
||||
if (string.IsNullOrEmpty(unityMonoScriptsBundleName) == false)
|
||||
buildTasks.Add(new CreateMonoScriptBundle(unityMonoScriptsBundleName));
|
||||
buildTasks.Add(new PostDependencyCallback());
|
||||
|
||||
// Packing
|
||||
|
@@ -7,10 +7,17 @@ namespace YooAsset.Editor
|
||||
public class ScriptableBuildPipeline : IBuildPipeline
|
||||
{
|
||||
public BuildResult Run(BuildParameters buildParameters, bool enableLog)
|
||||
{
|
||||
if (buildParameters is ScriptableBuildParameters)
|
||||
{
|
||||
AssetBundleBuilder builder = new AssetBundleBuilder();
|
||||
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid build parameter type : {buildParameters.GetType().Name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认的构建流程
|
||||
|
@@ -12,9 +12,9 @@ namespace YooAsset.Editor
|
||||
BuildOutputRootIsNullOrEmpty = 113,
|
||||
BuildinFileRootIsNullOrEmpty = 114,
|
||||
PackageOutputDirectoryExists = 115,
|
||||
BuildPipelineIsNullOrEmpty = 116,
|
||||
BuildBundleTypeIsUnknown = 117,
|
||||
RecommendScriptBuildPipeline = 130,
|
||||
BuildPipelineNotSupportBuildMode = 140,
|
||||
BuildPipelineNotSupportSharePackRule = 141,
|
||||
|
||||
// TaskGetBuildMap
|
||||
RemoveInvalidTags = 200,
|
||||
@@ -39,5 +39,6 @@ namespace YooAsset.Editor
|
||||
// TaskCreateManifest
|
||||
NotFoundUnityBundleInBuildResult = 600,
|
||||
FoundStrayBundle = 601,
|
||||
BundleHashConflict = 602,
|
||||
}
|
||||
}
|
@@ -1,29 +0,0 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包流水线的构建模式
|
||||
/// </summary>
|
||||
public enum EBuildMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 强制重建模式
|
||||
/// </summary>
|
||||
ForceRebuild,
|
||||
|
||||
/// <summary>
|
||||
/// 增量构建模式
|
||||
/// </summary>
|
||||
IncrementalBuild,
|
||||
|
||||
/// <summary>
|
||||
/// 演练构建模式
|
||||
/// </summary>
|
||||
DryRunBuild,
|
||||
|
||||
/// <summary>
|
||||
/// 模拟构建模式
|
||||
/// </summary>
|
||||
SimulateBuild,
|
||||
}
|
||||
}
|
@@ -6,6 +6,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public enum EBuildPipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器下的模拟构建管线(ESBP)
|
||||
/// </summary>
|
||||
EditorSimulateBuildPipeline,
|
||||
|
||||
/// <summary>
|
||||
/// 传统内置构建管线 (BBP)
|
||||
/// </summary>
|
||||
|
@@ -3,6 +3,6 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public interface IBuildPipeline
|
||||
{
|
||||
public BuildResult Run(BuildParameters buildParameters, bool enableLog);
|
||||
BuildResult Run(BuildParameters buildParameters, bool enableLog);
|
||||
}
|
||||
}
|
@@ -13,6 +13,7 @@ namespace YooAsset.Editor
|
||||
internal abstract class BuildPipelineViewerBase
|
||||
{
|
||||
private const int StyleWidth = 400;
|
||||
private const int LabelMinWidth = 180;
|
||||
|
||||
protected readonly string PackageName;
|
||||
protected readonly BuildTarget BuildTarget;
|
||||
@@ -27,6 +28,8 @@ namespace YooAsset.Editor
|
||||
private EnumField _outputNameStyleField;
|
||||
private EnumField _copyBuildinFileOptionField;
|
||||
private TextField _copyBuildinFileTagsField;
|
||||
private Toggle _clearBuildCacheToggle;
|
||||
private Toggle _useAssetDependencyDBToggle;
|
||||
|
||||
public BuildPipelineViewerBase(string packageName, EBuildPipeline buildPipeline, BuildTarget buildTarget, VisualElement parent)
|
||||
{
|
||||
@@ -59,24 +62,6 @@ namespace YooAsset.Editor
|
||||
_buildVersionField.style.width = StyleWidth;
|
||||
_buildVersionField.SetValueWithoutNotify(GetDefaultPackageVersion());
|
||||
|
||||
// 构建模式
|
||||
{
|
||||
var buildModeContainer = Root.Q("BuildModeContainer");
|
||||
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline);
|
||||
var buildModeList = GetSupportBuildModes();
|
||||
int defaultIndex = buildModeList.FindIndex(x => x.Equals(buildMode));
|
||||
if (defaultIndex < 0)
|
||||
defaultIndex = (int)(EBuildMode)buildModeList[0];
|
||||
_buildModeField = new PopupField<Enum>(buildModeList, defaultIndex);
|
||||
_buildModeField.label = "Build Mode";
|
||||
_buildModeField.style.width = StyleWidth;
|
||||
_buildModeField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSetting.SetPackageBuildMode(PackageName, BuildPipeline, (EBuildMode)_buildModeField.value);
|
||||
});
|
||||
buildModeContainer.Add(_buildModeField);
|
||||
}
|
||||
|
||||
// 加密方法
|
||||
{
|
||||
var encryptionContainer = Root.Q("EncryptionContainer");
|
||||
@@ -148,6 +133,35 @@ namespace YooAsset.Editor
|
||||
AssetBundleBuilderSetting.SetPackageBuildinFileCopyParams(PackageName, BuildPipeline, _copyBuildinFileTagsField.value);
|
||||
});
|
||||
|
||||
// 清理构建缓存
|
||||
bool clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline);
|
||||
_clearBuildCacheToggle = Root.Q<Toggle>("ClearBuildCache");
|
||||
_clearBuildCacheToggle.SetValueWithoutNotify(clearBuildCache);
|
||||
_clearBuildCacheToggle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSetting.SetPackageClearBuildCache(PackageName, BuildPipeline, _clearBuildCacheToggle.value);
|
||||
});
|
||||
|
||||
// 使用资源依赖数据库
|
||||
bool useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline);
|
||||
_useAssetDependencyDBToggle = Root.Q<Toggle>("UseAssetDependency");
|
||||
_useAssetDependencyDBToggle.SetValueWithoutNotify(useAssetDependencyDB);
|
||||
_useAssetDependencyDBToggle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
AssetBundleBuilderSetting.SetPackageUseAssetDependencyDB(PackageName, BuildPipeline, _useAssetDependencyDBToggle.value);
|
||||
});
|
||||
|
||||
// 对齐文本间距
|
||||
UIElementsTools.SetElementLabelMinWidth(_buildOutputField, LabelMinWidth);
|
||||
UIElementsTools.SetElementLabelMinWidth(_buildVersionField, LabelMinWidth);
|
||||
UIElementsTools.SetElementLabelMinWidth(_compressionField, LabelMinWidth);
|
||||
UIElementsTools.SetElementLabelMinWidth(_encryptionField, LabelMinWidth);
|
||||
UIElementsTools.SetElementLabelMinWidth(_outputNameStyleField, LabelMinWidth);
|
||||
UIElementsTools.SetElementLabelMinWidth(_copyBuildinFileOptionField, LabelMinWidth);
|
||||
UIElementsTools.SetElementLabelMinWidth(_copyBuildinFileTagsField, LabelMinWidth);
|
||||
UIElementsTools.SetElementLabelMinWidth(_clearBuildCacheToggle, LabelMinWidth);
|
||||
UIElementsTools.SetElementLabelMinWidth(_useAssetDependencyDBToggle, LabelMinWidth);
|
||||
|
||||
// 构建按钮
|
||||
var buildButton = Root.Q<Button>("Build");
|
||||
buildButton.clicked += BuildButton_clicked;
|
||||
@@ -160,8 +174,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void BuildButton_clicked()
|
||||
{
|
||||
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline);
|
||||
if (EditorUtility.DisplayDialog("提示", $"通过构建模式【{buildMode}】来构建!", "Yes", "No"))
|
||||
if (EditorUtility.DisplayDialog("提示", $"开始构建资源包[{PackageName}]!", "Yes", "No"))
|
||||
{
|
||||
EditorTools.ClearUnityConsole();
|
||||
EditorApplication.delayCall += ExecuteBuild;
|
||||
@@ -177,11 +190,6 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
protected abstract void ExecuteBuild();
|
||||
|
||||
/// <summary>
|
||||
/// 获取构建管线支持的构建模式集合
|
||||
/// </summary>
|
||||
protected abstract List<Enum> GetSupportBuildModes();
|
||||
|
||||
/// <summary>
|
||||
/// 获取构建版本
|
||||
/// </summary>
|
||||
|
@@ -2,7 +2,8 @@
|
||||
<ui:VisualElement name="BuildContainer">
|
||||
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
|
||||
<ui:TextField picking-mode="Ignore" label="Build Version" name="BuildVersion" />
|
||||
<ui:VisualElement name="BuildModeContainer" style="height: 24px;" />
|
||||
<ui:Toggle label="Clear Build Cache" name="ClearBuildCache" />
|
||||
<ui:Toggle label="Use Asset Depend DB" name="UseAssetDependency" />
|
||||
<ui:VisualElement name="EncryptionContainer" style="height: 24px;" />
|
||||
<uie:EnumField label="Compression" value="Center" name="Compression" />
|
||||
<uie:EnumField label="File Name Style" value="Center" name="FileNameStyle" />
|
||||
|
@@ -22,18 +22,19 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
protected override void ExecuteBuild()
|
||||
{
|
||||
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline);
|
||||
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline);
|
||||
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline);
|
||||
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline);
|
||||
var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline);
|
||||
var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline);
|
||||
var useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline);
|
||||
|
||||
BuiltinBuildParameters buildParameters = new BuiltinBuildParameters();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = BuildPipeline.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.BuildMode = buildMode;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = GetPackageVersion();
|
||||
buildParameters.EnableSharePackRule = true;
|
||||
@@ -41,24 +42,16 @@ namespace YooAsset.Editor
|
||||
buildParameters.FileNameStyle = fileNameStyle;
|
||||
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
|
||||
buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
|
||||
buildParameters.EncryptionServices = CreateEncryptionInstance();
|
||||
buildParameters.CompressOption = compressOption;
|
||||
buildParameters.ClearBuildCacheFiles = clearBuildCache;
|
||||
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
|
||||
buildParameters.EncryptionServices = CreateEncryptionInstance();
|
||||
|
||||
BuiltinBuildPipeline pipeline = new BuiltinBuildPipeline();
|
||||
var buildResult = pipeline.Run(buildParameters, true);
|
||||
if (buildResult.Success)
|
||||
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
|
||||
}
|
||||
|
||||
protected override List<Enum> GetSupportBuildModes()
|
||||
{
|
||||
List<Enum> buildModeList = new List<Enum>();
|
||||
buildModeList.Add(EBuildMode.ForceRebuild);
|
||||
buildModeList.Add(EBuildMode.IncrementalBuild);
|
||||
buildModeList.Add(EBuildMode.DryRunBuild);
|
||||
buildModeList.Add(EBuildMode.SimulateBuild);
|
||||
return buildModeList;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,70 @@
|
||||
#if UNITY_2019_4_OR_NEWER
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal class EditorSimulateBuildPipelineViewer : BuildPipelineViewerBase
|
||||
{
|
||||
public EditorSimulateBuildPipelineViewer(string packageName, BuildTarget buildTarget, VisualElement parent)
|
||||
: base(packageName, EBuildPipeline.RawFileBuildPipeline, buildTarget, parent)
|
||||
{
|
||||
var compressionField = Root.Q<EnumField>("Compression");
|
||||
UIElementsTools.SetElementVisible(compressionField, false);
|
||||
|
||||
var encryptionContainer = Root.Q<VisualElement>("EncryptionContainer");
|
||||
UIElementsTools.SetElementVisible(encryptionContainer, false);
|
||||
|
||||
var fileNameStyleField = Root.Q<EnumField>("FileNameStyle");
|
||||
UIElementsTools.SetElementVisible(fileNameStyleField, false);
|
||||
|
||||
var copyBuildinFileOptionField = Root.Q<EnumField>("CopyBuildinFileOption");
|
||||
UIElementsTools.SetElementVisible(copyBuildinFileOptionField, false);
|
||||
|
||||
var copyBuildinFileParamField = Root.Q<TextField>("CopyBuildinFileParam");
|
||||
UIElementsTools.SetElementVisible(copyBuildinFileParamField, false);
|
||||
|
||||
var clearBuildCacheToggle = Root.Q<Toggle>("ClearBuildCache");
|
||||
UIElementsTools.SetElementVisible(clearBuildCacheToggle, false);
|
||||
|
||||
var useAssetDependencyToggle = Root.Q<Toggle>("UseAssetDependency");
|
||||
UIElementsTools.SetElementVisible(useAssetDependencyToggle, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行构建
|
||||
/// </summary>
|
||||
protected override void ExecuteBuild()
|
||||
{
|
||||
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline);
|
||||
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline);
|
||||
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline);
|
||||
|
||||
EditorSimulateBuildParameters buildParameters = new EditorSimulateBuildParameters();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = BuildPipeline.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = GetPackageVersion();
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.FileNameStyle = fileNameStyle;
|
||||
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
|
||||
buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
|
||||
buildParameters.EncryptionServices = CreateEncryptionInstance();
|
||||
|
||||
EditorSimulateBuildPipeline pipeline = new EditorSimulateBuildPipeline();
|
||||
var buildResult = pipeline.Run(buildParameters, true);
|
||||
if (buildResult.Success)
|
||||
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 01e426f05b237b340881910d779e4c2e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -24,23 +24,26 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
protected override void ExecuteBuild()
|
||||
{
|
||||
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline);
|
||||
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline);
|
||||
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline);
|
||||
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline);
|
||||
var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline);
|
||||
var useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline);
|
||||
|
||||
RawFileBuildParameters buildParameters = new RawFileBuildParameters();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = BuildPipeline.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.RawBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.BuildMode = buildMode;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = GetPackageVersion();
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.FileNameStyle = fileNameStyle;
|
||||
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
|
||||
buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
|
||||
buildParameters.ClearBuildCacheFiles = clearBuildCache;
|
||||
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
|
||||
buildParameters.EncryptionServices = CreateEncryptionInstance();
|
||||
|
||||
RawFileBuildPipeline pipeline = new RawFileBuildPipeline();
|
||||
@@ -48,14 +51,6 @@ namespace YooAsset.Editor
|
||||
if (buildResult.Success)
|
||||
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
|
||||
}
|
||||
|
||||
protected override List<Enum> GetSupportBuildModes()
|
||||
{
|
||||
List<Enum> buildModeList = new List<Enum>();
|
||||
buildModeList.Add(EBuildMode.ForceRebuild);
|
||||
buildModeList.Add(EBuildMode.SimulateBuild);
|
||||
return buildModeList;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -22,18 +22,19 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
protected override void ExecuteBuild()
|
||||
{
|
||||
var buildMode = AssetBundleBuilderSetting.GetPackageBuildMode(PackageName, BuildPipeline);
|
||||
var fileNameStyle = AssetBundleBuilderSetting.GetPackageFileNameStyle(PackageName, BuildPipeline);
|
||||
var buildinFileCopyOption = AssetBundleBuilderSetting.GetPackageBuildinFileCopyOption(PackageName, BuildPipeline);
|
||||
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline);
|
||||
var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline);
|
||||
var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline);
|
||||
var useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline);
|
||||
|
||||
ScriptableBuildParameters buildParameters = new ScriptableBuildParameters();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = BuildPipeline.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.BuildMode = buildMode;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = GetPackageVersion();
|
||||
buildParameters.EnableSharePackRule = true;
|
||||
@@ -41,22 +42,16 @@ namespace YooAsset.Editor
|
||||
buildParameters.FileNameStyle = fileNameStyle;
|
||||
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
|
||||
buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
|
||||
buildParameters.EncryptionServices = CreateEncryptionInstance();
|
||||
buildParameters.CompressOption = compressOption;
|
||||
buildParameters.ClearBuildCacheFiles = clearBuildCache;
|
||||
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
|
||||
buildParameters.EncryptionServices = CreateEncryptionInstance();
|
||||
|
||||
ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline();
|
||||
var buildResult = pipeline.Run(buildParameters, true);
|
||||
if (buildResult.Success)
|
||||
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
|
||||
}
|
||||
|
||||
protected override List<Enum> GetSupportBuildModes()
|
||||
{
|
||||
List<Enum> buildModeList = new List<Enum>();
|
||||
buildModeList.Add(EBuildMode.IncrementalBuild);
|
||||
buildModeList.Add(EBuildMode.SimulateBuild);
|
||||
return buildModeList;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -140,7 +140,7 @@ namespace YooAsset.Editor
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command, AssetBundleCollectorGroup group)
|
||||
{
|
||||
// 注意:模拟构建模式下只收集主资源
|
||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||
if (command.SimulateBuild)
|
||||
{
|
||||
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||
return new List<CollectAssetInfo>();
|
||||
@@ -149,7 +149,7 @@ namespace YooAsset.Editor
|
||||
Dictionary<string, CollectAssetInfo> result = new Dictionary<string, CollectAssetInfo>(1000);
|
||||
|
||||
// 收集打包资源路径
|
||||
List<string> findAssets =new List<string>();
|
||||
List<string> findAssets = new List<string>();
|
||||
if (AssetDatabase.IsValidFolder(CollectPath))
|
||||
{
|
||||
string collectDirectory = CollectPath;
|
||||
@@ -218,13 +218,7 @@ namespace YooAsset.Editor
|
||||
string bundleName = GetBundleName(command, group, assetInfo);
|
||||
List<string> assetTags = GetAssetTags(group);
|
||||
CollectAssetInfo collectAssetInfo = new CollectAssetInfo(CollectorType, bundleName, address, assetInfo, assetTags);
|
||||
|
||||
// 注意:模拟构建模式下不需要收集依赖资源
|
||||
if (command.BuildMode == EBuildMode.SimulateBuild)
|
||||
collectAssetInfo.DependAssets = new List<AssetInfo>();
|
||||
else
|
||||
collectAssetInfo.DependAssets = GetAllDependencies(command, assetInfo.AssetPath);
|
||||
|
||||
return collectAssetInfo;
|
||||
}
|
||||
|
||||
@@ -272,7 +266,11 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
|
||||
{
|
||||
string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
|
||||
// 注意:模拟构建模式下不需要收集依赖资源
|
||||
if (command.SimulateBuild)
|
||||
return new List<AssetInfo>();
|
||||
|
||||
string[] depends = command.AssetDependency.GetDependencies(mainAssetPath, true);
|
||||
List<AssetInfo> result = new List<AssetInfo>(depends.Length);
|
||||
foreach (string assetPath in depends)
|
||||
{
|
||||
|
@@ -46,7 +46,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 检测分组是否激活
|
||||
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
|
||||
if (activeRule.IsActiveGroup() == false)
|
||||
if (activeRule.IsActiveGroup(new GroupData(GroupName)) == false)
|
||||
return;
|
||||
|
||||
foreach (var collector in Collectors)
|
||||
@@ -80,7 +80,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 检测分组是否激活
|
||||
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(ActiveRuleName);
|
||||
if (activeRule.IsActiveGroup() == false)
|
||||
if (activeRule.IsActiveGroup(new GroupData(GroupName)) == false)
|
||||
{
|
||||
return new List<CollectAssetInfo>();
|
||||
}
|
||||
|
@@ -89,7 +89,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取包裹收集的资源文件
|
||||
/// </summary>
|
||||
public CollectResult GetPackageAssets(EBuildMode buildMode, string packageName)
|
||||
public CollectResult GetPackageAssets(bool simulateBuild, bool useAssetDependencyDB, string packageName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(packageName))
|
||||
throw new Exception("Build package name is null or empty !");
|
||||
@@ -100,7 +100,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 创建资源收集命令
|
||||
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(package.IgnoreRuleName);
|
||||
CollectCommand command = new CollectCommand(buildMode, packageName,
|
||||
CollectCommand command = new CollectCommand(simulateBuild, useAssetDependencyDB, packageName,
|
||||
package.EnableAddressable,
|
||||
package.LocationToLower,
|
||||
package.IncludeAssetGUID,
|
||||
|
@@ -201,7 +201,6 @@ namespace YooAsset.Editor
|
||||
public static void ClearAll()
|
||||
{
|
||||
Setting.ClearAll();
|
||||
SaveFile();
|
||||
}
|
||||
|
||||
public static List<RuleDisplayName> GetActiveRuleNames()
|
||||
@@ -275,23 +274,23 @@ namespace YooAsset.Editor
|
||||
|
||||
public static bool HasActiveRuleName(string ruleName)
|
||||
{
|
||||
return _cacheActiveRuleTypes.Keys.Contains(ruleName);
|
||||
return _cacheActiveRuleTypes.ContainsKey(ruleName);
|
||||
}
|
||||
public static bool HasAddressRuleName(string ruleName)
|
||||
{
|
||||
return _cacheAddressRuleTypes.Keys.Contains(ruleName);
|
||||
return _cacheAddressRuleTypes.ContainsKey(ruleName);
|
||||
}
|
||||
public static bool HasPackRuleName(string ruleName)
|
||||
{
|
||||
return _cachePackRuleTypes.Keys.Contains(ruleName);
|
||||
return _cachePackRuleTypes.ContainsKey(ruleName);
|
||||
}
|
||||
public static bool HasFilterRuleName(string ruleName)
|
||||
{
|
||||
return _cacheFilterRuleTypes.Keys.Contains(ruleName);
|
||||
return _cacheFilterRuleTypes.ContainsKey(ruleName);
|
||||
}
|
||||
public static bool HasIgnoreRuleName(string ruleName)
|
||||
{
|
||||
return _cacheIgnoreRuleTypes.Keys.Contains(ruleName);
|
||||
return _cacheIgnoreRuleTypes.ContainsKey(ruleName);
|
||||
}
|
||||
|
||||
public static IActiveRule GetActiveRuleInstance(string ruleName)
|
||||
|
@@ -175,7 +175,7 @@ namespace YooAsset.Editor
|
||||
_ignoreRulePopupField.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
if(selectPackage != null)
|
||||
if (selectPackage != null)
|
||||
{
|
||||
selectPackage.IgnoreRuleName = evt.newValue.ClassName;
|
||||
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
|
||||
@@ -205,7 +205,9 @@ namespace YooAsset.Editor
|
||||
_packageListView = root.Q<ListView>("PackageListView");
|
||||
_packageListView.makeItem = MakePackageListViewItem;
|
||||
_packageListView.bindItem = BindPackageListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
_packageListView.selectionChanged += PackageListView_onSelectionChange;
|
||||
#elif UNITY_2020_1_OR_NEWER
|
||||
_packageListView.onSelectionChange += PackageListView_onSelectionChange;
|
||||
#else
|
||||
_packageListView.onSelectionChanged += PackageListView_onSelectionChange;
|
||||
@@ -250,7 +252,9 @@ namespace YooAsset.Editor
|
||||
_groupListView = root.Q<ListView>("GroupListView");
|
||||
_groupListView.makeItem = MakeGroupListViewItem;
|
||||
_groupListView.bindItem = BindGroupListViewItem;
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
#if UNITY_2022_3_OR_NEWER
|
||||
_groupListView.selectionChanged += GroupListView_onSelectionChange;
|
||||
#elif UNITY_2020_1_OR_NEWER
|
||||
_groupListView.onSelectionChange += GroupListView_onSelectionChange;
|
||||
#else
|
||||
_groupListView.onSelectionChanged += GroupListView_onSelectionChange;
|
||||
@@ -657,7 +661,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 激活状态
|
||||
IActiveRule activeRule = AssetBundleCollectorSettingData.GetActiveRuleInstance(group.ActiveRuleName);
|
||||
bool isActive = activeRule.IsActiveGroup();
|
||||
bool isActive = activeRule.IsActiveGroup(new GroupData(group.GroupName));
|
||||
textField1.SetEnabled(isActive);
|
||||
}
|
||||
private void GroupListView_onSelectionChange(IEnumerable<object> objs)
|
||||
@@ -991,7 +995,7 @@ namespace YooAsset.Editor
|
||||
try
|
||||
{
|
||||
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(_ignoreRulePopupField.value.ClassName);
|
||||
CollectCommand command = new CollectCommand(EBuildMode.SimulateBuild,
|
||||
CollectCommand command = new CollectCommand(true, false,
|
||||
_packageNameTxt.value,
|
||||
_enableAddressableToogle.value,
|
||||
_locationToLowerToogle.value,
|
||||
|
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class AssetDependencyCache
|
||||
{
|
||||
private readonly AssetDependencyDatabase _database;
|
||||
|
||||
/// <summary>
|
||||
/// 初始化资源依赖缓存系统
|
||||
/// </summary>
|
||||
public AssetDependencyCache(bool useAssetDependencyDB)
|
||||
{
|
||||
if (useAssetDependencyDB)
|
||||
Debug.Log("Use asset dependency database !");
|
||||
|
||||
string databaseFilePath = "Library/AssetDependencyDB";
|
||||
_database = new AssetDependencyDatabase();
|
||||
_database.CreateDatabase(useAssetDependencyDB, databaseFilePath);
|
||||
|
||||
if (useAssetDependencyDB)
|
||||
{
|
||||
_database.SaveDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源的依赖列表
|
||||
/// </summary>
|
||||
/// <param name="assetPath">资源路径</param>
|
||||
/// <param name="recursive">递归查找所有依赖</param>
|
||||
/// <returns>返回依赖的资源路径集合</returns>
|
||||
public string[] GetDependencies(string assetPath, bool recursive = true)
|
||||
{
|
||||
// 通过本地缓存获取依赖关系
|
||||
return _database.GetDependencies(assetPath, recursive);
|
||||
|
||||
// 通过Unity引擎获取依赖关系
|
||||
//return AssetDatabase.GetDependencies(assetPath, recursive);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ddc7e04182c802b468e038777e4dd442
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,240 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源依赖数据库
|
||||
/// </summary>
|
||||
public class AssetDependencyDatabase
|
||||
{
|
||||
private const string FILE_VERSION = "1.0";
|
||||
|
||||
private class DependencyInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 此哈希函数会聚合了以下内容:源资源路径、源资源、元文件、目标平台以及导入器版本。
|
||||
/// 如果此哈希值发送变化,则说明导入资源可能已更改,因此应重新搜集依赖关系。
|
||||
/// </summary>
|
||||
public string DependHash;
|
||||
|
||||
/// <summary>
|
||||
/// 直接依赖资源的GUID列表
|
||||
/// </summary>
|
||||
public List<string> DependGUIDs = new List<string>();
|
||||
}
|
||||
|
||||
private string _databaseFilePath;
|
||||
private readonly Dictionary<string, DependencyInfo> _database = new Dictionary<string, DependencyInfo>(100000);
|
||||
|
||||
/// <summary>
|
||||
/// 创建缓存数据库
|
||||
/// </summary>
|
||||
public void CreateDatabase(bool readCacheDatabaseFile, string databaseFilePath)
|
||||
{
|
||||
_databaseFilePath = databaseFilePath;
|
||||
_database.Clear();
|
||||
|
||||
try
|
||||
{
|
||||
if (readCacheDatabaseFile && File.Exists(databaseFilePath))
|
||||
{
|
||||
// 解析缓存文件
|
||||
using var stream = File.OpenRead(databaseFilePath);
|
||||
using var reader = new BinaryReader(stream);
|
||||
string fileVersion = reader.ReadString();
|
||||
if (fileVersion != FILE_VERSION)
|
||||
throw new Exception("The database file version not match !");
|
||||
|
||||
var count = reader.ReadInt32();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var assetPath = reader.ReadString();
|
||||
var cacheInfo = new DependencyInfo
|
||||
{
|
||||
DependHash = reader.ReadString(),
|
||||
DependGUIDs = ReadStringList(reader),
|
||||
};
|
||||
_database.Add(assetPath, cacheInfo);
|
||||
}
|
||||
|
||||
// 移除无效资源
|
||||
List<string> removeList = new List<string>(10000);
|
||||
foreach (var cacheInfoPair in _database)
|
||||
{
|
||||
var assetPath = cacheInfoPair.Key;
|
||||
var assetGUID = AssetDatabase.AssetPathToGUID(assetPath);
|
||||
if (string.IsNullOrEmpty(assetGUID))
|
||||
{
|
||||
removeList.Add(assetPath);
|
||||
}
|
||||
}
|
||||
foreach (var assetPath in removeList)
|
||||
{
|
||||
_database.Remove(assetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ClearDatabase(true);
|
||||
Debug.LogError($"Failed to load cache database : {ex.Message}");
|
||||
}
|
||||
|
||||
// 查找新增或变动资源
|
||||
var allAssetPaths = AssetDatabase.GetAllAssetPaths();
|
||||
foreach (var assetPath in allAssetPaths)
|
||||
{
|
||||
if (_database.TryGetValue(assetPath, out DependencyInfo cacheInfo))
|
||||
{
|
||||
var dependHash = AssetDatabase.GetAssetDependencyHash(assetPath);
|
||||
if (dependHash.ToString() != cacheInfo.DependHash)
|
||||
{
|
||||
_database[assetPath] = CreateDependencyInfo(assetPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var newCacheInfo = CreateDependencyInfo(assetPath);
|
||||
_database.Add(assetPath, newCacheInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存缓存数据库
|
||||
/// </summary>
|
||||
public void SaveDatabase()
|
||||
{
|
||||
if (File.Exists(_databaseFilePath))
|
||||
File.Delete(_databaseFilePath);
|
||||
|
||||
try
|
||||
{
|
||||
using var stream = File.Create(_databaseFilePath);
|
||||
using var writer = new BinaryWriter(stream);
|
||||
writer.Write(FILE_VERSION);
|
||||
writer.Write(_database.Count);
|
||||
foreach (var assetPair in _database)
|
||||
{
|
||||
string assetPath = assetPair.Key;
|
||||
var assetInfo = assetPair.Value;
|
||||
writer.Write(assetPath);
|
||||
writer.Write(assetInfo.DependHash);
|
||||
WriteStringList(writer, assetInfo.DependGUIDs);
|
||||
}
|
||||
writer.Flush();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Failed to save cache database : {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理缓存数据库
|
||||
/// </summary>
|
||||
public void ClearDatabase(bool deleteDatabaseFile)
|
||||
{
|
||||
if (deleteDatabaseFile)
|
||||
{
|
||||
if (File.Exists(_databaseFilePath))
|
||||
File.Delete(_databaseFilePath);
|
||||
}
|
||||
|
||||
_database.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源的依赖列表
|
||||
/// </summary>
|
||||
public string[] GetDependencies(string assetPath, bool recursive)
|
||||
{
|
||||
// 注意:AssetDatabase.GetDependencies()方法返回结果里会踢出丢失文件!
|
||||
// 注意:AssetDatabase.GetDependencies()方法返回结果里会包含主资源路径!
|
||||
|
||||
// 注意:机制上不允许存在未收录的资源
|
||||
if (_database.ContainsKey(assetPath) == false)
|
||||
{
|
||||
throw new Exception($"Fatal : can not found cache info : {assetPath}");
|
||||
}
|
||||
|
||||
var result = new HashSet<string> { assetPath };
|
||||
CollectDependencies(assetPath, result, recursive);
|
||||
|
||||
// 注意:AssetDatabase.GetDependencies保持一致,将主资源添加到依赖列表最前面
|
||||
return result.ToArray();
|
||||
}
|
||||
private void CollectDependencies(string assetPath, HashSet<string> result, bool recursive)
|
||||
{
|
||||
if (_database.TryGetValue(assetPath, out var cacheInfo) == false)
|
||||
{
|
||||
throw new Exception($"Fatal : can not found cache info : {assetPath}");
|
||||
}
|
||||
|
||||
foreach (var dependGUID in cacheInfo.DependGUIDs)
|
||||
{
|
||||
string dependAssetPath = AssetDatabase.GUIDToAssetPath(dependGUID);
|
||||
if (string.IsNullOrEmpty(dependAssetPath))
|
||||
continue;
|
||||
|
||||
// 如果是文件夹资源
|
||||
if (AssetDatabase.IsValidFolder(dependAssetPath))
|
||||
continue;
|
||||
|
||||
// 如果已经收集过
|
||||
if (result.Contains(dependAssetPath))
|
||||
continue;
|
||||
|
||||
result.Add(dependAssetPath);
|
||||
|
||||
// 递归收集依赖
|
||||
if (recursive)
|
||||
CollectDependencies(dependAssetPath, result, recursive);
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> ReadStringList(BinaryReader reader)
|
||||
{
|
||||
var count = reader.ReadInt32();
|
||||
var values = new List<string>(count);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
values.Add(reader.ReadString());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
private void WriteStringList(BinaryWriter writer, List<string> values)
|
||||
{
|
||||
writer.Write(values.Count);
|
||||
foreach (var value in values)
|
||||
{
|
||||
writer.Write(value);
|
||||
}
|
||||
}
|
||||
private DependencyInfo CreateDependencyInfo(string assetPath)
|
||||
{
|
||||
var dependHash = AssetDatabase.GetAssetDependencyHash(assetPath);
|
||||
var dependAssetPaths = AssetDatabase.GetDependencies(assetPath, false);
|
||||
var dependGUIDs = new List<string>();
|
||||
foreach (var dependAssetPath in dependAssetPaths)
|
||||
{
|
||||
string guid = AssetDatabase.AssetPathToGUID(dependAssetPath);
|
||||
if (string.IsNullOrEmpty(guid) == false)
|
||||
{
|
||||
dependGUIDs.Add(guid);
|
||||
}
|
||||
}
|
||||
|
||||
var cacheInfo = new DependencyInfo();
|
||||
cacheInfo.DependHash = dependHash.ToString();
|
||||
cacheInfo.DependGUIDs = dependGUIDs;
|
||||
return cacheInfo;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38f3f2338cca06a42a0f845df9fbb563
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -4,9 +4,14 @@ namespace YooAsset.Editor
|
||||
public class CollectCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建模式
|
||||
/// 模拟构建模式
|
||||
/// </summary>
|
||||
public EBuildMode BuildMode { private set; get; }
|
||||
public bool SimulateBuild { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 使用资源依赖数据库
|
||||
/// </summary>
|
||||
public bool UseAssetDependencyDB { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
@@ -49,11 +54,12 @@ namespace YooAsset.Editor
|
||||
public IIgnoreRule IgnoreRule { private set; get; }
|
||||
|
||||
|
||||
public CollectCommand(EBuildMode buildMode, string packageName,
|
||||
public CollectCommand(bool simulateBuild, bool useAssetDependencyDB, string packageName,
|
||||
bool enableAddressable, bool locationToLower, bool includeAssetGUID,
|
||||
bool autoCollectShaders, bool uniqueBundleName, IIgnoreRule ignoreRule)
|
||||
{
|
||||
BuildMode = buildMode;
|
||||
SimulateBuild = simulateBuild;
|
||||
UseAssetDependencyDB = useAssetDependencyDB;
|
||||
PackageName = packageName;
|
||||
EnableAddressable = enableAddressable;
|
||||
LocationToLower = locationToLower;
|
||||
@@ -66,5 +72,16 @@ namespace YooAsset.Editor
|
||||
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
ShadersBundleName = packRuleResult.GetBundleName(packageName, uniqueBundleName);
|
||||
}
|
||||
|
||||
private AssetDependencyCache _assetDependency;
|
||||
public AssetDependencyCache AssetDependency
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_assetDependency == null)
|
||||
_assetDependency = new AssetDependencyCache(UseAssetDependencyDB);
|
||||
return _assetDependency;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,6 +1,16 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public struct GroupData
|
||||
{
|
||||
public string GroupName;
|
||||
|
||||
public GroupData(string groupName)
|
||||
{
|
||||
GroupName = groupName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 资源分组激活规则接口
|
||||
/// </summary>
|
||||
@@ -9,6 +19,6 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 是否激活分组
|
||||
/// </summary>
|
||||
bool IsActiveGroup();
|
||||
bool IsActiveGroup(GroupData data);
|
||||
}
|
||||
}
|
@@ -4,7 +4,7 @@ namespace YooAsset.Editor
|
||||
[DisplayName("启用分组")]
|
||||
public class EnableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
public bool IsActiveGroup(GroupData data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -13,7 +13,7 @@ namespace YooAsset.Editor
|
||||
[DisplayName("禁用分组")]
|
||||
public class DisableGroup : IActiveRule
|
||||
{
|
||||
public bool IsActiveGroup()
|
||||
public bool IsActiveGroup(GroupData data)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@@ -20,7 +20,8 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".unity";
|
||||
string extension = Path.GetExtension(data.AssetPath);
|
||||
return extension == ".unity" || extension == ".scene";
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -33,6 +33,14 @@ namespace YooAsset.Editor
|
||||
if (AssetDatabase.IsValidFolder(assetInfo.AssetPath))
|
||||
return true;
|
||||
|
||||
// 忽略编辑器图标资源
|
||||
if (assetInfo.AssetPath.Contains("/Gizmos/"))
|
||||
return true;
|
||||
|
||||
// 忽略编辑器专属资源
|
||||
if (assetInfo.AssetPath.Contains("/Editor/") || assetInfo.AssetPath.Contains("/Editor Resources/"))
|
||||
return true;
|
||||
|
||||
// 忽略编辑器下的类型资源
|
||||
if (assetInfo.AssetType == typeof(LightingDataAsset))
|
||||
return true;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user