diff --git a/UnityProject/Packages/YooAsset/Editor/Assembly/MacroDefine.cs b/UnityProject/Packages/YooAsset/Editor/Assembly/MacroDefine.cs index a647b43d..c7d92919 100644 --- a/UnityProject/Packages/YooAsset/Editor/Assembly/MacroDefine.cs +++ b/UnityProject/Packages/YooAsset/Editor/Assembly/MacroDefine.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; +#if YOO_ASSET_EXPERIMENT namespace YooAsset.Editor { public class MacroDefine @@ -15,3 +16,4 @@ namespace YooAsset.Editor }; } } +#endif \ No newline at end of file diff --git a/UnityProject/Packages/YooAsset/Editor/Assembly/MacroProcessor.cs b/UnityProject/Packages/YooAsset/Editor/Assembly/MacroProcessor.cs index 265fc1e6..c2249ba9 100644 --- a/UnityProject/Packages/YooAsset/Editor/Assembly/MacroProcessor.cs +++ b/UnityProject/Packages/YooAsset/Editor/Assembly/MacroProcessor.cs @@ -5,6 +5,7 @@ using System.Text; using System.Xml; using UnityEditor; +#if YOO_ASSET_EXPERIMENT namespace YooAsset.Editor { [InitializeOnLoad] @@ -22,13 +23,21 @@ namespace YooAsset.Editor return content; // 将修改后的XML结构重新输出为文本 - var stringWriter = new StringWriter(); - var writerSettings = new XmlWriterSettings(); - writerSettings.Indent = true; - var xmlWriter = XmlWriter.Create(stringWriter, writerSettings); - xmlDoc.WriteTo(xmlWriter); - xmlWriter.Flush(); - return stringWriter.ToString(); + using (var memoryStream = new MemoryStream()) + { + var writerSettings = new XmlWriterSettings + { + Indent = true, + Encoding = new UTF8Encoding(false), //无BOM + OmitXmlDeclaration = false + }; + + using (var xmlWriter = XmlWriter.Create(memoryStream, writerSettings)) + { + xmlDoc.Save(xmlWriter); + } + return Encoding.UTF8.GetString(memoryStream.ToArray()); + } } /// @@ -94,3 +103,4 @@ namespace YooAsset.Editor } } } +#endif \ No newline at end of file diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs index fec66722..17b45bf1 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilder.cs @@ -32,8 +32,9 @@ namespace YooAsset.Editor var buildParametersContext = new BuildParametersContext(buildParameters); _buildContext.SetContextObject(buildParametersContext); - // 初始化日志 - BuildLogger.InitLogger(enableLog); + // 初始化日志系统 + string logFilePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/buildInfo.log"; + BuildLogger.InitLogger(enableLog, logFilePath); // 执行构建流程 BuildLogger.Log($"Begin to build package : {buildParameters.PackageName} by {buildParameters.BuildPipeline}"); @@ -50,6 +51,9 @@ namespace YooAsset.Editor BuildLogger.Error(buildResult.ErrorInfo); } + // 关闭日志系统 + BuildLogger.Shuntdown(); + return buildResult; } } diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskPrepare_SBP.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskPrepare_SBP.cs index 438c758d..62c7f741 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskPrepare_SBP.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskPrepare_SBP.cs @@ -11,7 +11,7 @@ namespace YooAsset.Editor void IBuildTask.Run(BuildContext context) { var buildParametersContext = context.GetContextObject(); - var buildParameters = buildParametersContext.Parameters; + var buildParameters = buildParametersContext.Parameters as ScriptableBuildParameters; // 检测基础构建参数 buildParametersContext.CheckBuildParameters(); @@ -50,6 +50,13 @@ namespace YooAsset.Editor { BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}"); } + + // 检测内置着色器资源包名称 + if (string.IsNullOrEmpty(buildParameters.BuiltinShadersBundleName)) + { + string warning = BuildLogger.GetErrorMessage(ErrorCode.BuiltinShadersBundleNameIsNull, $"Builtin shaders bundle name is null. It will cause resource redundancy !"); + BuildLogger.Warning(warning); + } } } } \ No newline at end of file diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/ScriptableBuildParameters.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/ScriptableBuildParameters.cs index 2f622193..2767ce15 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/ScriptableBuildParameters.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/ScriptableBuildParameters.cs @@ -14,6 +14,11 @@ namespace YooAsset.Editor /// public ECompressOption CompressOption = ECompressOption.Uncompressed; + /// + /// 从AssetBundle文件头里剥离Unity版本信息 + /// + public bool StripUnityVersion = false; + /// /// 禁止写入类型树结构(可以降低包体和内存并提高加载效率) /// @@ -70,6 +75,9 @@ namespace YooAsset.Editor else throw new System.NotImplementedException(CompressOption.ToString()); + if (StripUnityVersion) + buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.StripUnityVersion; + if (DisableWriteTypeTree) buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree; diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildLogger.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildLogger.cs index abac194a..b4571229 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildLogger.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildSystem/BuildLogger.cs @@ -2,37 +2,100 @@ using System.IO; using System.Collections.Generic; using UnityEngine; +using System.Text; namespace YooAsset.Editor { internal static class BuildLogger { - private static bool _enableLog = true; + private const int MAX_LOG_BUFFER_SIZE = 1024 * 1024 * 2; //2MB - public static void InitLogger(bool enableLog) + private static bool _enableLog = true; + private static string _logFilePath; + + private static readonly object _lockObj = new object(); + private static readonly StringBuilder _logBuilder = new StringBuilder(MAX_LOG_BUFFER_SIZE); + + /// + /// 初始化日志系统 + /// + public static void InitLogger(bool enableLog, string logFilePath) { _enableLog = enableLog; + _logFilePath = logFilePath; + _logBuilder.Clear(); + + if (_enableLog) + { + if (string.IsNullOrEmpty(_logFilePath)) + throw new Exception("Log file path is null or empty !"); + + Debug.Log($"Logger initialized at {DateTime.Now:yyyy-MM-dd HH:mm:ss}"); + } + } + + /// + /// 关闭日志系统 + /// + public static void Shuntdown() + { + if (_enableLog) + { + lock (_lockObj) + { + try + { + if (File.Exists(_logFilePath)) + File.Delete(_logFilePath); + + FileUtility.CreateFileDirectory(_logFilePath); + File.WriteAllText(_logFilePath, _logBuilder.ToString(), Encoding.UTF8); + _logBuilder.Clear(); + } + catch (Exception ex) + { + Debug.LogError($"Failed to write log file: {ex.Message}"); + } + } + } } public static void Log(string message) { if (_enableLog) { + WriteLog("INFO", message); Debug.Log(message); } } public static void Warning(string message) { - Debug.LogWarning(message); + if (_enableLog) + { + WriteLog("WARN", message); + Debug.LogWarning(message); + } } public static void Error(string message) { - Debug.LogError(message); + if (_enableLog) + { + WriteLog("ERROR", message); + Debug.LogError(message); + } } - public static string GetErrorMessage(ErrorCode code, string message) { return $"[ErrorCode{(int)code}] {message}"; } + + private static void WriteLog(string level, string message) + { + lock (_lockObj) + { + string logEntry = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [{level}] {message}"; + _logBuilder.AppendLine(logEntry); + } + } } } \ No newline at end of file diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildSystem/ErrorCode.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildSystem/ErrorCode.cs index ed45bd00..20d4f99e 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildSystem/ErrorCode.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleBuilder/BuildSystem/ErrorCode.cs @@ -15,6 +15,7 @@ namespace YooAsset.Editor BuildPipelineIsNullOrEmpty = 116, BuildBundleTypeIsUnknown = 117, RecommendScriptBuildPipeline = 130, + BuiltinShadersBundleNameIsNull = 131, // TaskGetBuildMap RemoveInvalidTags = 200, diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs index 0ecad2ca..796694ce 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleCollector/AssetBundleCollector.cs @@ -259,10 +259,13 @@ namespace YooAsset.Editor } private List GetAssetTags(AssetBundleCollectorGroup group) { - List tags = EditorTools.StringToStringList(group.AssetTags, ';'); - List temper = EditorTools.StringToStringList(AssetTags, ';'); - tags.AddRange(temper); - return tags; + List result = EditorTools.StringToStringList(AssetTags, ';'); + if (CollectorType == ECollectorType.MainAssetCollector) + { + List temps = EditorTools.StringToStringList(group.AssetTags, ';'); + result.AddRange(temps); + } + return result; } private List GetAllDependencies(CollectCommand command, string mainAssetPath) { diff --git a/UnityProject/Packages/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs b/UnityProject/Packages/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs index 64c0e395..4e3fef76 100644 --- a/UnityProject/Packages/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs +++ b/UnityProject/Packages/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs @@ -296,6 +296,7 @@ namespace YooAsset.Editor string filePath = $"{resultPath}/{nameof(DebugReport)}_{_currentReport.FrameCount}.json"; string fileContent = JsonUtility.ToJson(_currentReport, true); FileUtility.WriteAllText(filePath, fileContent); + Debug.Log($"Debug report file saved : {filePath}"); } } private void OnSearchKeyWordChange(ChangeEvent e) diff --git a/UnityProject/Packages/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadWebNormalAssetBundleOperation.cs b/UnityProject/Packages/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadWebNormalAssetBundleOperation.cs index b58bbca9..58425012 100644 --- a/UnityProject/Packages/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadWebNormalAssetBundleOperation.cs +++ b/UnityProject/Packages/YooAsset/Runtime/FileSystem/Operation/Internal/DownloadWebNormalAssetBundleOperation.cs @@ -122,7 +122,7 @@ namespace YooAsset { if (_disableUnityWebCache) { - var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, 0); + var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, Bundle.UnityCRC); #if UNITY_2020_3_OR_NEWER downloadhandler.autoLoadAssetBundle = false; #endif @@ -132,9 +132,8 @@ namespace YooAsset { // 注意:优先从浏览器缓存里获取文件 // The file hash defining the version of the asset bundle. - uint unityCRC = Bundle.UnityCRC; Hash128 fileHash = Hash128.Parse(Bundle.FileHash); - var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, fileHash, unityCRC); + var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, fileHash, Bundle.UnityCRC); #if UNITY_2020_3_OR_NEWER downloadhandler.autoLoadAssetBundle = false; #endif