Skip to content

Commit

Permalink
fixed scene load with suspend bug issue (v2.10.2)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael811125 committed Mar 19, 2024
1 parent e7c0a58 commit 62739d1
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ public Scene GetScene()
return this.GetOperationHandle<SceneHandle>().SceneObject;
}

public bool UnsuspendScene()
{
if (this.IsSceneOperationHandleValid()) return this.GetOperationHandle<SceneHandle>().UnSuspend();
return false;
}

public void UnloadScene()
{
if (this.IsSceneOperationHandleValid()) this.GetOperationHandle<SceneHandle>().UnloadAsync();
Expand Down
102 changes: 43 additions & 59 deletions Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheBundle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -298,12 +292,9 @@ public async UniTask<T> LoadRawFileAsync<T>(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)
{
Expand Down Expand Up @@ -402,11 +393,8 @@ public T LoadRawFile<T>(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);
Expand Down Expand Up @@ -570,25 +558,30 @@ public async UniTask<BundlePack> 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)
Expand Down Expand Up @@ -636,13 +629,16 @@ public async UniTask<BundlePack> LoadSceneAsync(string packageName, string asset
Logging.Print<Logger>($"<color=#ff33ae>Package: {packageName} doesn't exist or location invalid.</color>");
}

if (!loaded || !pack.GetScene().isLoaded)
if (!suspendLoaded)
{
this.UnloadScene(assetName, true);
if (this.GetRetryCounter(assetName).IsRetryActive()) Logging.Print<Logger>($"<color=#f7ff3e>【Load Scene】 => << CacheBundle >> Asset: {assetName} doing retry. Retry count: {this.GetRetryCounter(assetName).retryCount}, Max retry count: {maxRetryCount}</color>");
else Logging.Print<Logger>($"<color=#f7ff3e>【Load Scene】 => << CacheBundle >> Asset: {assetName} start doing retry. Max retry count: {maxRetryCount}</color>");
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<Logger>($"<color=#f7ff3e>【Load Scene】 => << CacheBundle >> Asset: {assetName} doing retry. Retry count: {this.GetRetryCounter(assetName).retryCount}, Max retry count: {maxRetryCount}</color>");
else Logging.Print<Logger>($"<color=#f7ff3e>【Load Scene】 => << CacheBundle >> Asset: {assetName} start doing retry. Max retry count: {maxRetryCount}</color>");
this.GetRetryCounter(assetName).AddRetryCount();
return await this.LoadSceneAsync(packageName, assetName, loadSceneMode, activateOnLoad, priority, progression);
}
}

this.RemoveLoadingFlags(assetName);
Expand Down Expand Up @@ -830,12 +826,9 @@ public void UnloadScene(string assetName, bool recursively)
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)
{
Expand Down Expand Up @@ -940,11 +933,8 @@ public void UnloadScene(string assetName, bool recursively)
{
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);
Expand Down Expand Up @@ -1020,12 +1010,9 @@ public void UnloadScene(string assetName, bool recursively)
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)
{
Expand Down Expand Up @@ -1114,11 +1101,8 @@ public void UnloadScene(string assetName, bool recursively)
{
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,9 @@ public override ResourcePack GetFromCache(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)
{
Expand Down Expand Up @@ -230,12 +227,9 @@ public override ResourcePack GetFromCache(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)
{
Expand Down
21 changes: 20 additions & 1 deletion Assets/OxGFrame/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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<BundlePack>("MyPackage", "SceneName", false, 100);
```
- Added UnsuspendScene in BundlePack.
```C#
// Method 1
var bundlePack = await CoreFrames.USFrame.LoadAdditiveSceneAsync<BundlePack>("MyPackage", "SceneName", false, 100);
bundlePack.GetOperationHandle<SceneHandle>().UnSuspend();

// Method 2
var bundlePack = await CoreFrames.USFrame.LoadAdditiveSceneAsync<BundlePack>("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).
Expand Down
2 changes: 1 addition & 1 deletion Assets/OxGFrame/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down

0 comments on commit 62739d1

Please sign in to comment.