From d063eb3d36b91755adb68b2ed4e8921d36b07dc6 Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 3 Mar 2022 18:07:58 +0800 Subject: [PATCH] Update YooAssets --- Assets/YooAsset/Runtime/YooAssetDriver.cs | 12 +++++ .../YooAsset/Runtime/YooAssetDriver.cs.meta | 11 ++++ Assets/YooAsset/Runtime/YooAssets.cs | 54 ++++++++++++------- 3 files changed, 57 insertions(+), 20 deletions(-) create mode 100644 Assets/YooAsset/Runtime/YooAssetDriver.cs create mode 100644 Assets/YooAsset/Runtime/YooAssetDriver.cs.meta diff --git a/Assets/YooAsset/Runtime/YooAssetDriver.cs b/Assets/YooAsset/Runtime/YooAssetDriver.cs new file mode 100644 index 0000000..492458d --- /dev/null +++ b/Assets/YooAsset/Runtime/YooAssetDriver.cs @@ -0,0 +1,12 @@ +using UnityEngine; + +namespace YooAsset +{ + internal class YooAssetDriver : MonoBehaviour + { + void Update() + { + YooAssets.InternalUpdate(); + } + } +} \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/YooAssetDriver.cs.meta b/Assets/YooAsset/Runtime/YooAssetDriver.cs.meta new file mode 100644 index 0000000..fbc6727 --- /dev/null +++ b/Assets/YooAsset/Runtime/YooAssetDriver.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6849dc1f64284274490437c22a811a1d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs index e04d8dd..a66c834 100644 --- a/Assets/YooAsset/Runtime/YooAssets.cs +++ b/Assets/YooAsset/Runtime/YooAssets.cs @@ -93,6 +93,7 @@ namespace YooAsset } + private static bool _isInitialize = false; private static string _locationRoot; private static EPlayMode _playMode; private static IBundleServices _bundleServices; @@ -117,6 +118,19 @@ namespace YooAsset throw new Exception($"Editor play mode only support unity editor."); #endif + // 创建驱动器 + if (_isInitialize == false) + { + _isInitialize = true; + UnityEngine.GameObject driver = new UnityEngine.GameObject("[YooAsset]"); + var driverGo = driver.AddComponent().gameObject; + UnityEngine.Object.DontDestroyOnLoad(driverGo); + } + else + { + throw new Exception("YooAsset is initialized yet."); + } + // 检测创建参数 if (parameters.AssetLoadingMaxNumber < 3) { @@ -212,16 +226,16 @@ namespace YooAsset /// /// 更新资源系统 /// - public static void Update() + internal static void InternalUpdate() { // 更新异步请求操作 OperationUpdater.Update(); // 更新下载管理系统 DownloadSystem.Update(); - + // 轮询更新资源系统 - AssetSystem.UpdatePoll(); + AssetSystem.Update(); // 自动释放零引用资源 if (_releaseCD > 0) @@ -417,39 +431,39 @@ namespace YooAsset /// /// 创建补丁下载器 /// - /// DLC标记 + /// 资源标签 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static PatchDownloader CreateDLCDownloader(string dlcTag, int downloadingMaxNumber, int failedTryAgain) + public static DownloaderOperation CreatePatchDownloader(string tag, int downloadingMaxNumber, int failedTryAgain) { - return CreateDLCDownloader(new string[] { dlcTag }, downloadingMaxNumber, failedTryAgain); + return CreatePatchDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain); } /// /// 创建补丁下载器 /// - /// DLC标记列表 + /// 资源标签列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static PatchDownloader CreateDLCDownloader(string[] dlcTags, int downloadingMaxNumber, int failedTryAgain) + public static DownloaderOperation CreatePatchDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain) { if (_playMode == EPlayMode.EditorPlayMode) { List downloadList = new List(); - PatchDownloader downlader = new PatchDownloader(null, downloadList, downloadingMaxNumber, failedTryAgain); - return downlader; + var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + return operation; } else if (_playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - PatchDownloader downlader = new PatchDownloader(null, downloadList, downloadingMaxNumber, failedTryAgain); - return downlader; + var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + return operation; } else if (_playMode == EPlayMode.HostPlayMode) { if (_hostPlayModeImpl == null) throw new Exception("YooAsset is not initialized."); - return _hostPlayModeImpl.CreateDLCDownloader(dlcTags, downloadingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreateDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain); } else { @@ -458,24 +472,24 @@ namespace YooAsset } /// - /// 创建补丁下载器 + /// 创建资源包下载器 /// /// 资源列表 /// 同时下载的最大文件数 /// 下载失败的重试次数 - public static PatchDownloader CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain) + public static DownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain) { if (_playMode == EPlayMode.EditorPlayMode) { List downloadList = new List(); - PatchDownloader downlader = new PatchDownloader(null, downloadList, downloadingMaxNumber, failedTryAgain); - return downlader; + var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + return operation; } else if (_playMode == EPlayMode.OfflinePlayMode) { List downloadList = new List(); - PatchDownloader downlader = new PatchDownloader(null, downloadList, downloadingMaxNumber, failedTryAgain); - return downlader; + var operation = new DownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain); + return operation; } else if (_playMode == EPlayMode.HostPlayMode) { @@ -488,7 +502,7 @@ namespace YooAsset string assetPath = ConvertLocationToAssetPath(location); assetPaths.Add(assetPath); } - return _hostPlayModeImpl.CreateBundleDownloader(assetPaths, downloadingMaxNumber, failedTryAgain); + return _hostPlayModeImpl.CreateDownloaderByPaths(assetPaths, downloadingMaxNumber, failedTryAgain); } else {