mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
Update YooAsset
Update YooAsset
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
#if YOO_ASSET_EXPERIMENT
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public class MacroDefine
|
public class MacroDefine
|
||||||
@@ -15,3 +16,4 @@ namespace YooAsset.Editor
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@@ -5,6 +5,7 @@ using System.Text;
|
|||||||
using System.Xml;
|
using System.Xml;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
|
#if YOO_ASSET_EXPERIMENT
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
[InitializeOnLoad]
|
[InitializeOnLoad]
|
||||||
@@ -22,13 +23,21 @@ namespace YooAsset.Editor
|
|||||||
return content;
|
return content;
|
||||||
|
|
||||||
// 将修改后的XML结构重新输出为文本
|
// 将修改后的XML结构重新输出为文本
|
||||||
var stringWriter = new StringWriter();
|
using (var memoryStream = new MemoryStream())
|
||||||
var writerSettings = new XmlWriterSettings();
|
{
|
||||||
writerSettings.Indent = true;
|
var writerSettings = new XmlWriterSettings
|
||||||
var xmlWriter = XmlWriter.Create(stringWriter, writerSettings);
|
{
|
||||||
xmlDoc.WriteTo(xmlWriter);
|
Indent = true,
|
||||||
xmlWriter.Flush();
|
Encoding = new UTF8Encoding(false), //无BOM
|
||||||
return stringWriter.ToString();
|
OmitXmlDeclaration = false
|
||||||
|
};
|
||||||
|
|
||||||
|
using (var xmlWriter = XmlWriter.Create(memoryStream, writerSettings))
|
||||||
|
{
|
||||||
|
xmlDoc.Save(xmlWriter);
|
||||||
|
}
|
||||||
|
return Encoding.UTF8.GetString(memoryStream.ToArray());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -94,3 +103,4 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
@@ -32,8 +32,9 @@ namespace YooAsset.Editor
|
|||||||
var buildParametersContext = new BuildParametersContext(buildParameters);
|
var buildParametersContext = new BuildParametersContext(buildParameters);
|
||||||
_buildContext.SetContextObject(buildParametersContext);
|
_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}");
|
BuildLogger.Log($"Begin to build package : {buildParameters.PackageName} by {buildParameters.BuildPipeline}");
|
||||||
@@ -50,6 +51,9 @@ namespace YooAsset.Editor
|
|||||||
BuildLogger.Error(buildResult.ErrorInfo);
|
BuildLogger.Error(buildResult.ErrorInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭日志系统
|
||||||
|
BuildLogger.Shuntdown();
|
||||||
|
|
||||||
return buildResult;
|
return buildResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@ namespace YooAsset.Editor
|
|||||||
void IBuildTask.Run(BuildContext context)
|
void IBuildTask.Run(BuildContext context)
|
||||||
{
|
{
|
||||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||||
var buildParameters = buildParametersContext.Parameters;
|
var buildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||||
|
|
||||||
// 检测基础构建参数
|
// 检测基础构建参数
|
||||||
buildParametersContext.CheckBuildParameters();
|
buildParametersContext.CheckBuildParameters();
|
||||||
@@ -50,6 +50,13 @@ namespace YooAsset.Editor
|
|||||||
{
|
{
|
||||||
BuildLogger.Log($"Create pipeline output directory: {pipelineOutputDirectory}");
|
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>
|
/// </summary>
|
||||||
public ECompressOption CompressOption = ECompressOption.Uncompressed;
|
public ECompressOption CompressOption = ECompressOption.Uncompressed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 从AssetBundle文件头里剥离Unity版本信息
|
||||||
|
/// </summary>
|
||||||
|
public bool StripUnityVersion = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
|
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -70,6 +75,9 @@ namespace YooAsset.Editor
|
|||||||
else
|
else
|
||||||
throw new System.NotImplementedException(CompressOption.ToString());
|
throw new System.NotImplementedException(CompressOption.ToString());
|
||||||
|
|
||||||
|
if (StripUnityVersion)
|
||||||
|
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.StripUnityVersion;
|
||||||
|
|
||||||
if (DisableWriteTypeTree)
|
if (DisableWriteTypeTree)
|
||||||
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree;
|
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree;
|
||||||
|
|
||||||
|
@@ -2,37 +2,100 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
internal static class BuildLogger
|
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;
|
_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)
|
public static void Log(string message)
|
||||||
{
|
{
|
||||||
if (_enableLog)
|
if (_enableLog)
|
||||||
{
|
{
|
||||||
|
WriteLog("INFO", message);
|
||||||
Debug.Log(message);
|
Debug.Log(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static void Warning(string message)
|
public static void Warning(string message)
|
||||||
{
|
{
|
||||||
Debug.LogWarning(message);
|
if (_enableLog)
|
||||||
|
{
|
||||||
|
WriteLog("WARN", message);
|
||||||
|
Debug.LogWarning(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static void Error(string 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)
|
public static string GetErrorMessage(ErrorCode code, string message)
|
||||||
{
|
{
|
||||||
return $"[ErrorCode{(int)code}] {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,
|
BuildPipelineIsNullOrEmpty = 116,
|
||||||
BuildBundleTypeIsUnknown = 117,
|
BuildBundleTypeIsUnknown = 117,
|
||||||
RecommendScriptBuildPipeline = 130,
|
RecommendScriptBuildPipeline = 130,
|
||||||
|
BuiltinShadersBundleNameIsNull = 131,
|
||||||
|
|
||||||
// TaskGetBuildMap
|
// TaskGetBuildMap
|
||||||
RemoveInvalidTags = 200,
|
RemoveInvalidTags = 200,
|
||||||
|
@@ -259,10 +259,13 @@ namespace YooAsset.Editor
|
|||||||
}
|
}
|
||||||
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
private List<string> GetAssetTags(AssetBundleCollectorGroup group)
|
||||||
{
|
{
|
||||||
List<string> tags = EditorTools.StringToStringList(group.AssetTags, ';');
|
List<string> result = EditorTools.StringToStringList(AssetTags, ';');
|
||||||
List<string> temper = EditorTools.StringToStringList(AssetTags, ';');
|
if (CollectorType == ECollectorType.MainAssetCollector)
|
||||||
tags.AddRange(temper);
|
{
|
||||||
return tags;
|
List<string> temps = EditorTools.StringToStringList(group.AssetTags, ';');
|
||||||
|
result.AddRange(temps);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
|
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
|
||||||
{
|
{
|
||||||
|
@@ -296,6 +296,7 @@ namespace YooAsset.Editor
|
|||||||
string filePath = $"{resultPath}/{nameof(DebugReport)}_{_currentReport.FrameCount}.json";
|
string filePath = $"{resultPath}/{nameof(DebugReport)}_{_currentReport.FrameCount}.json";
|
||||||
string fileContent = JsonUtility.ToJson(_currentReport, true);
|
string fileContent = JsonUtility.ToJson(_currentReport, true);
|
||||||
FileUtility.WriteAllText(filePath, fileContent);
|
FileUtility.WriteAllText(filePath, fileContent);
|
||||||
|
Debug.Log($"Debug report file saved : {filePath}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||||
|
@@ -122,7 +122,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_disableUnityWebCache)
|
if (_disableUnityWebCache)
|
||||||
{
|
{
|
||||||
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, 0);
|
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, Bundle.UnityCRC);
|
||||||
#if UNITY_2020_3_OR_NEWER
|
#if UNITY_2020_3_OR_NEWER
|
||||||
downloadhandler.autoLoadAssetBundle = false;
|
downloadhandler.autoLoadAssetBundle = false;
|
||||||
#endif
|
#endif
|
||||||
@@ -132,9 +132,8 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
// 注意:优先从浏览器缓存里获取文件
|
// 注意:优先从浏览器缓存里获取文件
|
||||||
// The file hash defining the version of the asset bundle.
|
// The file hash defining the version of the asset bundle.
|
||||||
uint unityCRC = Bundle.UnityCRC;
|
|
||||||
Hash128 fileHash = Hash128.Parse(Bundle.FileHash);
|
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
|
#if UNITY_2020_3_OR_NEWER
|
||||||
downloadhandler.autoLoadAssetBundle = false;
|
downloadhandler.autoLoadAssetBundle = false;
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user