Update YooAsset

pull/4/head
hevinci 2022-03-09 21:53:01 +08:00
parent c3ecca7cfd
commit 1c7b90806c
77 changed files with 596 additions and 604 deletions

View File

@ -1,8 +1,11 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEditor.UIElements;
public class AssetBundleBrowserWindow namespace YooAsset.Editor
{ {
public class AssetBundleBrowserWindow
{
}
} }

View File

@ -3,7 +3,6 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using YooAsset.Utility;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using YooAsset.Utility;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
@ -125,7 +124,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 从输出目录加载补丁清单文件 /// 从输出目录加载补丁清单文件
/// </summary> /// </summary>
public static PatchManifest LoadPatchManifestFile(string fileDirectory) internal static PatchManifest LoadPatchManifestFile(string fileDirectory)
{ {
string filePath = $"{fileDirectory}/{ResourceSettingData.Setting.PatchManifestFileName}"; string filePath = $"{fileDirectory}/{ResourceSettingData.Setting.PatchManifestFileName}";
if (File.Exists(filePath) == false) if (File.Exists(filePath) == false)

View File

@ -2,7 +2,6 @@
using System.IO; using System.IO;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using YooAsset.Utility;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {

View File

@ -3,7 +3,6 @@ using System.Linq;
using System.IO; using System.IO;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using YooAsset.Utility;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {

View File

@ -4,7 +4,6 @@ using System.Linq;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using YooAsset.Utility;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {

View File

@ -2,7 +2,6 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using YooAsset.Utility;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {

View File

@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using YooAsset.Utility;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {

View File

@ -4,7 +4,6 @@ using System.Xml;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using YooAsset.Utility;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {

View File

@ -1,7 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using UnityEditor; using UnityEditor;
using YooAsset.Utility;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: f3763af65a2f76945bd4a6adc720ec07 guid: 5b503bf79c4303d4794d7c9414a4c201
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View File

@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset.Editor
{
public class AssetBundleProfilerWindow
{
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 8ce33ab90add0ab4aa7063977e23284e guid: 7375e313be9e6b24ab7193e64a67fa07
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -8,7 +8,6 @@ using System.Text.RegularExpressions;
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using UnityEditor.Animations; using UnityEditor.Animations;
using YooAsset.Utility;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {

View File

@ -1,5 +1,4 @@
using System.IO; using System.IO;
using YooAsset.Utility;
namespace YooAsset namespace YooAsset
{ {
@ -113,7 +112,7 @@ namespace YooAsset
} }
// 没有找到同名的资源文件 // 没有找到同名的资源文件
Logger.Warning($"Not found asset : {filePath}"); YooLogger.Warning($"Not found asset : {filePath}");
return filePath; return filePath;
#else #else
throw new System.NotImplementedException(); throw new System.NotImplementedException();

View File

@ -307,7 +307,7 @@ namespace YooAsset
DebugSummy.DebugProviderInfo providerInfo = new DebugSummy.DebugProviderInfo(); DebugSummy.DebugProviderInfo providerInfo = new DebugSummy.DebugProviderInfo();
providerInfo.AssetPath = provider.AssetPath; providerInfo.AssetPath = provider.AssetPath;
providerInfo.RefCount = provider.RefCount; providerInfo.RefCount = provider.RefCount;
providerInfo.States = provider.States; providerInfo.States = (int)provider.States;
providerInfo.BundleInfos.Clear(); providerInfo.BundleInfos.Clear();
summy.ProviderInfos.Add(providerInfo); summy.ProviderInfos.Add(providerInfo);

View File

@ -1,8 +1,8 @@
 
namespace YooAsset namespace YooAsset
{ {
public interface IBundleServices internal interface IBundleServices
{ {
/// <summary> /// <summary>
/// 获取AssetBundle的信息 /// 获取AssetBundle的信息
/// </summary> /// </summary>

View File

@ -34,7 +34,7 @@ namespace YooAsset
} }
else else
{ {
Logger.Warning($"Scene is invalid or not loaded : {Scene.name}"); YooLogger.Warning($"Scene is invalid or not loaded : {Scene.name}");
return false; return false;
} }
} }

View File

@ -136,7 +136,7 @@ namespace YooAsset
// 注意Unity2017.4编辑器模式下如果AssetBundle文件不存在会导致编辑器崩溃这里做了预判。 // 注意Unity2017.4编辑器模式下如果AssetBundle文件不存在会导致编辑器崩溃这里做了预判。
if (System.IO.File.Exists(BundleFileInfo.LocalPath) == false) if (System.IO.File.Exists(BundleFileInfo.LocalPath) == false)
{ {
Logger.Warning($"Not found assetBundle file : {BundleFileInfo.LocalPath}"); YooLogger.Warning($"Not found assetBundle file : {BundleFileInfo.LocalPath}");
States = ELoaderStates.Fail; States = ELoaderStates.Fail;
return; return;
} }
@ -188,7 +188,7 @@ namespace YooAsset
if (_isWaitForAsyncComplete) if (_isWaitForAsyncComplete)
{ {
// 强制挂起主线程(注意:该操作会很耗时) // 强制挂起主线程(注意:该操作会很耗时)
Logger.Warning("Suspend the main thread to load unity bundle."); YooLogger.Warning("Suspend the main thread to load unity bundle.");
CacheBundle = _cacheRequest.assetBundle; CacheBundle = _cacheRequest.assetBundle;
} }
else else
@ -202,7 +202,7 @@ namespace YooAsset
// Check error // Check error
if (CacheBundle == null) if (CacheBundle == null)
{ {
Logger.Error($"Failed to load assetBundle file : {BundleFileInfo.BundleName}"); YooLogger.Error($"Failed to load assetBundle file : {BundleFileInfo.BundleName}");
States = ELoaderStates.Fail; States = ELoaderStates.Fail;
} }
else else
@ -302,7 +302,7 @@ namespace YooAsset
if (_isShowWaitForAsyncError == false) if (_isShowWaitForAsyncError == false)
{ {
_isShowWaitForAsyncError = true; _isShowWaitForAsyncError = true;
Logger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {States}"); YooLogger.Error($"WaitForAsyncComplete failed ! BundleName : {BundleFileInfo.BundleName} States : {States}");
} }
break; break;
} }

View File

@ -74,7 +74,7 @@ namespace YooAsset
debugInfo.BundleName = loader.BundleFileInfo.BundleName; debugInfo.BundleName = loader.BundleFileInfo.BundleName;
debugInfo.Version = loader.BundleFileInfo.Version; debugInfo.Version = loader.BundleFileInfo.Version;
debugInfo.RefCount = loader.RefCount; debugInfo.RefCount = loader.RefCount;
debugInfo.States = loader.States; debugInfo.States = (int)loader.States;
output.Add(debugInfo); output.Add(debugInfo);
} }
} }

View File

@ -61,7 +61,7 @@ namespace YooAsset
public void Release() public void Release()
{ {
if (RefCount <= 0) if (RefCount <= 0)
Logger.Warning("Asset provider reference count is already zero. There may be resource leaks !"); YooLogger.Warning("Asset provider reference count is already zero. There may be resource leaks !");
RefCount--; RefCount--;
} }
@ -97,7 +97,7 @@ namespace YooAsset
// 验证结果 // 验证结果
if (IsDone == false) if (IsDone == false)
{ {
Logger.Warning($"WaitForAsyncComplete failed to loading : {AssetPath}"); YooLogger.Warning($"WaitForAsyncComplete failed to loading : {AssetPath}");
} }
} }

View File

@ -84,7 +84,7 @@ namespace YooAsset
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
// 强制挂起主线程(注意:该操作会很耗时) // 强制挂起主线程(注意:该操作会很耗时)
Logger.Warning("Suspend the main thread to load unity asset."); YooLogger.Warning("Suspend the main thread to load unity asset.");
AssetObject = _cacheRequest.asset; AssetObject = _cacheRequest.asset;
} }
else else
@ -97,7 +97,7 @@ namespace YooAsset
States = AssetObject == null ? EAssetStates.Fail : EAssetStates.Success; States = AssetObject == null ? EAssetStates.Fail : EAssetStates.Success;
if (States == EAssetStates.Fail) if (States == EAssetStates.Fail)
Logger.Warning($"Failed to load asset : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}"); YooLogger.Warning($"Failed to load asset : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}");
InvokeCompletion(); InvokeCompletion();
} }
} }

View File

@ -42,7 +42,7 @@ namespace YooAsset
ownerInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName; ownerInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName;
ownerInfo.Version = OwnerBundle.BundleFileInfo.Version; ownerInfo.Version = OwnerBundle.BundleFileInfo.Version;
ownerInfo.RefCount = OwnerBundle.RefCount; ownerInfo.RefCount = OwnerBundle.RefCount;
ownerInfo.States = OwnerBundle.States; ownerInfo.States = (int)OwnerBundle.States;
output.Add(ownerInfo); output.Add(ownerInfo);
DependBundles.GetBundleDebugInfos(output); DependBundles.GetBundleDebugInfos(output);

View File

@ -64,7 +64,7 @@ namespace YooAsset
} }
else else
{ {
Logger.Warning($"Failed to load scene : {AssetName}"); YooLogger.Warning($"Failed to load scene : {AssetName}");
States = EAssetStates.Fail; States = EAssetStates.Fail;
InvokeCompletion(); InvokeCompletion();
} }

View File

@ -84,7 +84,7 @@ namespace YooAsset
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
{ {
// 强制挂起主线程(注意:该操作会很耗时) // 强制挂起主线程(注意:该操作会很耗时)
Logger.Warning("Suspend the main thread to load unity asset."); YooLogger.Warning("Suspend the main thread to load unity asset.");
AllAssets = _cacheRequest.allAssets; AllAssets = _cacheRequest.allAssets;
} }
else else
@ -97,7 +97,7 @@ namespace YooAsset
States = AllAssets == null ? EAssetStates.Fail : EAssetStates.Success; States = AllAssets == null ? EAssetStates.Fail : EAssetStates.Success;
if (States == EAssetStates.Fail) if (States == EAssetStates.Fail)
Logger.Warning($"Failed to load sub assets : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}"); YooLogger.Warning($"Failed to load sub assets : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}");
InvokeCompletion(); InvokeCompletion();
} }
} }

View File

@ -59,7 +59,7 @@ namespace YooAsset
{ {
States = AssetObject == null ? EAssetStates.Fail : EAssetStates.Success; States = AssetObject == null ? EAssetStates.Fail : EAssetStates.Success;
if (States == EAssetStates.Fail) if (States == EAssetStates.Fail)
Logger.Warning($"Failed to load asset object : {AssetPath}"); YooLogger.Warning($"Failed to load asset object : {AssetPath}");
InvokeCompletion(); InvokeCompletion();
} }
#endif #endif

View File

@ -46,7 +46,7 @@ namespace YooAsset
} }
else else
{ {
Logger.Warning($"Failed to load scene : {AssetName}"); YooLogger.Warning($"Failed to load scene : {AssetName}");
States = EAssetStates.Fail; States = EAssetStates.Fail;
InvokeCompletion(); InvokeCompletion();
} }

View File

@ -66,7 +66,7 @@ namespace YooAsset
{ {
States = AllAssets == null ? EAssetStates.Fail : EAssetStates.Success; States = AllAssets == null ? EAssetStates.Fail : EAssetStates.Success;
if (States == EAssetStates.Fail) if (States == EAssetStates.Fail)
Logger.Warning($"Failed to load all asset object : {AssetPath}"); YooLogger.Warning($"Failed to load all asset object : {AssetPath}");
InvokeCompletion(); InvokeCompletion();
} }
#endif #endif

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal class OperationUpdater internal class OperationSystem
{ {
private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100); private static readonly List<AsyncOperationBase> _operations = new List<AsyncOperationBase>(100);

View File

@ -2,7 +2,6 @@
using System.IO; using System.IO;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using YooAsset.Utility;
namespace YooAsset namespace YooAsset
{ {
@ -62,7 +61,7 @@ namespace YooAsset
// 创建新的下载器 // 创建新的下载器
{ {
Logger.Log($"Beginning to download file : {bundleInfo.BundleName} URL : {bundleInfo.RemoteMainURL}"); YooLogger.Log($"Beginning to download file : {bundleInfo.BundleName} URL : {bundleInfo.RemoteMainURL}");
FileUtility.CreateFileDirectory(bundleInfo.LocalPath); FileUtility.CreateFileDirectory(bundleInfo.LocalPath);
var newDownloader = new FileDownloader(bundleInfo); var newDownloader = new FileDownloader(bundleInfo);
newDownloader.SendRequest(failedTryAgain, timeout); newDownloader.SendRequest(failedTryAgain, timeout);
@ -96,7 +95,7 @@ namespace YooAsset
{ {
string bundleName = _cachedHashList[hash]; string bundleName = _cachedHashList[hash];
_cachedHashList.Remove(hash); _cachedHashList.Remove(hash);
Logger.Error($"Cache file is missing : {bundleName} Hash : {hash}"); YooLogger.Error($"Cache file is missing : {bundleName} Hash : {hash}");
return false; return false;
} }
} }
@ -113,7 +112,7 @@ namespace YooAsset
{ {
if (_cachedHashList.ContainsKey(hash) == false) if (_cachedHashList.ContainsKey(hash) == false)
{ {
Logger.Log($"Cache verify file : {bundleName} Hash : {hash}"); YooLogger.Log($"Cache verify file : {bundleName} Hash : {hash}");
_cachedHashList.Add(hash, bundleName); _cachedHashList.Add(hash, bundleName);
} }
} }

View File

@ -159,7 +159,7 @@ namespace YooAsset
{ {
_failedTryAgain--; _failedTryAgain--;
_steps = ESteps.CreateDownload; _steps = ESteps.CreateDownload;
Logger.Warning($"Try again download : {_requestURL}"); YooLogger.Warning($"Try again download : {_requestURL}");
} }
} }
} }
@ -190,7 +190,7 @@ namespace YooAsset
float offset = Time.realtimeSinceStartup - _latestDownloadRealtime; float offset = Time.realtimeSinceStartup - _latestDownloadRealtime;
if (offset > _timeout) if (offset > _timeout)
{ {
Logger.Warning($"Web file request timeout : {_requestURL}"); YooLogger.Warning($"Web file request timeout : {_requestURL}");
_webRequest.Abort(); _webRequest.Abort();
_isAbort = true; _isAbort = true;
} }
@ -236,7 +236,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void ReportError() public void ReportError()
{ {
Logger.Error($"Failed to download : {_requestURL} Error : {_lastError}"); YooLogger.Error($"Failed to download : {_requestURL} Error : {_lastError}");
} }
} }
} }

View File

@ -158,7 +158,7 @@ namespace YooAsset
/// </summary> /// </summary>
public void ReportError() public void ReportError()
{ {
Logger.Error(_downloadError); YooLogger.Error(_downloadError);
} }

View File

@ -81,7 +81,7 @@ namespace YooAsset
} }
internal override void Start() internal override void Start()
{ {
Logger.Log($"Begine to download : {TotalDownloadCount} files and {TotalDownloadBytes} bytes"); YooLogger.Log($"Begine to download : {TotalDownloadCount} files and {TotalDownloadBytes} bytes");
_steps = ESteps.Loading; _steps = ESteps.Loading;
} }
internal override void Update() internal override void Update()
@ -174,7 +174,7 @@ namespace YooAsset
{ {
if (_steps == ESteps.None) if (_steps == ESteps.None)
{ {
OperationUpdater.ProcessOperaiton(this); OperationSystem.ProcessOperaiton(this);
} }
} }
} }

View File

@ -128,12 +128,12 @@ namespace YooAsset
PatchCache cache = PatchCache.LoadCache(); PatchCache cache = PatchCache.LoadCache();
if (cache.CacheAppVersion != Application.version) if (cache.CacheAppVersion != Application.version)
{ {
Logger.Warning($"Cache is dirty ! Cache app version is {cache.CacheAppVersion}, Current app version is {Application.version}"); YooLogger.Warning($"Cache is dirty ! Cache app version is {cache.CacheAppVersion}, Current app version is {Application.version}");
// 注意在覆盖安装的时候会保留APP沙盒目录可以选择清空缓存目录 // 注意在覆盖安装的时候会保留APP沙盒目录可以选择清空缓存目录
if (_impl.ClearCacheWhenDirty) if (_impl.ClearCacheWhenDirty)
{ {
Logger.Warning("Clear cache files."); YooLogger.Warning("Clear cache files.");
PatchHelper.DeleteSandboxCacheFolder(); PatchHelper.DeleteSandboxCacheFolder();
} }
@ -148,7 +148,7 @@ namespace YooAsset
if (_steps == ESteps.LoadAppManifest) if (_steps == ESteps.LoadAppManifest)
{ {
// 加载APP内的补丁清单 // 加载APP内的补丁清单
Logger.Log($"Load application patch manifest."); YooLogger.Log($"Load application patch manifest.");
string filePath = AssetPathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName); string filePath = AssetPathHelper.MakeStreamingLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
_downloadURL = AssetPathHelper.ConvertToWWWPath(filePath); _downloadURL = AssetPathHelper.ConvertToWWWPath(filePath);
_downloader = new UnityWebRequester(); _downloader = new UnityWebRequester();
@ -183,7 +183,7 @@ namespace YooAsset
// 加载沙盒内的补丁清单 // 加载沙盒内的补丁清单
if (PatchHelper.CheckSandboxPatchManifestFileExist()) if (PatchHelper.CheckSandboxPatchManifestFileExist())
{ {
Logger.Log($"Load sandbox patch manifest."); YooLogger.Log($"Load sandbox patch manifest.");
string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); string filePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
string jsonData = File.ReadAllText(filePath); string jsonData = File.ReadAllText(filePath);
_impl.LocalPatchManifest = PatchManifest.Deserialize(jsonData); _impl.LocalPatchManifest = PatchManifest.Deserialize(jsonData);

View File

@ -81,11 +81,11 @@ namespace YooAsset
if (_impl.IgnoreResourceVersion && _updateResourceVersion > 0) if (_impl.IgnoreResourceVersion && _updateResourceVersion > 0)
{ {
Logger.Warning($"Update resource version {_updateResourceVersion} is invalid when ignore resource version."); YooLogger.Warning($"Update resource version {_updateResourceVersion} is invalid when ignore resource version.");
} }
else else
{ {
Logger.Log($"Update patch manifest : update resource version is {_updateResourceVersion}"); YooLogger.Log($"Update patch manifest : update resource version is {_updateResourceVersion}");
} }
} }
internal override void Update() internal override void Update()
@ -96,7 +96,7 @@ namespace YooAsset
if (_steps == ESteps.LoadWebManifestHash) if (_steps == ESteps.LoadWebManifestHash)
{ {
string webURL = GetPatchManifestRequestURL(_updateResourceVersion, ResourceSettingData.Setting.PatchManifestHashFileName); string webURL = GetPatchManifestRequestURL(_updateResourceVersion, ResourceSettingData.Setting.PatchManifestHashFileName);
Logger.Log($"Beginning to request patch manifest hash : {webURL}"); YooLogger.Log($"Beginning to request patch manifest hash : {webURL}");
_downloaderHash = new UnityWebRequester(); _downloaderHash = new UnityWebRequester();
_downloaderHash.SendRequest(webURL, _timeout); _downloaderHash.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifestHash; _steps = ESteps.CheckWebManifestHash;
@ -125,12 +125,12 @@ namespace YooAsset
string currentFileHash = PatchHelper.GetSandboxPatchManifestFileHash(); string currentFileHash = PatchHelper.GetSandboxPatchManifestFileHash();
if (currentFileHash == webManifestHash) if (currentFileHash == webManifestHash)
{ {
Logger.Log($"Patch manifest file hash is not change : {webManifestHash}"); YooLogger.Log($"Patch manifest file hash is not change : {webManifestHash}");
_steps = ESteps.InitPrepareCache; _steps = ESteps.InitPrepareCache;
} }
else else
{ {
Logger.Log($"Patch manifest hash is change : {webManifestHash} -> {currentFileHash}"); YooLogger.Log($"Patch manifest hash is change : {webManifestHash} -> {currentFileHash}");
_steps = ESteps.LoadWebManifest; _steps = ESteps.LoadWebManifest;
} }
} }
@ -138,7 +138,7 @@ namespace YooAsset
if (_steps == ESteps.LoadWebManifest) if (_steps == ESteps.LoadWebManifest)
{ {
string webURL = GetPatchManifestRequestURL(_updateResourceVersion, ResourceSettingData.Setting.PatchManifestFileName); string webURL = GetPatchManifestRequestURL(_updateResourceVersion, ResourceSettingData.Setting.PatchManifestFileName);
Logger.Log($"Beginning to request patch manifest : {webURL}"); YooLogger.Log($"Beginning to request patch manifest : {webURL}");
_downloaderManifest = new UnityWebRequester(); _downloaderManifest = new UnityWebRequester();
_downloaderManifest.SendRequest(webURL, _timeout); _downloaderManifest.SendRequest(webURL, _timeout);
_steps = ESteps.CheckWebManifest; _steps = ESteps.CheckWebManifest;
@ -179,7 +179,7 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime; float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyTime;
Logger.Log($"Verify files total time : {costTime}"); YooLogger.Log($"Verify files total time : {costTime}");
} }
} }
} }
@ -205,7 +205,7 @@ namespace YooAsset
_impl.LocalPatchManifest = PatchManifest.Deserialize(content); _impl.LocalPatchManifest = PatchManifest.Deserialize(content);
// 注意:这里会覆盖掉沙盒内的补丁清单文件 // 注意:这里会覆盖掉沙盒内的补丁清单文件
Logger.Log("Save remote patch manifest file."); YooLogger.Log("Save remote patch manifest file.");
string savePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName); string savePath = AssetPathHelper.MakePersistentLoadPath(ResourceSettingData.Setting.PatchManifestFileName);
PatchManifest.Serialize(savePath, _impl.LocalPatchManifest); PatchManifest.Serialize(savePath, _impl.LocalPatchManifest);
} }
@ -276,7 +276,7 @@ namespace YooAsset
} }
else else
{ {
Logger.Warning("Failed to run verify thread."); YooLogger.Warning("Failed to run verify thread.");
break; break;
} }
} }

View File

@ -3,7 +3,7 @@
namespace YooAsset namespace YooAsset
{ {
[Serializable] [Serializable]
public class PatchAsset internal class PatchAsset
{ {
/// <summary> /// <summary>
/// 资源路径 /// 资源路径

View File

@ -1,11 +1,10 @@
using System; using System;
using System.Linq; using System.Linq;
using YooAsset.Utility;
namespace YooAsset namespace YooAsset
{ {
[Serializable] [Serializable]
public class PatchBundle internal class PatchBundle
{ {
/// <summary> /// <summary>
/// 资源包名称 /// 资源包名称

View File

@ -2,7 +2,6 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using YooAsset.Utility;
namespace YooAsset namespace YooAsset
{ {
@ -22,14 +21,14 @@ namespace YooAsset
{ {
if (PatchHelper.CheckSandboxCacheFileExist()) if (PatchHelper.CheckSandboxCacheFileExist())
{ {
Logger.Log("Load patch cache from disk."); YooLogger.Log("Load patch cache from disk.");
string filePath = PatchHelper.GetSandboxCacheFilePath(); string filePath = PatchHelper.GetSandboxCacheFilePath();
string jsonData = FileUtility.ReadFile(filePath); string jsonData = FileUtility.ReadFile(filePath);
return JsonUtility.FromJson<PatchCache>(jsonData); return JsonUtility.FromJson<PatchCache>(jsonData);
} }
else else
{ {
Logger.Log($"Create patch cache to disk : {Application.version}"); YooLogger.Log($"Create patch cache to disk : {Application.version}");
PatchCache cache = new PatchCache(); PatchCache cache = new PatchCache();
cache.CacheAppVersion = Application.version; cache.CacheAppVersion = Application.version;
string filePath = PatchHelper.GetSandboxCacheFilePath(); string filePath = PatchHelper.GetSandboxCacheFilePath();
@ -44,7 +43,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static void UpdateCache() public static void UpdateCache()
{ {
Logger.Log($"Update patch cache to disk : {Application.version}"); YooLogger.Log($"Update patch cache to disk : {Application.version}");
PatchCache cache = new PatchCache(); PatchCache cache = new PatchCache();
cache.CacheAppVersion = Application.version; cache.CacheAppVersion = Application.version;
string filePath = PatchHelper.GetSandboxCacheFilePath(); string filePath = PatchHelper.GetSandboxCacheFilePath();

View File

@ -1,6 +1,5 @@
using System.IO; using System.IO;
using System.Text; using System.Text;
using YooAsset.Utility;
namespace YooAsset namespace YooAsset
{ {

View File

@ -3,7 +3,6 @@ using System.IO;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using YooAsset.Utility;
namespace YooAsset namespace YooAsset
{ {
@ -11,7 +10,7 @@ namespace YooAsset
/// 补丁清单文件 /// 补丁清单文件
/// </summary> /// </summary>
[Serializable] [Serializable]
public class PatchManifest internal class PatchManifest
{ {
/// <summary> /// <summary>
/// 资源版本号 /// 资源版本号
@ -79,7 +78,7 @@ namespace YooAsset
} }
else else
{ {
Logger.Warning($"Not found asset path in patch manifest : {assetPath}"); YooLogger.Warning($"Not found asset path in patch manifest : {assetPath}");
return new string[] { }; return new string[] { };
} }
} }
@ -104,7 +103,7 @@ namespace YooAsset
} }
else else
{ {
Logger.Warning($"Not found asset path in patch manifest : {assetPath}"); YooLogger.Warning($"Not found asset path in patch manifest : {assetPath}");
return string.Empty; return string.Empty;
} }
} }
@ -150,7 +149,7 @@ namespace YooAsset
{ {
string assetPathWithoutExtension = StringUtility.RemoveExtension(assetPath); string assetPathWithoutExtension = StringUtility.RemoveExtension(assetPath);
if (patchManifest.Assets.ContainsKey(assetPathWithoutExtension)) if (patchManifest.Assets.ContainsKey(assetPathWithoutExtension))
Logger.Warning($"Asset path have existed : {assetPathWithoutExtension}"); YooLogger.Warning($"Asset path have existed : {assetPathWithoutExtension}");
else else
patchManifest.Assets.Add(assetPathWithoutExtension, patchAsset); patchManifest.Assets.Add(assetPathWithoutExtension, patchAsset);
} }

View File

@ -12,7 +12,7 @@ namespace YooAsset
public InitializationOperation InitializeAsync() public InitializationOperation InitializeAsync()
{ {
var operation = new EditorModeInitializationOperation(); var operation = new EditorModeInitializationOperation();
OperationUpdater.ProcessOperaiton(operation); OperationSystem.ProcessOperaiton(operation);
return operation; return operation;
} }
@ -27,7 +27,7 @@ namespace YooAsset
#region IBundleServices接口 #region IBundleServices接口
BundleInfo IBundleServices.GetBundleInfo(string bundleName) BundleInfo IBundleServices.GetBundleInfo(string bundleName)
{ {
Logger.Warning($"Editor play mode can not get bundle info."); YooLogger.Warning($"Editor play mode can not get bundle info.");
BundleInfo bundleInfo = new BundleInfo(bundleName, bundleName); BundleInfo bundleInfo = new BundleInfo(bundleName, bundleName);
return bundleInfo; return bundleInfo;
} }

View File

@ -28,7 +28,7 @@ namespace YooAsset
_fallbackHostServer = fallbackHostServer; _fallbackHostServer = fallbackHostServer;
var operation = new HostPlayModeInitializationOperation(this); var operation = new HostPlayModeInitializationOperation(this);
OperationUpdater.ProcessOperaiton(operation); OperationSystem.ProcessOperaiton(operation);
return operation; return operation;
} }
@ -38,7 +38,7 @@ namespace YooAsset
public UpdateManifestOperation UpdatePatchManifestAsync(int updateResourceVersion, int timeout) public UpdateManifestOperation UpdatePatchManifestAsync(int updateResourceVersion, int timeout)
{ {
var operation = new HostPlayModeUpdateManifestOperation(this, updateResourceVersion, timeout); var operation = new HostPlayModeUpdateManifestOperation(this, updateResourceVersion, timeout);
OperationUpdater.ProcessOperaiton(operation); OperationSystem.ProcessOperaiton(operation);
return operation; return operation;
} }
@ -284,7 +284,7 @@ namespace YooAsset
} }
else else
{ {
Logger.Warning($"Not found bundle in patch manifest : {bundleName}"); YooLogger.Warning($"Not found bundle in patch manifest : {bundleName}");
BundleInfo bundleInfo = new BundleInfo(bundleName, string.Empty); BundleInfo bundleInfo = new BundleInfo(bundleName, string.Empty);
return bundleInfo; return bundleInfo;
} }

View File

@ -14,7 +14,7 @@ namespace YooAsset
public InitializationOperation InitializeAsync() public InitializationOperation InitializeAsync()
{ {
var operation = new OfflinePlayModeInitializationOperation(this); var operation = new OfflinePlayModeInitializationOperation(this);
OperationUpdater.ProcessOperaiton(operation); OperationSystem.ProcessOperaiton(operation);
return operation; return operation;
} }
@ -42,7 +42,7 @@ namespace YooAsset
} }
else else
{ {
Logger.Warning($"Not found bundle in patch manifest : {bundleName}"); YooLogger.Warning($"Not found bundle in patch manifest : {bundleName}");
BundleInfo bundleInfo = new BundleInfo(bundleName, string.Empty); BundleInfo bundleInfo = new BundleInfo(bundleName, string.Empty);
return bundleInfo; return bundleInfo;
} }

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 778d989dab3088b499eb457a9b7cf854 guid: 13c0685c8f990994eb8bccb06df93ca3
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View File

@ -29,7 +29,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 加载状态 /// 加载状态
/// </summary> /// </summary>
public ELoaderStates States { set; get; } public int States { set; get; }
} }
/// <summary> /// <summary>
@ -50,7 +50,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 加载状态 /// 加载状态
/// </summary> /// </summary>
public EAssetStates States { set; get; } public int States { set; get; }
/// <summary> /// <summary>
/// 依赖的资源包列表 /// 依赖的资源包列表

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 2de5a58f37a4ae64e804f150144da809
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("YooAsset.Editor")]

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: dfc7a106fdf9d90428c38ec09d35a6f3 guid: a6847b71aba411740aaec06eea58a377
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -2,8 +2,8 @@
namespace YooAsset namespace YooAsset
{ {
[CreateAssetMenu(fileName = "YooAssetSetting", menuName = "YooAsset/Create Setting")] [CreateAssetMenu(fileName = "YooAssetSettings", menuName = "YooAsset/Create Settings")]
public class ResourceSetting : ScriptableObject public class YooAssetSettings : ScriptableObject
{ {
/// <summary> /// <summary>
/// AssetBundle文件的后缀名 /// AssetBundle文件的后缀名

View File

@ -4,8 +4,8 @@ namespace YooAsset
{ {
public static class ResourceSettingData public static class ResourceSettingData
{ {
private static ResourceSetting _setting = null; private static YooAssetSettings _setting = null;
public static ResourceSetting Setting public static YooAssetSettings Setting
{ {
get get
{ {
@ -20,15 +20,15 @@ namespace YooAsset
/// </summary> /// </summary>
private static void LoadSettingData() private static void LoadSettingData()
{ {
_setting = Resources.Load<ResourceSetting>("YooAssetSetting"); _setting = Resources.Load<YooAssetSettings>("YooAssetSettings");
if (_setting == null) if (_setting == null)
{ {
Debug.Log("Use YooAsset default resource setting."); YooLogger.Log("YooAsset use default settings.");
_setting = ScriptableObject.CreateInstance<ResourceSetting>(); _setting = ScriptableObject.CreateInstance<YooAssetSettings>();
} }
else else
{ {
Debug.Log("Use YooAsset custom resource setting."); YooLogger.Log("YooAsset use custom settings.");
} }
} }
} }

View File

@ -1,140 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
namespace YooAsset.Utility
{
public static class AssemblyUtility
{
public const string YooAssetAssemblyName = "YooAsset";
public const string YooAssetAssemblyEditorName = "YooAsset.Editor";
public const string UnityDefaultAssemblyName = "Assembly-CSharp";
public const string UnityDefaultAssemblyEditorName = "Assembly-CSharp-Editor";
private static readonly Dictionary<string, List<Type>> _cache = new Dictionary<string, List<Type>>();
static AssemblyUtility()
{
_cache.Clear();
}
/// <summary>
/// 获取程序集
/// </summary>
public static Assembly GetAssembly(string assemblyName)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (assembly.GetName().Name == assemblyName)
return assembly;
}
return null;
}
/// <summary>
/// 获取程序集里的所有类型
/// </summary>
private static List<Type> GetTypes(string assemblyName)
{
if (_cache.ContainsKey(assemblyName))
return _cache[assemblyName];
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (assembly.GetName().Name == assemblyName)
{
List<Type> types = assembly.GetTypes().ToList();
_cache.Add(assemblyName, types);
return types;
}
}
// 注意:如果没有找到程序集返回空列表
UnityEngine.Debug.LogWarning($"Not found assembly : {assemblyName}");
return new List<Type>();
}
/// <summary>
/// 获取带继承关系的所有类的类型
/// <param name="parentType">父类类型</param>
/// </summary>
public static List<Type> GetAssignableTypes(string assemblyName, System.Type parentType)
{
List<Type> result = new List<Type>();
List<Type> cacheTypes = GetTypes(assemblyName);
for (int i = 0; i < cacheTypes.Count; i++)
{
Type type = cacheTypes[i];
// 判断继承关系
if (parentType.IsAssignableFrom(type))
{
if (type.Name == parentType.Name)
continue;
result.Add(type);
}
}
return result;
}
/// <summary>
/// 获取带属性标签的所有类的类型
/// <param name="attributeType">属性类型</param>
/// </summary>
public static List<Type> GetAttributeTypes(string assemblyName, System.Type attributeType)
{
List<Type> result = new List<Type>();
List<Type> cacheTypes = GetTypes(assemblyName);
for (int i = 0; i < cacheTypes.Count; i++)
{
System.Type type = cacheTypes[i];
// 判断属性标签
if (Attribute.IsDefined(type, attributeType))
{
result.Add(type);
}
}
return result;
}
/// <summary>
/// 获取带继承关系和属性标签的所有类的类型
/// </summary>
/// <param name="parentType">父类类型</param>
/// <param name="attributeType">属性类型</param>
public static List<Type> GetAssignableAttributeTypes(string assemblyName, System.Type parentType, System.Type attributeType, bool checkError = true)
{
List<Type> result = new List<Type>();
List<Type> cacheTypes = GetTypes(assemblyName);
for (int i = 0; i < cacheTypes.Count; i++)
{
Type type = cacheTypes[i];
// 判断属性标签
if (Attribute.IsDefined(type, attributeType))
{
// 判断继承关系
if (parentType.IsAssignableFrom(type))
{
if (type.Name == parentType.Name)
continue;
result.Add(type);
}
else
{
if(checkError)
throw new Exception($"class {type} must inherit from {parentType}.");
}
}
}
return result;
}
}
}

View File

@ -1,8 +1,8 @@
using System; using System;
namespace YooAsset.Utility namespace YooAsset
{ {
public struct BitMask32 internal struct BitMask32
{ {
private int _mask; private int _mask;

View File

@ -1,8 +1,8 @@
using System; using System;
namespace YooAsset.Utility namespace YooAsset
{ {
public struct BitMask64 internal struct BitMask64
{ {
private long _mask; private long _mask;

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Security.Cryptography; using System.Security.Cryptography;
namespace YooAsset.Utility namespace YooAsset
{ {
internal class SafeProxy internal class SafeProxy
{ {

View File

@ -1,70 +0,0 @@
using System;
using System.Text;
using System.IO;
namespace YooAsset.Utility
{
public static class FileUtility
{
/// <summary>
/// 读取文件
/// </summary>
public static string ReadFile(string filePath)
{
if (File.Exists(filePath) == false)
return string.Empty;
return File.ReadAllText(filePath, Encoding.UTF8);
}
/// <summary>
/// 创建文件
/// </summary>
public static void CreateFile(string filePath, string content)
{
// 删除旧文件
if (File.Exists(filePath))
File.Delete(filePath);
// 创建文件夹路径
CreateFileDirectory(filePath);
// 创建新文件
byte[] bytes = Encoding.UTF8.GetBytes(content);
using (FileStream fs = File.Create(filePath))
{
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
}
}
/// <summary>
/// 创建文件的文件夹路径
/// </summary>
public static void CreateFileDirectory(string filePath)
{
// 获取文件的文件夹路径
string directory = Path.GetDirectoryName(filePath);
CreateDirectory(directory);
}
/// <summary>
/// 创建文件夹路径
/// </summary>
public static void CreateDirectory(string directory)
{
// If the directory doesn't exist, create it.
if (Directory.Exists(directory) == false)
Directory.CreateDirectory(directory);
}
/// <summary>
/// 获取文件大小(字节数)
/// </summary>
public static long GetFileSize(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
return fileInfo.Length;
}
}
}

View File

@ -1,169 +0,0 @@
using System;
using System.Text;
using System.IO;
using System.Security.Cryptography;
namespace YooAsset.Utility
{
public static class HashUtility
{
private static string ToString(byte[] hashBytes)
{
string result = BitConverter.ToString(hashBytes);
result = result.Replace("-", "");
return result.ToLower();
}
#region SHA1
/// <summary>
/// 获取字符串的Hash值
/// </summary>
public static string StringSHA1(string str)
{
byte[] buffer = Encoding.UTF8.GetBytes(str);
return BytesSHA1(buffer);
}
/// <summary>
/// 获取文件的Hash值
/// </summary>
public static string FileSHA1(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamSHA1(fs);
}
}
catch (Exception e)
{
Logger.Exception(e);
return string.Empty;
}
}
/// <summary>
/// 获取数据流的Hash值
/// </summary>
public static string StreamSHA1(Stream stream)
{
// 说明创建的是SHA1类的实例生成的是160位的散列码
HashAlgorithm hash = HashAlgorithm.Create();
byte[] hashBytes = hash.ComputeHash(stream);
return ToString(hashBytes);
}
/// <summary>
/// 获取字节数组的Hash值
/// </summary>
public static string BytesSHA1(byte[] buffer)
{
// 说明创建的是SHA1类的实例生成的是160位的散列码
HashAlgorithm hash = HashAlgorithm.Create();
byte[] hashBytes = hash.ComputeHash(buffer);
return ToString(hashBytes);
}
#endregion
#region MD5
/// <summary>
/// 获取字符串的MD5
/// </summary>
public static string StringMD5(string str)
{
byte[] buffer = Encoding.UTF8.GetBytes(str);
return BytesMD5(buffer);
}
/// <summary>
/// 获取文件的MD5
/// </summary>
public static string FileMD5(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamMD5(fs);
}
}
catch (Exception e)
{
Logger.Exception(e);
return string.Empty;
}
}
/// <summary>
/// 获取数据流的MD5
/// </summary>
public static string StreamMD5(Stream stream)
{
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] hashBytes = provider.ComputeHash(stream);
return ToString(hashBytes);
}
/// <summary>
/// 获取字节数组的MD5
/// </summary>
public static string BytesMD5(byte[] buffer)
{
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] hashBytes = provider.ComputeHash(buffer);
return ToString(hashBytes);
}
#endregion
#region CRC32
/// <summary>
/// 获取字符串的CRC32
/// </summary>
public static string StringCRC32(string str)
{
byte[] buffer = Encoding.UTF8.GetBytes(str);
return BytesCRC32(buffer);
}
/// <summary>
/// 获取文件的CRC32
/// </summary>
public static string FileCRC32(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamCRC32(fs);
}
}
catch (Exception e)
{
Logger.Exception(e);
return string.Empty;
}
}
/// <summary>
/// 获取数据流的CRC32
/// </summary>
public static string StreamCRC32(Stream stream)
{
CRC32Algorithm hash = new CRC32Algorithm();
byte[] hashBytes = hash.ComputeHash(stream);
return ToString(hashBytes);
}
/// <summary>
/// 获取字节数组的CRC32
/// </summary>
public static string BytesCRC32(byte[] buffer)
{
CRC32Algorithm hash = new CRC32Algorithm();
byte[] hashBytes = hash.ComputeHash(buffer);
return ToString(hashBytes);
}
#endregion
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 43b9656e0b5241e49afcd9d671f5deac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,107 +0,0 @@
using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
namespace YooAsset.Utility
{
public static class StringUtility
{
[ThreadStatic]
private static StringBuilder _cacheBuilder = new StringBuilder(1024);
public static string Format(string format, object arg0)
{
if (string.IsNullOrEmpty(format))
throw new ArgumentNullException();
_cacheBuilder.Length = 0;
_cacheBuilder.AppendFormat(format, arg0);
return _cacheBuilder.ToString();
}
public static string Format(string format, object arg0, object arg1)
{
if (string.IsNullOrEmpty(format))
throw new ArgumentNullException();
_cacheBuilder.Length = 0;
_cacheBuilder.AppendFormat(format, arg0, arg1);
return _cacheBuilder.ToString();
}
public static string Format(string format, object arg0, object arg1, object arg2)
{
if (string.IsNullOrEmpty(format))
throw new ArgumentNullException();
_cacheBuilder.Length = 0;
_cacheBuilder.AppendFormat(format, arg0, arg1, arg2);
return _cacheBuilder.ToString();
}
public static string Format(string format, params object[] args)
{
if (string.IsNullOrEmpty(format))
throw new ArgumentNullException();
if (args == null)
throw new ArgumentNullException();
_cacheBuilder.Length = 0;
_cacheBuilder.AppendFormat(format, args);
return _cacheBuilder.ToString();
}
public static List<string> StringToStringList(string str, char separator)
{
List<string> result = new List<string>();
if (!String.IsNullOrEmpty(str))
{
string[] splits = str.Split(separator);
foreach (string split in splits)
{
if (!String.IsNullOrEmpty(split))
{
result.Add(split);
}
}
}
return result;
}
public static bool StringToBool(string str)
{
int value = (int)Convert.ChangeType(str, typeof(int));
return value > 0;
}
public static T NameToEnum<T>(string name)
{
if (Enum.IsDefined(typeof(T), name) == false)
{
throw new ArgumentException($"Enum {typeof(T)} is not defined name {name}");
}
return (T)Enum.Parse(typeof(T), name);
}
public static string RemoveFirstChar(string str)
{
if (string.IsNullOrEmpty(str))
return str;
return str.Substring(1);
}
public static string RemoveLastChar(string str)
{
if (string.IsNullOrEmpty(str))
return str;
return str.Substring(0, str.Length - 1);
}
public static string RemoveExtension(string str)
{
if (string.IsNullOrEmpty(str))
return str;
int index = str.LastIndexOf(".");
if (index == -1)
return str;
else
return str.Remove(index); //"assets/config/test.unity3d" --> "assets/config/test"
}
}
}

View File

@ -2,7 +2,7 @@
namespace YooAsset namespace YooAsset
{ {
internal static class Logger internal static class YooLogger
{ {
/// <summary> /// <summary>
/// 日志 /// 日志

View File

@ -0,0 +1,481 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Diagnostics;
using System.Reflection;
namespace YooAsset
{
/// <summary>
/// 程序集工具类
/// </summary>
internal static class AssemblyUtility
{
public const string YooAssetAssemblyName = "YooAsset";
public const string YooAssetAssemblyEditorName = "YooAsset.Editor";
public const string UnityDefaultAssemblyName = "Assembly-CSharp";
public const string UnityDefaultAssemblyEditorName = "Assembly-CSharp-Editor";
private static readonly Dictionary<string, List<Type>> _cache = new Dictionary<string, List<Type>>();
static AssemblyUtility()
{
_cache.Clear();
}
/// <summary>
/// 获取程序集
/// </summary>
public static Assembly GetAssembly(string assemblyName)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (assembly.GetName().Name == assemblyName)
return assembly;
}
return null;
}
/// <summary>
/// 获取程序集里的所有类型
/// </summary>
private static List<Type> GetTypes(string assemblyName)
{
if (_cache.ContainsKey(assemblyName))
return _cache[assemblyName];
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
if (assembly.GetName().Name == assemblyName)
{
List<Type> types = assembly.GetTypes().ToList();
_cache.Add(assemblyName, types);
return types;
}
}
// 注意:如果没有找到程序集返回空列表
UnityEngine.Debug.LogWarning($"Not found assembly : {assemblyName}");
return new List<Type>();
}
/// <summary>
/// 获取带继承关系的所有类的类型
/// <param name="parentType">父类类型</param>
/// </summary>
public static List<Type> GetAssignableTypes(string assemblyName, System.Type parentType)
{
List<Type> result = new List<Type>();
List<Type> cacheTypes = GetTypes(assemblyName);
for (int i = 0; i < cacheTypes.Count; i++)
{
Type type = cacheTypes[i];
// 判断继承关系
if (parentType.IsAssignableFrom(type))
{
if (type.Name == parentType.Name)
continue;
result.Add(type);
}
}
return result;
}
/// <summary>
/// 获取带属性标签的所有类的类型
/// <param name="attributeType">属性类型</param>
/// </summary>
public static List<Type> GetAttributeTypes(string assemblyName, System.Type attributeType)
{
List<Type> result = new List<Type>();
List<Type> cacheTypes = GetTypes(assemblyName);
for (int i = 0; i < cacheTypes.Count; i++)
{
System.Type type = cacheTypes[i];
// 判断属性标签
if (Attribute.IsDefined(type, attributeType))
{
result.Add(type);
}
}
return result;
}
/// <summary>
/// 获取带继承关系和属性标签的所有类的类型
/// </summary>
/// <param name="parentType">父类类型</param>
/// <param name="attributeType">属性类型</param>
public static List<Type> GetAssignableAttributeTypes(string assemblyName, System.Type parentType, System.Type attributeType, bool checkError = true)
{
List<Type> result = new List<Type>();
List<Type> cacheTypes = GetTypes(assemblyName);
for (int i = 0; i < cacheTypes.Count; i++)
{
Type type = cacheTypes[i];
// 判断属性标签
if (Attribute.IsDefined(type, attributeType))
{
// 判断继承关系
if (parentType.IsAssignableFrom(type))
{
if (type.Name == parentType.Name)
continue;
result.Add(type);
}
else
{
if(checkError)
throw new Exception($"class {type} must inherit from {parentType}.");
}
}
}
return result;
}
}
/// <summary>
/// 字符串工具类
/// </summary>
internal static class StringUtility
{
[ThreadStatic]
private static StringBuilder _cacheBuilder = new StringBuilder(1024);
public static string Format(string format, object arg0)
{
if (string.IsNullOrEmpty(format))
throw new ArgumentNullException();
_cacheBuilder.Length = 0;
_cacheBuilder.AppendFormat(format, arg0);
return _cacheBuilder.ToString();
}
public static string Format(string format, object arg0, object arg1)
{
if (string.IsNullOrEmpty(format))
throw new ArgumentNullException();
_cacheBuilder.Length = 0;
_cacheBuilder.AppendFormat(format, arg0, arg1);
return _cacheBuilder.ToString();
}
public static string Format(string format, object arg0, object arg1, object arg2)
{
if (string.IsNullOrEmpty(format))
throw new ArgumentNullException();
_cacheBuilder.Length = 0;
_cacheBuilder.AppendFormat(format, arg0, arg1, arg2);
return _cacheBuilder.ToString();
}
public static string Format(string format, params object[] args)
{
if (string.IsNullOrEmpty(format))
throw new ArgumentNullException();
if (args == null)
throw new ArgumentNullException();
_cacheBuilder.Length = 0;
_cacheBuilder.AppendFormat(format, args);
return _cacheBuilder.ToString();
}
public static List<string> StringToStringList(string str, char separator)
{
List<string> result = new List<string>();
if (!String.IsNullOrEmpty(str))
{
string[] splits = str.Split(separator);
foreach (string split in splits)
{
if (!String.IsNullOrEmpty(split))
{
result.Add(split);
}
}
}
return result;
}
public static bool StringToBool(string str)
{
int value = (int)Convert.ChangeType(str, typeof(int));
return value > 0;
}
public static T NameToEnum<T>(string name)
{
if (Enum.IsDefined(typeof(T), name) == false)
{
throw new ArgumentException($"Enum {typeof(T)} is not defined name {name}");
}
return (T)Enum.Parse(typeof(T), name);
}
public static string RemoveFirstChar(string str)
{
if (string.IsNullOrEmpty(str))
return str;
return str.Substring(1);
}
public static string RemoveLastChar(string str)
{
if (string.IsNullOrEmpty(str))
return str;
return str.Substring(0, str.Length - 1);
}
public static string RemoveExtension(string str)
{
if (string.IsNullOrEmpty(str))
return str;
int index = str.LastIndexOf(".");
if (index == -1)
return str;
else
return str.Remove(index); //"assets/config/test.unity3d" --> "assets/config/test"
}
}
/// <summary>
/// 文件工具类
/// </summary>
internal static class FileUtility
{
/// <summary>
/// 读取文件
/// </summary>
public static string ReadFile(string filePath)
{
if (File.Exists(filePath) == false)
return string.Empty;
return File.ReadAllText(filePath, Encoding.UTF8);
}
/// <summary>
/// 创建文件
/// </summary>
public static void CreateFile(string filePath, string content)
{
// 删除旧文件
if (File.Exists(filePath))
File.Delete(filePath);
// 创建文件夹路径
CreateFileDirectory(filePath);
// 创建新文件
byte[] bytes = Encoding.UTF8.GetBytes(content);
using (FileStream fs = File.Create(filePath))
{
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
}
}
/// <summary>
/// 创建文件的文件夹路径
/// </summary>
public static void CreateFileDirectory(string filePath)
{
// 获取文件的文件夹路径
string directory = Path.GetDirectoryName(filePath);
CreateDirectory(directory);
}
/// <summary>
/// 创建文件夹路径
/// </summary>
public static void CreateDirectory(string directory)
{
// If the directory doesn't exist, create it.
if (Directory.Exists(directory) == false)
Directory.CreateDirectory(directory);
}
/// <summary>
/// 获取文件大小(字节数)
/// </summary>
public static long GetFileSize(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
return fileInfo.Length;
}
}
/// <summary>
/// 哈希工具类
/// </summary>
internal static class HashUtility
{
private static string ToString(byte[] hashBytes)
{
string result = BitConverter.ToString(hashBytes);
result = result.Replace("-", "");
return result.ToLower();
}
#region SHA1
/// <summary>
/// 获取字符串的Hash值
/// </summary>
public static string StringSHA1(string str)
{
byte[] buffer = Encoding.UTF8.GetBytes(str);
return BytesSHA1(buffer);
}
/// <summary>
/// 获取文件的Hash值
/// </summary>
public static string FileSHA1(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamSHA1(fs);
}
}
catch (Exception e)
{
YooLogger.Exception(e);
return string.Empty;
}
}
/// <summary>
/// 获取数据流的Hash值
/// </summary>
public static string StreamSHA1(Stream stream)
{
// 说明创建的是SHA1类的实例生成的是160位的散列码
HashAlgorithm hash = HashAlgorithm.Create();
byte[] hashBytes = hash.ComputeHash(stream);
return ToString(hashBytes);
}
/// <summary>
/// 获取字节数组的Hash值
/// </summary>
public static string BytesSHA1(byte[] buffer)
{
// 说明创建的是SHA1类的实例生成的是160位的散列码
HashAlgorithm hash = HashAlgorithm.Create();
byte[] hashBytes = hash.ComputeHash(buffer);
return ToString(hashBytes);
}
#endregion
#region MD5
/// <summary>
/// 获取字符串的MD5
/// </summary>
public static string StringMD5(string str)
{
byte[] buffer = Encoding.UTF8.GetBytes(str);
return BytesMD5(buffer);
}
/// <summary>
/// 获取文件的MD5
/// </summary>
public static string FileMD5(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamMD5(fs);
}
}
catch (Exception e)
{
YooLogger.Exception(e);
return string.Empty;
}
}
/// <summary>
/// 获取数据流的MD5
/// </summary>
public static string StreamMD5(Stream stream)
{
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] hashBytes = provider.ComputeHash(stream);
return ToString(hashBytes);
}
/// <summary>
/// 获取字节数组的MD5
/// </summary>
public static string BytesMD5(byte[] buffer)
{
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] hashBytes = provider.ComputeHash(buffer);
return ToString(hashBytes);
}
#endregion
#region CRC32
/// <summary>
/// 获取字符串的CRC32
/// </summary>
public static string StringCRC32(string str)
{
byte[] buffer = Encoding.UTF8.GetBytes(str);
return BytesCRC32(buffer);
}
/// <summary>
/// 获取文件的CRC32
/// </summary>
public static string FileCRC32(string filePath)
{
try
{
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
return StreamCRC32(fs);
}
}
catch (Exception e)
{
YooLogger.Exception(e);
return string.Empty;
}
}
/// <summary>
/// 获取数据流的CRC32
/// </summary>
public static string StreamCRC32(Stream stream)
{
CRC32Algorithm hash = new CRC32Algorithm();
byte[] hashBytes = hash.ComputeHash(stream);
return ToString(hashBytes);
}
/// <summary>
/// 获取字节数组的CRC32
/// </summary>
public static string BytesCRC32(byte[] buffer)
{
CRC32Algorithm hash = new CRC32Algorithm();
byte[] hashBytes = hash.ComputeHash(buffer);
return ToString(hashBytes);
}
#endregion
}
}

View File

@ -1,10 +1,9 @@
{ {
"name": "YooAsset", "name": "YooAsset",
"rootNamespace": "",
"references": [], "references": [],
"includePlatforms": [], "includePlatforms": [],
"excludePlatforms": [], "excludePlatforms": [],
"allowUnsafeCode": true, "allowUnsafeCode": false,
"overrideReferences": false, "overrideReferences": false,
"precompiledReferences": [], "precompiledReferences": [],
"autoReferenced": true, "autoReferenced": true,

View File

@ -135,7 +135,7 @@ namespace YooAsset
if (parameters.AssetLoadingMaxNumber < 3) if (parameters.AssetLoadingMaxNumber < 3)
{ {
parameters.AssetLoadingMaxNumber = 3; parameters.AssetLoadingMaxNumber = 3;
Logger.Warning($"{nameof(parameters.AssetLoadingMaxNumber)} minimum is 3"); YooLogger.Warning($"{nameof(parameters.AssetLoadingMaxNumber)} minimum is 3");
} }
// 创建间隔计时器 // 创建间隔计时器
@ -200,13 +200,13 @@ namespace YooAsset
if (_playMode == EPlayMode.EditorPlayMode) if (_playMode == EPlayMode.EditorPlayMode)
{ {
var operation = new EditorModeUpdateManifestOperation(); var operation = new EditorModeUpdateManifestOperation();
OperationUpdater.ProcessOperaiton(operation); OperationSystem.ProcessOperaiton(operation);
return operation; return operation;
} }
else if (_playMode == EPlayMode.OfflinePlayMode) else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
var operation = new OfflinePlayModeUpdateManifestOperation(); var operation = new OfflinePlayModeUpdateManifestOperation();
OperationUpdater.ProcessOperaiton(operation); OperationSystem.ProcessOperaiton(operation);
return operation; return operation;
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
@ -284,7 +284,7 @@ namespace YooAsset
public static void GetDebugSummy(DebugSummy summy) public static void GetDebugSummy(DebugSummy summy)
{ {
if (summy == null) if (summy == null)
Logger.Error($"{nameof(DebugSummy)} is null"); YooLogger.Error($"{nameof(DebugSummy)} is null");
AssetSystem.GetDebugSummy(summy); AssetSystem.GetDebugSummy(summy);
} }
@ -507,7 +507,7 @@ namespace YooAsset
/// </summary> /// </summary>
public static void ClearSandbox() public static void ClearSandbox()
{ {
Logger.Warning("Clear sandbox."); YooLogger.Warning("Clear sandbox.");
PatchHelper.ClearSandbox(); PatchHelper.ClearSandbox();
} }
@ -527,7 +527,7 @@ namespace YooAsset
internal static void InternalUpdate() internal static void InternalUpdate()
{ {
// 更新异步请求操作 // 更新异步请求操作
OperationUpdater.Update(); OperationSystem.Update();
// 更新下载管理系统 // 更新下载管理系统
DownloadSystem.Update(); DownloadSystem.Update();