From 3f2cd27c5dfb3b450245bf1a37fc1b3414031c7c Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期三, 11 二月 2026 11:03:58 +0800
Subject: [PATCH] 小游戏适配 资源系统改造
---
Main/Manager/StageManager.cs | 119 +++++++++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 99 insertions(+), 20 deletions(-)
diff --git a/Main/Manager/StageManager.cs b/Main/Manager/StageManager.cs
index 9b6e0a1..1f56223 100644
--- a/Main/Manager/StageManager.cs
+++ b/Main/Manager/StageManager.cs
@@ -3,6 +3,7 @@
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
+using ProjSG.Resource;
public enum StageName
{
@@ -37,14 +38,39 @@
{
UIManager.Instance.DestroyAllUI();
+ // US3: Show loading screen FIRST, then load resources with progress
+ LoadingWin loadingWin = UIManager.Instance.OpenWindow<LoadingWin>();
+ InitLoadingWinData(loadingWin);
+
+ // Phase 1 (0% ~ 30%): YooAsset resource preload
if (AssetSource.isUseAssetBundle)
{
- AssetBundleUtility.Instance.Sync_LoadAll("maps/Login");
+ loadingWin.SetProgress(0.05f);
+ await YooAssetService.Instance.LoadAllAssetsAsync<UnityEngine.Object>("Assets/ResourcesOut/maps/Login");
+ loadingWin.SetProgress(0.3f);
}
+ // Phase 2 (30% ~ 60%): Scene loading
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync("Login");
+ asyncOperation.allowSceneActivation = false;
- await OnLoading(asyncOperation, ConfigManager.Instance.GetLoadingProgress, Main.InitManagers);
+ while (!asyncOperation.isDone)
+ {
+ if (asyncOperation.progress >= 0.9f)
+ {
+ asyncOperation.allowSceneActivation = true;
+ }
+ loadingWin.SetProgress(0.3f + asyncOperation.progress * 0.3f);
+ await UniTask.Yield();
+ }
+
+ // Phase 3 (60% ~ 100%): Manager initialization
+ await WaitForManagerProgress(loadingWin, 0.6f, 1.0f,
+ ConfigManager.Instance.GetLoadingProgress, Main.InitManagers);
+
+ loadingWin.SetProgress(1f, true);
+ await UniTask.Delay(TimeSpan.FromSeconds(0.5f));
+ loadingWin.CloseWindow();
Main.OnSwitchToLoginScene();
@@ -52,7 +78,6 @@
UIManager.Instance.OpenWindow<LaunchBackGroundWin>();
UIManager.Instance.OpenWindow<LoginWin>();
- // SoundPlayer.Instance.StopBackGroundMusic();
if (VersionUtility.Instance.NeedDownAsset() && !AssetVersionUtility.hasDownLoadFullAsset)
{
@@ -111,15 +136,41 @@
BeforeLoadingGameScene?.Invoke();
- // ResManager.Instance.PrewarmResources();
+ // US3: Show loading screen FIRST, then load resources with progress
+ LoadingWin loadingWin = UIManager.Instance.OpenWindow<LoadingWin>();
+ InitLoadingWinData(loadingWin);
+
+ // Phase 1 (0% ~ 30%): YooAsset resource preload
if (AssetSource.isUseAssetBundle)
{
- AssetBundleUtility.Instance.Sync_LoadAll("maps/Game");
+ loadingWin.SetProgress(0.05f);
+ await YooAssetService.Instance.LoadAllAssetsAsync<UnityEngine.Object>("Assets/ResourcesOut/maps/Game");
+ loadingWin.SetProgress(0.3f);
}
- SoundPlayer.Instance.StopBackGroundMusic();
- AsyncOperation asyncOperation = SceneManager.LoadSceneAsync("Game");
- await OnLoading(asyncOperation, () => (DTC0403_tagPlayerLoginLoadOK.finishedLogin ? .5f : 0f) + GetManagerRequestDataProgress() * .5f);
+ SoundPlayer.Instance.StopBackGroundMusic();
+
+ // Phase 2 (30% ~ 60%): Scene loading
+ AsyncOperation asyncOperation = SceneManager.LoadSceneAsync("Game");
+ asyncOperation.allowSceneActivation = false;
+
+ while (!asyncOperation.isDone)
+ {
+ if (asyncOperation.progress >= 0.9f)
+ {
+ asyncOperation.allowSceneActivation = true;
+ }
+ loadingWin.SetProgress(0.3f + asyncOperation.progress * 0.3f);
+ await UniTask.Yield();
+ }
+
+ // Phase 3 (60% ~ 100%): Manager data ready
+ await WaitForManagerProgress(loadingWin, 0.6f, 1.0f,
+ () => (DTC0403_tagPlayerLoginLoadOK.finishedLogin ? .5f : 0f) + GetManagerRequestDataProgress() * .5f);
+
+ loadingWin.SetProgress(1f, true);
+ await UniTask.Delay(TimeSpan.FromSeconds(0.5f));
+ loadingWin.CloseWindow();
// 鍔犺浇鍒濆鍖栨暟鎹畬鎴�
currentStage = StageName.Game;
@@ -150,18 +201,7 @@
asyncOperation.allowSceneActivation = false;
LoadingWin loadingWin = UIManager.Instance.OpenWindow<LoadingWin>();
-
- LaunchWin launchWin = UIManager.Instance.GetUI<LaunchWin>();
- if (null != launchWin && launchWin.IsActive() && launchWinData == null)
- {
- launchWinData = launchWin.GetData();
- }
-
- if (null != launchWinData)
- {
- loadingWin.SetData(launchWinData);
- launchWinData = null;
- }
+ InitLoadingWinData(loadingWin);
while (!asyncOperation.isDone)
{
@@ -198,6 +238,45 @@
loadingWin.CloseWindow();
}
+ /// <summary>
+ /// US3: 绛夊緟Manager鍒濆鍖栬繘搴﹀苟鏇存柊LoadingWin銆�
+ /// </summary>
+ private async UniTask WaitForManagerProgress(LoadingWin loadingWin, float startPct, float endPct,
+ Func<float> getProgress, Func<UniTask> extraTask = null)
+ {
+ float managerProgress = getProgress();
+
+ while (managerProgress < 1f)
+ {
+ loadingWin.SetProgress(startPct + managerProgress * (endPct - startPct));
+ await UniTask.Yield();
+ managerProgress = getProgress();
+ }
+
+ if (extraTask != null)
+ {
+ await extraTask();
+ }
+ }
+
+ /// <summary>
+ /// US3: 鍒濆鍖� LoadingWin 鏁版嵁锛堜粠 LaunchWin 缁ф壙鑳屾櫙绛夛級銆�
+ /// </summary>
+ private void InitLoadingWinData(LoadingWin loadingWin)
+ {
+ LaunchWin launchWin = UIManager.Instance.GetUI<LaunchWin>();
+ if (launchWin != null && launchWin.IsActive() && launchWinData == null)
+ {
+ launchWinData = launchWin.GetData();
+ }
+
+ if (launchWinData != null)
+ {
+ loadingWin.SetData(launchWinData);
+ launchWinData = null;
+ }
+ }
+
private void OnCloseWindow(UIBase closeUI)
{
if (closeUI is LaunchWin)
--
Gitblit v1.8.0