【m】框架大更新
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class BuildContext
|
||||
{
|
||||
private readonly Dictionary<System.Type, IContextObject> _contextObjects = new Dictionary<System.Type, IContextObject>();
|
||||
|
||||
/// <summary>
|
||||
/// 清空所有上下文对象
|
||||
/// </summary>
|
||||
public void ClearAllContext()
|
||||
{
|
||||
_contextObjects.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置上下文对象
|
||||
/// </summary>
|
||||
public void SetContextObject(IContextObject contextObject)
|
||||
{
|
||||
if (contextObject == null)
|
||||
throw new ArgumentNullException("contextObject");
|
||||
|
||||
var type = contextObject.GetType();
|
||||
if (_contextObjects.ContainsKey(type))
|
||||
throw new Exception($"Context object {type} is already existed.");
|
||||
|
||||
_contextObjects.Add(type, contextObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取上下文对象
|
||||
/// </summary>
|
||||
public T GetContextObject<T>() where T : IContextObject
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (_contextObjects.TryGetValue(type, out IContextObject contextObject))
|
||||
{
|
||||
return (T)contextObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Not found context object : {type}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取上下文对象
|
||||
/// </summary>
|
||||
public T TryGetContextObject<T>() where T : IContextObject
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (_contextObjects.TryGetValue(type, out IContextObject contextObject))
|
||||
{
|
||||
return (T)contextObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb46a91f7edad9e4b8814829a33df014
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Text;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal static class BuildLogger
|
||||
{
|
||||
private const int MAX_LOG_BUFFER_SIZE = 1024 * 1024 * 2; //2MB
|
||||
|
||||
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)
|
||||
{
|
||||
if (_enableLog)
|
||||
{
|
||||
WriteLog("WARN", message);
|
||||
Debug.LogWarning(message);
|
||||
}
|
||||
}
|
||||
public static void Error(string 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 851e558739fd70147be0ea90e2e88518
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建结果
|
||||
/// </summary>
|
||||
public class BuildResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建是否成功
|
||||
/// </summary>
|
||||
public bool Success;
|
||||
|
||||
/// <summary>
|
||||
/// 构建失败的任务
|
||||
/// </summary>
|
||||
public string FailedTask;
|
||||
|
||||
/// <summary>
|
||||
/// 构建失败的信息
|
||||
/// </summary>
|
||||
public string ErrorInfo;
|
||||
|
||||
/// <summary>
|
||||
/// 构建失败的堆栈
|
||||
/// </summary>
|
||||
public string ErrorStack;
|
||||
|
||||
/// <summary>
|
||||
/// 输出的补丁包目录
|
||||
/// </summary>
|
||||
public string OutputPackageDirectory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e26bdcacb014bb4490f18272127050d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class BuildRunner
|
||||
{
|
||||
private static Stopwatch _buildWatch;
|
||||
|
||||
/// <summary>
|
||||
/// 总耗时
|
||||
/// </summary>
|
||||
public static int TotalSeconds = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 执行构建流程
|
||||
/// </summary>
|
||||
/// <returns>如果成功返回TRUE,否则返回FALSE</returns>
|
||||
public static BuildResult Run(List<IBuildTask> pipeline, BuildContext context)
|
||||
{
|
||||
if (pipeline == null)
|
||||
throw new ArgumentNullException("pipeline");
|
||||
if (context == null)
|
||||
throw new ArgumentNullException("context");
|
||||
|
||||
BuildResult buildResult = new BuildResult();
|
||||
buildResult.Success = true;
|
||||
TotalSeconds = 0;
|
||||
for (int i = 0; i < pipeline.Count; i++)
|
||||
{
|
||||
IBuildTask task = pipeline[i];
|
||||
try
|
||||
{
|
||||
_buildWatch = Stopwatch.StartNew();
|
||||
string taskName = task.GetType().Name.Split('_')[0];
|
||||
BuildLogger.Log($"--------------------------------------------->{taskName}<--------------------------------------------");
|
||||
task.Run(context);
|
||||
_buildWatch.Stop();
|
||||
|
||||
// 统计耗时
|
||||
int seconds = GetBuildSeconds();
|
||||
TotalSeconds += seconds;
|
||||
BuildLogger.Log($"{taskName} It takes {seconds} seconds in total");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
EditorTools.ClearProgressBar();
|
||||
buildResult.FailedTask = task.GetType().Name;
|
||||
buildResult.ErrorInfo = e.ToString();
|
||||
buildResult.ErrorStack = e.StackTrace;
|
||||
buildResult.Success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 返回运行结果
|
||||
BuildLogger.Log($"Total build process time: {TotalSeconds} seconds");
|
||||
return buildResult;
|
||||
}
|
||||
|
||||
private static int GetBuildSeconds()
|
||||
{
|
||||
float seconds = _buildWatch.ElapsedMilliseconds / 1000f;
|
||||
return (int)seconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bedcc06ee301034cade6170f9771d93
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
internal enum ErrorCode
|
||||
{
|
||||
// TaskPrepare
|
||||
ThePipelineIsBuiding = 100,
|
||||
FoundUnsavedScene = 101,
|
||||
NoBuildTarget = 110,
|
||||
PackageNameIsNullOrEmpty = 111,
|
||||
PackageVersionIsNullOrEmpty = 112,
|
||||
BuildOutputRootIsNullOrEmpty = 113,
|
||||
BuildinFileRootIsNullOrEmpty = 114,
|
||||
PackageOutputDirectoryExists = 115,
|
||||
BuildPipelineIsNullOrEmpty = 116,
|
||||
BuildBundleTypeIsUnknown = 117,
|
||||
RecommendScriptBuildPipeline = 130,
|
||||
BuiltinShadersBundleNameIsNull = 131,
|
||||
|
||||
// TaskGetBuildMap
|
||||
RemoveInvalidTags = 200,
|
||||
FoundUndependedAsset = 201,
|
||||
PackAssetListIsEmpty = 202,
|
||||
NotSupportMultipleRawAsset = 210,
|
||||
|
||||
// TaskBuilding
|
||||
UnityEngineBuildFailed = 300,
|
||||
UnityEngineBuildFatal = 301,
|
||||
|
||||
// TaskUpdateBundleInfo
|
||||
CharactersOverTheLimit = 400,
|
||||
NotFoundUnityBundleHash = 401,
|
||||
NotFoundUnityBundleCRC = 402,
|
||||
BundleTempSizeIsZero = 403,
|
||||
|
||||
// TaskVerifyBuildResult
|
||||
UnintendedBuildBundle = 500,
|
||||
UnintendedBuildResult = 501,
|
||||
|
||||
// TaskCreateManifest
|
||||
NotFoundUnityBundleInBuildResult = 600,
|
||||
FoundStrayBundle = 601,
|
||||
BundleHashConflict = 602,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f038e615f0fb094fb40138c2e0b07b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public interface IBuildTask
|
||||
{
|
||||
void Run(BuildContext context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cadfee738c5899147942a441df7531ee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public interface IContextObject
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d60185a4ac0b1b34e835e5b4a1d82783
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user