mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Update YooAsset
Update YooAsset
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ namespace YooAsset.Editor
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -14,6 +14,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public ECompressOption CompressOption = ECompressOption.Uncompressed;
|
||||
|
||||
/// <summary>
|
||||
/// 从AssetBundle文件头里剥离Unity版本信息
|
||||
/// </summary>
|
||||
public bool StripUnityVersion = false;
|
||||
|
||||
/// <summary>
|
||||
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
/// <summary>
|
||||
/// 初始化日志系统
|
||||
/// </summary>
|
||||
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}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭日志系统
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ namespace YooAsset.Editor
|
||||
BuildPipelineIsNullOrEmpty = 116,
|
||||
BuildBundleTypeIsUnknown = 117,
|
||||
RecommendScriptBuildPipeline = 130,
|
||||
BuiltinShadersBundleNameIsNull = 131,
|
||||
|
||||
// TaskGetBuildMap
|
||||
RemoveInvalidTags = 200,
|
||||
|
Reference in New Issue
Block a user