diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/Base/AssetObject.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/Base/AssetObject.cs index 38d840d4..8530a479 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/Base/AssetObject.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/Base/AssetObject.cs @@ -150,6 +150,12 @@ public Scene GetScene() return this.GetOperationHandle().SceneObject; } + public bool UnsuspendScene() + { + if (this.IsSceneOperationHandleValid()) return this.GetOperationHandle().UnSuspend(); + return false; + } + public void UnloadScene() { if (this.IsSceneOperationHandleValid()) this.GetOperationHandle().UnloadAsync(); diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheBundle.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheBundle.cs index 4ebebd92..fa3ec8d8 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheBundle.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheBundle.cs @@ -108,12 +108,9 @@ public async UniTask PreloadRawFileAsync(string packageName, string[] assetNames float lastCount = 0; do { - if (progression != null) - { - this.currentCount += (req.Progress - lastCount); - lastCount = req.Progress; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount += (req.Progress - lastCount); + lastCount = req.Progress; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); if (req.IsDone) { @@ -218,11 +215,8 @@ public void PreloadRawFile(string packageName, string[] assetNames, Progression { if (req.IsDone) { - if (progression != null) - { - this.currentCount++; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount++; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); loaded = true; pack.SetPack(packageName, assetName, req); @@ -298,12 +292,9 @@ public async UniTask LoadRawFileAsync(string packageName, string assetName float lastCount = 0; do { - if (progression != null) - { - this.currentCount += (req.Progress - lastCount); - lastCount = req.Progress; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount += (req.Progress - lastCount); + lastCount = req.Progress; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); if (req.IsDone) { @@ -402,11 +393,8 @@ public T LoadRawFile(string packageName, string assetName, Progression progre { if (req.IsDone) { - if (progression != null) - { - this.currentCount++; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount++; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); loaded = true; pack.SetPack(packageName, assetName, req); @@ -570,25 +558,30 @@ public async UniTask LoadSceneAsync(string packageName, string asset bool loaded = false; var pack = new BundlePack(); + // 是否 Suspend + bool suspendLoad = !activateOnLoad; + bool suspendLoaded = false; + // 場景需特殊處理 var package = PackageManager.GetPackage(packageName); if (package != null && package.CheckLocationValid(assetName)) { - var req = package.LoadSceneAsync(assetName, loadSceneMode, !activateOnLoad, priority); + var req = package.LoadSceneAsync(assetName, loadSceneMode, suspendLoad, priority); if (req != null) { float lastCount = 0; do { - if (progression != null) - { - this.currentCount += (req.Progress - lastCount); - lastCount = req.Progress; - if (this.currentCount >= 0.9f) this.currentCount = 1f; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount += (req.Progress - lastCount); + lastCount = req.Progress; + if (this.currentCount >= 0.9f) this.currentCount = 1f; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - if (req.IsDone) + // 處理 Suspend load + suspendLoaded = suspendLoad && this.currentCount >= 1f; + + if (req.IsDone || + suspendLoaded) { loaded = true; switch (loadSceneMode) @@ -636,13 +629,16 @@ public async UniTask LoadSceneAsync(string packageName, string asset Logging.Print($"Package: {packageName} doesn't exist or location invalid."); } - if (!loaded || !pack.GetScene().isLoaded) + if (!suspendLoaded) { - this.UnloadScene(assetName, true); - if (this.GetRetryCounter(assetName).IsRetryActive()) Logging.Print($"【Load Scene】 => << CacheBundle >> Asset: {assetName} doing retry. Retry count: {this.GetRetryCounter(assetName).retryCount}, Max retry count: {maxRetryCount}"); - else Logging.Print($"【Load Scene】 => << CacheBundle >> Asset: {assetName} start doing retry. Max retry count: {maxRetryCount}"); - this.GetRetryCounter(assetName).AddRetryCount(); - return await this.LoadSceneAsync(packageName, assetName, loadSceneMode, activateOnLoad, priority, progression); + if (!loaded || !pack.GetScene().isLoaded) + { + this.UnloadScene(assetName, true); + if (this.GetRetryCounter(assetName).IsRetryActive()) Logging.Print($"【Load Scene】 => << CacheBundle >> Asset: {assetName} doing retry. Retry count: {this.GetRetryCounter(assetName).retryCount}, Max retry count: {maxRetryCount}"); + else Logging.Print($"【Load Scene】 => << CacheBundle >> Asset: {assetName} start doing retry. Max retry count: {maxRetryCount}"); + this.GetRetryCounter(assetName).AddRetryCount(); + return await this.LoadSceneAsync(packageName, assetName, loadSceneMode, activateOnLoad, priority, progression); + } } this.RemoveLoadingFlags(assetName); @@ -830,12 +826,9 @@ public async UniTask PreloadAssetAsync(string packageName, string[] assetName float lastCount = 0; do { - if (progression != null) - { - this.currentCount += (req.Progress - lastCount); - lastCount = req.Progress; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount += (req.Progress - lastCount); + lastCount = req.Progress; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); if (req.IsDone) { @@ -940,11 +933,8 @@ public void PreloadAsset(string packageName, string[] assetNames, Progression { if (req.IsDone) { - if (progression != null) - { - this.currentCount++; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount++; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); loaded = true; pack.SetPack(packageName, assetName, req); @@ -1020,12 +1010,9 @@ public async UniTask LoadAssetAsync(string packageName, string assetName, float lastCount = 0; do { - if (progression != null) - { - this.currentCount += (req.Progress - lastCount); - lastCount = req.Progress; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount += (req.Progress - lastCount); + lastCount = req.Progress; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); if (req.IsDone) { @@ -1114,11 +1101,8 @@ public T LoadAsset(string packageName, string assetName, Progression progress { if (req.IsDone) { - if (progression != null) - { - this.currentCount++; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount++; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); loaded = true; pack.SetPack(packageName, assetName, req); diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheResource.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheResource.cs index 3c0f5c71..e5f1820f 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheResource.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheResource.cs @@ -78,12 +78,9 @@ public async UniTask PreloadAssetAsync(string[] assetNames, Progression progr float lastCount = 0; do { - if (progression != null) - { - this.currentCount += (req.progress - lastCount); - lastCount = req.progress; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount += (req.progress - lastCount); + lastCount = req.progress; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); if (req.isDone) { @@ -230,12 +227,9 @@ public async UniTask LoadAssetAsync(string assetName, Progression progress float lastCount = 0; do { - if (progression != null) - { - this.currentCount += (req.progress - lastCount); - lastCount = req.progress; - progression.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); - } + this.currentCount += (req.progress - lastCount); + lastCount = req.progress; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); if (req.isDone) { diff --git a/Assets/OxGFrame/CHANGELOG.md b/Assets/OxGFrame/CHANGELOG.md index 1cc41171..3492d5b8 100644 --- a/Assets/OxGFrame/CHANGELOG.md +++ b/Assets/OxGFrame/CHANGELOG.md @@ -1,8 +1,27 @@ # CHANGELOG +## [2.10.2] - 2024-03-19 +- Fixed When scene load with suspend (activateOnLoad = false) cannot return BundlePack correctly . +```C# + // activateOnLoad = false (suspend) + var bundlePack = await CoreFrames.USFrame.LoadAdditiveSceneAsync("MyPackage", "SceneName", false, 100); +``` +- Added UnsuspendScene in BundlePack. +```C# + // Method 1 + var bundlePack = await CoreFrames.USFrame.LoadAdditiveSceneAsync("MyPackage", "SceneName", false, 100); + bundlePack.GetOperationHandle().UnSuspend(); + + // Method 2 + var bundlePack = await CoreFrames.USFrame.LoadAdditiveSceneAsync("MyPackage", "SceneName", false, 100); + bundlePack.UnsuspendScene(); +``` +- Modified set #ROOTNAMESPACE# symbol in script templates. +- Optimized remove useless interfaces. + ## [2.10.1] - 2024-03-14 - Fixed AudioBase and VideoBase to avoid executing Stop again in OnDestroy if they are being destroyed. -- Added MediaLRUCache to handle audios or videos that have not been Unloaded for a long time (Optimize memory). +- Added MediaLRUCache to handle least recently used audio or vidoe will be removed (Optimize memory). - Added binding access modifier rules in BindCodeSetting, split by "$". - _Node@MyObj*Txt$public (UIBase, SRBase). - ~Node@MyObj*Txt$public (CPBase). diff --git a/Assets/OxGFrame/package.json b/Assets/OxGFrame/package.json index df69ddcf..cea8862f 100644 --- a/Assets/OxGFrame/package.json +++ b/Assets/OxGFrame/package.json @@ -2,7 +2,7 @@ "name": "com.michaelo.oxgframe", "displayName": "OxGFrame", "description": "The OxGFrame is a framework based on Unity for accelerating game development. Supports multi-platform Win, OSX, Android, iOS, WebGL.", - "version": "2.10.1", + "version": "2.10.2", "unity": "2021.3", "license": "MIT", "samples": [