From 966c2891bb87a8b6964e0d22108ebb9f068b6d55 Mon Sep 17 00:00:00 2001 From: MichaelO Date: Fri, 24 May 2024 00:31:38 +0800 Subject: [PATCH] added progression param to sync LoadScene methods (organized) --- .../Scripts/Runtime/AssetLoaders.cs | 24 +- .../Scripts/Runtime/Cacher/CacheBundle.cs | 10 +- .../Scripts/Runtime/Core/CoreFrames.cs | 394 ++++++------------ .../Scripts/Runtime/Core/USFrame/USManager.cs | 18 +- .../USFrameDemo/Scripts/USFrameDemo.cs | 30 +- .../Samples~/USFrameDemo/USFrameDemo.unity | 1 + 6 files changed, 198 insertions(+), 279 deletions(-) diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/AssetLoaders.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/AssetLoaders.cs index 69594be3..e86370db 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/AssetLoaders.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/AssetLoaders.cs @@ -41,15 +41,15 @@ public static async UniTask LoadSceneAsync(string packageName, strin /// /// /// - public static BundlePack LoadScene(string assetName, LoadSceneMode loadSceneMode = LoadSceneMode.Single) + public static BundlePack LoadScene(string assetName, LoadSceneMode loadSceneMode = LoadSceneMode.Single, Progression progression = null) { string packageName = AssetPatcher.GetDefaultPackageName(); - return CacheBundle.GetInstance().LoadScene(packageName, assetName, loadSceneMode); + return CacheBundle.GetInstance().LoadScene(packageName, assetName, loadSceneMode, progression); } - public static BundlePack LoadScene(string packageName, string assetName, LoadSceneMode loadSceneMode = LoadSceneMode.Single) + public static BundlePack LoadScene(string packageName, string assetName, LoadSceneMode loadSceneMode = LoadSceneMode.Single, Progression progression = null) { - return CacheBundle.GetInstance().LoadScene(packageName, assetName, loadSceneMode); + return CacheBundle.GetInstance().LoadScene(packageName, assetName, loadSceneMode, progression); } /// @@ -77,15 +77,15 @@ public static async UniTask LoadSingleSceneAsync(string packageName, /// /// /// - public static BundlePack LoadSingleScene(string assetName) + public static BundlePack LoadSingleScene(string assetName, Progression progression = null) { string packageName = AssetPatcher.GetDefaultPackageName(); - return CacheBundle.GetInstance().LoadScene(packageName, assetName, LoadSceneMode.Single); + return CacheBundle.GetInstance().LoadScene(packageName, assetName, LoadSceneMode.Single, progression); } - public static BundlePack LoadSingleScene(string packageName, string assetName) + public static BundlePack LoadSingleScene(string packageName, string assetName, Progression progression = null) { - return CacheBundle.GetInstance().LoadScene(packageName, assetName, LoadSceneMode.Single); + return CacheBundle.GetInstance().LoadScene(packageName, assetName, LoadSceneMode.Single, progression); } /// @@ -113,15 +113,15 @@ public static async UniTask LoadAdditiveSceneAsync(string packageNam /// /// /// - public static BundlePack LoadAdditiveScene(string assetName) + public static BundlePack LoadAdditiveScene(string assetName, Progression progression = null) { string packageName = AssetPatcher.GetDefaultPackageName(); - return CacheBundle.GetInstance().LoadScene(packageName, assetName, LoadSceneMode.Additive); + return CacheBundle.GetInstance().LoadScene(packageName, assetName, LoadSceneMode.Additive, progression); } - public static BundlePack LoadAdditiveScene(string packageName, string assetName) + public static BundlePack LoadAdditiveScene(string packageName, string assetName, Progression progression = null) { - return CacheBundle.GetInstance().LoadScene(packageName, assetName, LoadSceneMode.Additive); + return CacheBundle.GetInstance().LoadScene(packageName, assetName, LoadSceneMode.Additive, progression); } /// diff --git a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheBundle.cs b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheBundle.cs index 3341342f..6fdff762 100644 --- a/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheBundle.cs +++ b/Assets/OxGFrame/AssetLoader/Scripts/Runtime/Cacher/CacheBundle.cs @@ -646,7 +646,7 @@ public async UniTask LoadSceneAsync(string packageName, string asset return pack; } - public BundlePack LoadScene(string packageName, string assetName, LoadSceneMode loadSceneMode) + public BundlePack LoadScene(string packageName, string assetName, LoadSceneMode loadSceneMode, Progression progression) { /** * Single Scene will auto unload and release @@ -666,6 +666,10 @@ public BundlePack LoadScene(string packageName, string assetName, LoadSceneMode return null; } + // 初始加載進度 + this.currentCount = 0; + this.totalCount = 1; + // 場景最多嘗試 1 次 byte maxRetryCount = 1; // Loading 標記 @@ -686,6 +690,8 @@ public BundlePack LoadScene(string packageName, string assetName, LoadSceneMode { if (req.IsDone) { + this.currentCount++; + progression?.Invoke(this.currentCount / this.totalCount, this.currentCount, this.totalCount); loaded = true; switch (loadSceneMode) { @@ -743,7 +749,7 @@ public BundlePack LoadScene(string packageName, string assetName, LoadSceneMode 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 this.LoadScene(packageName, assetName, loadSceneMode); + return this.LoadScene(packageName, assetName, loadSceneMode, progression); } this.RemoveLoadingFlags(assetName); diff --git a/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/CoreFrames.cs b/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/CoreFrames.cs index 13789682..d96da2e7 100644 --- a/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/CoreFrames.cs +++ b/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/CoreFrames.cs @@ -649,25 +649,7 @@ public static void SetActiveSceneRootGameObjects(Scene scene, bool active, strin public static async UniTask LoadSingleSceneAsync(string sceneName, Progression progression = null) { var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - await USManager.GetInstance().LoadFromBuildAsync(sceneName, LoadSceneMode.Single, progression); - } - else await USManager.GetInstance().LoadFromBundleAsync(packageName, sceneName, LoadSceneMode.Single, true, 100, progression); - } - - /// - /// (Single) If use prefix "build#" will load from build and else will load from bundle - /// - /// - public static void LoadSingleScene(string sceneName) - { - var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - USManager.GetInstance().LoadFromBuild(sceneName, LoadSceneMode.Single); - } - else USManager.GetInstance().LoadFromBundle(packageName, sceneName, LoadSceneMode.Single); + await LoadSingleSceneAsync(packageName, sceneName, progression); } /// @@ -683,11 +665,7 @@ public static void LoadSingleScene(string sceneName) public static async UniTask LoadSingleSceneAsync(string sceneName, Progression progression = null) where T : class { var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - return await USManager.GetInstance().LoadFromBuildAsync(sceneName, LoadSceneMode.Single, progression) as T; - } - else return await USManager.GetInstance().LoadFromBundleAsync(packageName, sceneName, LoadSceneMode.Single, true, 100, progression) as T; + return await LoadSingleSceneAsync(packageName, sceneName, progression); } /// @@ -706,20 +684,6 @@ public static async UniTask LoadSingleSceneAsync(string packageName, string scen else await USManager.GetInstance().LoadFromBundleAsync(packageName, sceneName, LoadSceneMode.Single, true, 100, progression); } - /// - /// (Single) If use prefix "build#" will load from build and else will load from bundle - /// - /// - /// - public static void LoadSingleScene(string packageName, string sceneName) - { - if (RefineBuildScenePath(ref sceneName)) - { - USManager.GetInstance().LoadFromBuild(sceneName, LoadSceneMode.Single); - } - else USManager.GetInstance().LoadFromBundle(packageName, sceneName, LoadSceneMode.Single); - } - /// /// (Single) If use prefix "build#" will load from build and else will load from bundle /// @@ -741,57 +705,47 @@ public static async UniTask LoadSingleSceneAsync(string packageName, strin } /// - /// (Additive) If use prefix "build#" will load from build and else will load from bundle + /// (Single) If use prefix "build#" will load from build and else will load from bundle /// /// - /// - /// - /// - /// - public static async UniTask LoadAdditiveSceneAsync(string sceneName, bool activateOnLoad = true, uint priority = 100, Progression progression = null) + public static void LoadSingleScene(string sceneName, Progression progression = null) { var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - await USManager.GetInstance().LoadFromBuildAsync(sceneName, LoadSceneMode.Additive, progression); - } - else await USManager.GetInstance().LoadFromBundleAsync(packageName, sceneName, LoadSceneMode.Additive, activateOnLoad, priority, progression); + LoadSingleScene(packageName, sceneName, progression); } - public static async UniTask LoadAdditiveSceneAsync(string sceneName, bool activeRootGameObjects = true, bool activateOnLoad = true, uint priority = 100, Progression progression = null) + /// + /// (Single) If use prefix "build#" will load from build and else will load from bundle + /// + /// + /// + public static void LoadSingleScene(string packageName, string sceneName, Progression progression = null) { - var packageName = AssetPatcher.GetDefaultPackageName(); if (RefineBuildScenePath(ref sceneName)) { - await USManager.GetInstance().LoadFromBuildAsync(sceneName, LoadSceneMode.Additive, progression); + USManager.GetInstance().LoadFromBuild(sceneName, LoadSceneMode.Single, progression); } - else await USManager.GetInstance().LoadFromBundleAsync(packageName, sceneName, LoadSceneMode.Additive, activateOnLoad, priority, progression); - if (!activeRootGameObjects) USManager.GetInstance().SetActiveSceneRootGameObjects(sceneName, false); + else USManager.GetInstance().LoadFromBundle(packageName, sceneName, LoadSceneMode.Single, progression); } /// /// (Additive) If use prefix "build#" will load from build and else will load from bundle /// /// - public static void LoadAdditiveScene(string sceneName) + /// + /// + /// + /// + public static async UniTask LoadAdditiveSceneAsync(string sceneName, bool activateOnLoad = true, uint priority = 100, Progression progression = null) { var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - USManager.GetInstance().LoadFromBuild(sceneName, LoadSceneMode.Additive); - } - else USManager.GetInstance().LoadFromBundle(packageName, sceneName, LoadSceneMode.Additive); + await LoadAdditiveSceneAsync(packageName, sceneName, activateOnLoad, priority, progression); } - public static void LoadAdditiveScene(string sceneName, bool activeRootGameObjects = true) + public static async UniTask LoadAdditiveSceneAsync(string sceneName, bool activeRootGameObjects = true, bool activateOnLoad = true, uint priority = 100, Progression progression = null) { var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - USManager.GetInstance().LoadFromBuild(sceneName, LoadSceneMode.Additive); - } - else USManager.GetInstance().LoadFromBundle(packageName, sceneName, LoadSceneMode.Additive); - if (!activeRootGameObjects) USManager.GetInstance().SetActiveSceneRootGameObjects(sceneName, false); + await LoadAdditiveSceneAsync(packageName, sceneName, activeRootGameObjects, activateOnLoad, priority, progression); } /// @@ -809,28 +763,13 @@ public static void LoadAdditiveScene(string sceneName, bool activeRootGameObject public static async UniTask LoadAdditiveSceneAsync(string sceneName, bool activateOnLoad = true, uint priority = 100, Progression progression = null) where T : class { var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - return await USManager.GetInstance().LoadFromBuildAsync(sceneName, LoadSceneMode.Additive, progression) as T; - } - else return await USManager.GetInstance().LoadFromBundleAsync(packageName, sceneName, LoadSceneMode.Additive, activateOnLoad, priority, progression) as T; + return await LoadAdditiveSceneAsync(packageName, sceneName, activateOnLoad, priority, progression); } public static async UniTask LoadAdditiveSceneAsync(string sceneName, bool activeRootGameObjects = true, bool activateOnLoad = true, uint priority = 100, Progression progression = null) where T : class { var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - var handler = await USManager.GetInstance().LoadFromBuildAsync(sceneName, LoadSceneMode.Additive, progression) as T; - if (!activeRootGameObjects) USManager.GetInstance().SetActiveSceneRootGameObjects(sceneName, false); - return handler; - } - else - { - var handler = await USManager.GetInstance().LoadFromBundleAsync(packageName, sceneName, LoadSceneMode.Additive, activateOnLoad, priority, progression) as T; - if (!activeRootGameObjects) USManager.GetInstance().SetActiveSceneRootGameObjects(sceneName, false); - return handler; - } + return await LoadAdditiveSceneAsync(packageName, sceneName, activeRootGameObjects, activateOnLoad, priority, progression); } /// @@ -861,30 +800,6 @@ public static async UniTask LoadAdditiveSceneAsync(string packageName, string sc if (!activeRootGameObjects) USManager.GetInstance().SetActiveSceneRootGameObjects(sceneName, false); } - /// - /// (Additive) If use prefix "build#" will load from build and else will load from bundle - /// - /// - /// - public static void LoadAdditiveScene(string packageName, string sceneName) - { - if (RefineBuildScenePath(ref sceneName)) - { - USManager.GetInstance().LoadFromBuild(sceneName, LoadSceneMode.Additive); - } - else USManager.GetInstance().LoadFromBundle(packageName, sceneName, LoadSceneMode.Additive); - } - - public static void LoadAdditiveScene(string packageName, string sceneName, bool activeRootGameObjects = true) - { - if (RefineBuildScenePath(ref sceneName)) - { - USManager.GetInstance().LoadFromBuild(sceneName, LoadSceneMode.Additive); - } - else USManager.GetInstance().LoadFromBundle(packageName, sceneName, LoadSceneMode.Additive); - if (!activeRootGameObjects) USManager.GetInstance().SetActiveSceneRootGameObjects(sceneName, false); - } - /// /// (Additive) If use prefix "build#" will load from build and else will load from bundle /// @@ -923,6 +838,47 @@ public static async UniTask LoadAdditiveSceneAsync(string packageName, str } } + /// + /// (Additive) If use prefix "build#" will load from build and else will load from bundle + /// + /// + /// + public static void LoadAdditiveScene(string sceneName, Progression progression = null) + { + var packageName = AssetPatcher.GetDefaultPackageName(); + LoadAdditiveScene(packageName, sceneName, progression); + } + + public static void LoadAdditiveScene(string sceneName, bool activeRootGameObjects = true, Progression progression = null) + { + var packageName = AssetPatcher.GetDefaultPackageName(); + LoadAdditiveScene(packageName, sceneName, activeRootGameObjects, progression); + } + + /// + /// (Additive) If use prefix "build#" will load from build and else will load from bundle + /// + /// + /// + public static void LoadAdditiveScene(string packageName, string sceneName, Progression progression = null) + { + if (RefineBuildScenePath(ref sceneName)) + { + USManager.GetInstance().LoadFromBuild(sceneName, LoadSceneMode.Additive, progression); + } + else USManager.GetInstance().LoadFromBundle(packageName, sceneName, LoadSceneMode.Additive, progression); + } + + public static void LoadAdditiveScene(string packageName, string sceneName, bool activeRootGameObjects = true, Progression progression = null) + { + if (RefineBuildScenePath(ref sceneName)) + { + USManager.GetInstance().LoadFromBuild(sceneName, LoadSceneMode.Additive, progression); + } + else USManager.GetInstance().LoadFromBundle(packageName, sceneName, LoadSceneMode.Additive, progression); + if (!activeRootGameObjects) USManager.GetInstance().SetActiveSceneRootGameObjects(sceneName, false); + } + /// /// Load single scene and additive scenes /// @@ -932,6 +888,21 @@ public static async UniTask LoadAdditiveSceneAsync(string packageName, str /// /// public static async UniTask LoadMainAndSubScenesAsync(string singleSceneName, AdditiveSceneInfo[] additiveSceneInfos, uint priority = 100, Progression progression = null) + { + var packageName = AssetPatcher.GetDefaultPackageName(); + await LoadMainAndSubScenesAsync(packageName, singleSceneName, additiveSceneInfos, priority, progression); + } + + /// + /// Load single scene and additive scenes + /// + /// + /// + /// + /// + /// + /// + public static async UniTask LoadMainAndSubScenesAsync(string packageName, string singleSceneName, AdditiveSceneInfo[] additiveSceneInfos, uint priority = 100, Progression progression = null) { var scene = GetSceneByName(singleSceneName); if (!string.IsNullOrEmpty(scene.name) && @@ -949,7 +920,7 @@ public static async UniTask LoadMainAndSubScenesAsync(string singleSceneName, Ad // Single scene bool loaded = false; - await LoadSingleSceneAsync(singleSceneName, (float progress, float currentCount, float totalCount) => + await LoadSingleSceneAsync(packageName, singleSceneName, (float progress, float currentCount, float totalCount) => { if (!loaded && progress == 1) { @@ -968,6 +939,7 @@ await LoadSingleSceneAsync(singleSceneName, (float progress, float currentCount, loaded = false; await LoadAdditiveSceneAsync ( + packageName, additiveSceneInfo.sceneName, additiveSceneInfo.activeRootGameObjects, true, @@ -987,41 +959,28 @@ await LoadAdditiveSceneAsync } } - public static void LoadMainAndSubScenes(string singleSceneName, AdditiveSceneInfo[] additiveSceneInfos) + /// + /// Load additive scenes + /// + /// + /// + /// + /// + public static async UniTask LoadSubScenesAsync(AdditiveSceneInfo[] additiveSceneInfos, uint priority = 100, Progression progression = null) { - var scene = GetSceneByName(singleSceneName); - if (!string.IsNullOrEmpty(scene.name) && - scene.isLoaded) - { - Logging.PrintWarning($"Single Scene => {singleSceneName} already exists!!!"); - return; - } - - // Single scene - LoadSingleScene(singleSceneName); - - // Additive scenes - if (additiveSceneInfos != null) - { - foreach (var additiveSceneInfo in additiveSceneInfos) - { - LoadAdditiveScene - ( - additiveSceneInfo.sceneName, - additiveSceneInfo.activeRootGameObjects - ); - } - } + var packageName = AssetPatcher.GetDefaultPackageName(); + await LoadSubScenesAsync(packageName, additiveSceneInfos, priority, progression); } /// /// Load additive scenes /// + /// /// /// /// /// - public static async UniTask LoadSubScenesAsync(AdditiveSceneInfo[] additiveSceneInfos, uint priority = 100, Progression progression = null) + public static async UniTask LoadSubScenesAsync(string packageName, AdditiveSceneInfo[] additiveSceneInfos, uint priority = 100, Progression progression = null) { float comboCurrentCount = 0; float comboTotalCount = 0; @@ -1038,6 +997,7 @@ public static async UniTask LoadSubScenesAsync(AdditiveSceneInfo[] additiveScene bool loaded = false; await LoadAdditiveSceneAsync ( + packageName, additiveSceneInfo.sceneName, additiveSceneInfo.activeRootGameObjects, true, @@ -1057,32 +1017,19 @@ await LoadAdditiveSceneAsync } } - public static void LoadSubScenes(AdditiveSceneInfo[] additiveSceneInfos) - { - // Additive scenes - if (additiveSceneInfos != null) - { - foreach (var additiveSceneInfo in additiveSceneInfos) - { - LoadAdditiveScene - ( - additiveSceneInfo.sceneName, - additiveSceneInfo.activeRootGameObjects - ); - } - } - } - /// /// Load single scene and additive scenes /// - /// /// /// - /// /// - /// - public static async UniTask LoadMainAndSubScenesAsync(string packageName, string singleSceneName, AdditiveSceneInfo[] additiveSceneInfos, uint priority = 100, Progression progression = null) + public static void LoadMainAndSubScenes(string singleSceneName, AdditiveSceneInfo[] additiveSceneInfos, Progression progression = null) + { + var packageName = AssetPatcher.GetDefaultPackageName(); + LoadMainAndSubScenes(packageName, singleSceneName, additiveSceneInfos, progression); + } + + public static void LoadMainAndSubScenes(string packageName, string singleSceneName, AdditiveSceneInfo[] additiveSceneInfos, Progression progression = null) { var scene = GetSceneByName(singleSceneName); if (!string.IsNullOrEmpty(scene.name) && @@ -1100,7 +1047,7 @@ public static async UniTask LoadMainAndSubScenesAsync(string packageName, string // Single scene bool loaded = false; - await LoadSingleSceneAsync(packageName, singleSceneName, (float progress, float currentCount, float totalCount) => + LoadSingleScene(packageName, singleSceneName, (float progress, float currentCount, float totalCount) => { if (!loaded && progress == 1) { @@ -1113,17 +1060,14 @@ await LoadSingleSceneAsync(packageName, singleSceneName, (float progress, float // Additive scenes if (additiveSceneInfos != null) { - uint idx = 0; foreach (var additiveSceneInfo in additiveSceneInfos) { loaded = false; - await LoadAdditiveSceneAsync + LoadAdditiveScene ( packageName, additiveSceneInfo.sceneName, additiveSceneInfo.activeRootGameObjects, - true, - priority + idx, (float progress, float currentCount, float totalCount) => { if (!loaded && progress == 1) @@ -1134,48 +1078,17 @@ await LoadAdditiveSceneAsync progression?.Invoke(comboCurrentCount / comboTotalCount, comboCurrentCount, comboTotalCount); } ); - idx++; } } } - public static void LoadMainAndSubScenes(string packageName, string singleSceneName, AdditiveSceneInfo[] additiveSceneInfos) + public static void LoadSubScenes(AdditiveSceneInfo[] additiveSceneInfos, Progression progression = null) { - var scene = GetSceneByName(singleSceneName); - if (!string.IsNullOrEmpty(scene.name) && - scene.isLoaded) - { - Logging.PrintWarning($"Single Scene => {singleSceneName} already exists!!!"); - return; - } - - // Single scene - LoadSingleScene(packageName, singleSceneName); - - // Additive scenes - if (additiveSceneInfos != null) - { - foreach (var additiveSceneInfo in additiveSceneInfos) - { - LoadAdditiveScene - ( - packageName, - additiveSceneInfo.sceneName, - additiveSceneInfo.activeRootGameObjects - ); - } - } + var packageName = AssetPatcher.GetDefaultPackageName(); + LoadSubScenes(packageName, additiveSceneInfos, progression); } - /// - /// Load additive scenes - /// - /// - /// - /// - /// - /// - public static async UniTask LoadSubScenesAsync(string packageName, AdditiveSceneInfo[] additiveSceneInfos, uint priority = 100, Progression progression = null) + public static void LoadSubScenes(string packageName, AdditiveSceneInfo[] additiveSceneInfos, Progression progression = null) { float comboCurrentCount = 0; float comboTotalCount = 0; @@ -1186,17 +1099,14 @@ public static async UniTask LoadSubScenesAsync(string packageName, AdditiveScene // Additive scenes if (additiveSceneInfos != null) { - uint idx = 0; foreach (var additiveSceneInfo in additiveSceneInfos) { bool loaded = false; - await LoadAdditiveSceneAsync + LoadAdditiveScene ( packageName, additiveSceneInfo.sceneName, additiveSceneInfo.activeRootGameObjects, - true, - priority + idx, (float progress, float currentCount, float totalCount) => { if (!loaded && progress == 1) @@ -1207,24 +1117,6 @@ await LoadAdditiveSceneAsync progression?.Invoke(comboCurrentCount / comboTotalCount, comboCurrentCount, comboTotalCount); } ); - idx++; - } - } - } - - public static void LoadSubScenes(string packageName, AdditiveSceneInfo[] additiveSceneInfos) - { - // Additive scenes - if (additiveSceneInfos != null) - { - foreach (var additiveSceneInfo in additiveSceneInfos) - { - LoadAdditiveScene - ( - packageName, - additiveSceneInfo.sceneName, - additiveSceneInfo.activeRootGameObjects - ); } } } @@ -1241,11 +1133,7 @@ public static void LoadSubScenes(string packageName, AdditiveSceneInfo[] additiv public static async UniTask LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode, bool activateOnLoad = true, uint priority = 100, Progression progression = null) { var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - await USManager.GetInstance().LoadFromBuildAsync(sceneName, loadSceneMode, progression); - } - else await USManager.GetInstance().LoadFromBundleAsync(packageName, sceneName, loadSceneMode, activateOnLoad, priority, progression); + await LoadSceneAsync(packageName, sceneName, loadSceneMode, activateOnLoad, priority, progression); } /// @@ -1263,26 +1151,7 @@ public static async UniTask LoadSceneAsync(string sceneName, LoadSceneMode loadS public static async UniTask LoadSceneAsync(string sceneName, LoadSceneMode loadSceneMode, bool activateOnLoad = true, uint priority = 100, Progression progression = null) where T : class { var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - return await USManager.GetInstance().LoadFromBuildAsync(sceneName, loadSceneMode, progression) as T; - } - else return await USManager.GetInstance().LoadFromBundleAsync(packageName, sceneName, loadSceneMode, activateOnLoad, priority, progression) as T; - } - - /// - /// If use prefix "build#" will load from build and else will load from bundle - /// - /// - /// - public static void LoadScene(string sceneName, LoadSceneMode loadSceneMode) - { - var packageName = AssetPatcher.GetDefaultPackageName(); - if (RefineBuildScenePath(ref sceneName)) - { - USManager.GetInstance().LoadFromBuild(sceneName, loadSceneMode); - } - else USManager.GetInstance().LoadFromBundle(packageName, sceneName, loadSceneMode); + return await LoadSceneAsync(packageName, sceneName, loadSceneMode, activateOnLoad, priority, progression); } /// @@ -1327,31 +1196,44 @@ public static async UniTask LoadSceneAsync(string packageName, string scen else return await USManager.GetInstance().LoadFromBundleAsync(packageName, sceneName, loadSceneMode, activateOnLoad, priority, progression) as T; } + /// + /// Only load from build via build index + /// + /// + /// + /// + /// + public static async UniTask LoadSceneAsync(int buildIndex, LoadSceneMode loadSceneMode = LoadSceneMode.Single, Progression progression = null) + { + return await USManager.GetInstance().LoadFromBuildAsync(buildIndex, loadSceneMode, progression); + } + /// /// If use prefix "build#" will load from build and else will load from bundle /// - /// /// /// - public static void LoadScene(string packageName, string sceneName, LoadSceneMode loadSceneMode) + /// + public static void LoadScene(string sceneName, LoadSceneMode loadSceneMode, Progression progression = null) { - if (RefineBuildScenePath(ref sceneName)) - { - USManager.GetInstance().LoadFromBuild(sceneName, loadSceneMode); - } - else USManager.GetInstance().LoadFromBundle(packageName, sceneName, loadSceneMode); + var packageName = AssetPatcher.GetDefaultPackageName(); + LoadScene(packageName, sceneName, loadSceneMode, progression); } /// - /// Only load from build via build index + /// If use prefix "build#" will load from build and else will load from bundle /// - /// + /// + /// /// /// - /// - public static async UniTask LoadSceneAsync(int buildIndex, LoadSceneMode loadSceneMode = LoadSceneMode.Single, Progression progression = null) + public static void LoadScene(string packageName, string sceneName, LoadSceneMode loadSceneMode, Progression progression = null) { - return await USManager.GetInstance().LoadFromBuildAsync(buildIndex, loadSceneMode, progression); + if (RefineBuildScenePath(ref sceneName)) + { + USManager.GetInstance().LoadFromBuild(sceneName, loadSceneMode, progression); + } + else USManager.GetInstance().LoadFromBundle(packageName, sceneName, loadSceneMode, progression); } /// @@ -1359,9 +1241,11 @@ public static async UniTask LoadSceneAsync(int buildIndex, LoadS /// /// /// - public static Scene LoadScene(int buildIndex, LoadSceneMode loadSceneMode = LoadSceneMode.Single) + /// + /// + public static Scene LoadScene(int buildIndex, LoadSceneMode loadSceneMode = LoadSceneMode.Single, Progression progression = null) { - return USManager.GetInstance().LoadFromBuild(buildIndex, loadSceneMode); + return USManager.GetInstance().LoadFromBuild(buildIndex, loadSceneMode, progression); } /// diff --git a/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/USFrame/USManager.cs b/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/USFrame/USManager.cs index 44ba8e60..44bd74d8 100644 --- a/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/USFrame/USManager.cs +++ b/Assets/OxGFrame/CoreFrame/Scripts/Runtime/Core/USFrame/USManager.cs @@ -166,7 +166,7 @@ public async UniTask LoadFromBundleAsync(string packageName, string return null; } - public BundlePack LoadFromBundle(string packageName, string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single) + public BundlePack LoadFromBundle(string packageName, string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single, Progression progression = null) { var scene = this.GetSceneByName(sceneName); if (!string.IsNullOrEmpty(scene.name) && @@ -177,7 +177,7 @@ public BundlePack LoadFromBundle(string packageName, string sceneName, LoadScene return null; } - var pack = AssetLoaders.LoadScene(packageName, sceneName, loadSceneMode); + var pack = AssetLoaders.LoadScene(packageName, sceneName, loadSceneMode, progression); if (pack != null) { Logging.Print($"Load Scene From Bundle => sceneName: {sceneName}, mode: {loadSceneMode}"); @@ -239,7 +239,7 @@ public async UniTask LoadFromBuildAsync(string sceneName, LoadSc return req; } - public Scene LoadFromBuild(string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single) + public Scene LoadFromBuild(string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single, Progression progression = null) { this._currentCount = 0; this._totalCount = 1; // 初始 1 = 必有一場景 @@ -254,6 +254,11 @@ public Scene LoadFromBuild(string sceneName, LoadSceneMode loadSceneMode = LoadS } scene = SceneManager.LoadScene(sceneName, new LoadSceneParameters(loadSceneMode)); + if (progression != null) + { + this._currentCount++; + progression.Invoke(this._currentCount / this._totalCount, this._currentCount, this._totalCount); + } Logging.Print($"Load Scene From Build => sceneName: {sceneName}, mode: {loadSceneMode}"); // (Caution) If use sync to load scene.isLoaded return false -> Why?? return scene; @@ -297,7 +302,7 @@ public async UniTask LoadFromBuildAsync(int buildIndex, LoadScen return req; } - public Scene LoadFromBuild(int buildIndex, LoadSceneMode loadSceneMode = LoadSceneMode.Single) + public Scene LoadFromBuild(int buildIndex, LoadSceneMode loadSceneMode = LoadSceneMode.Single, Progression progression = null) { this._currentCount = 0; this._totalCount = 1; // 初始 1 = 必有一場景 @@ -313,6 +318,11 @@ public Scene LoadFromBuild(int buildIndex, LoadSceneMode loadSceneMode = LoadSce } scene = SceneManager.LoadScene(sceneName, new LoadSceneParameters(loadSceneMode)); + if (progression != null) + { + this._currentCount++; + progression.Invoke(this._currentCount / this._totalCount, this._currentCount, this._totalCount); + } Logging.Print($"Load Scene From Build => idx: {buildIndex}, mode: {loadSceneMode}"); // (Caution) If use sync to load scene.isLoaded return false -> Why?? return scene; diff --git a/Assets/OxGFrame/Samples~/USFrameDemo/Scripts/USFrameDemo.cs b/Assets/OxGFrame/Samples~/USFrameDemo/Scripts/USFrameDemo.cs index f0e75fe1..b6091734 100644 --- a/Assets/OxGFrame/Samples~/USFrameDemo/Scripts/USFrameDemo.cs +++ b/Assets/OxGFrame/Samples~/USFrameDemo/Scripts/USFrameDemo.cs @@ -63,7 +63,10 @@ await CoreFrames.USFrame.LoadSceneAsync(UnityScene.Build.LevelDemo01, LoadSceneM } else { - CoreFrames.USFrame.LoadScene(UnityScene.Build.LevelDemo01, LoadSceneMode.Single); + CoreFrames.USFrame.LoadScene(UnityScene.Build.LevelDemo01, LoadSceneMode.Single, (float progress, float currentCount, float totalCount) => + { + Debug.Log($"Progress: {progress}, CurrentCount: {currentCount}, TotalCount: {totalCount}"); + }); } } @@ -82,7 +85,10 @@ await CoreFrames.USFrame.LoadSceneAsync(UnityScene.Build.LevelDemo02, LoadSceneM } else { - CoreFrames.USFrame.LoadScene(UnityScene.Build.LevelDemo02, LoadSceneMode.Single); + CoreFrames.USFrame.LoadScene(UnityScene.Build.LevelDemo02, LoadSceneMode.Single, (float progress, float currentCount, float totalCount) => + { + Debug.Log($"Progress: {progress}, CurrentCount: {currentCount}, TotalCount: {totalCount}"); + }); } } @@ -101,7 +107,10 @@ await CoreFrames.USFrame.LoadSceneAsync(UnityScene.Build.LevelDemo03, LoadSceneM } else { - CoreFrames.USFrame.LoadScene(UnityScene.Build.LevelDemo03, LoadSceneMode.Additive); + CoreFrames.USFrame.LoadScene(UnityScene.Build.LevelDemo03, LoadSceneMode.Additive, (float progress, float currentCount, float totalCount) => + { + Debug.Log($"Progress: {progress}, CurrentCount: {currentCount}, TotalCount: {totalCount}"); + }); } } #endregion @@ -122,7 +131,10 @@ await CoreFrames.USFrame.LoadSceneAsync(UnityScene.Bundle.LevelDemo01, LoadScene } else { - CoreFrames.USFrame.LoadScene(UnityScene.Bundle.LevelDemo01, LoadSceneMode.Single); + CoreFrames.USFrame.LoadScene(UnityScene.Bundle.LevelDemo01, LoadSceneMode.Single, (float progress, float currentCount, float totalCount) => + { + Debug.Log($"Progress: {progress}, CurrentCount: {currentCount}, TotalCount: {totalCount}"); + }); } } @@ -141,7 +153,10 @@ await CoreFrames.USFrame.LoadSceneAsync(UnityScene.Bundle.LevelDemo02, LoadScene } else { - CoreFrames.USFrame.LoadScene(UnityScene.Bundle.LevelDemo02, LoadSceneMode.Single); + CoreFrames.USFrame.LoadScene(UnityScene.Bundle.LevelDemo02, LoadSceneMode.Single, (float progress, float currentCount, float totalCount) => + { + Debug.Log($"Progress: {progress}, CurrentCount: {currentCount}, TotalCount: {totalCount}"); + }); } } @@ -160,7 +175,10 @@ await CoreFrames.USFrame.LoadSceneAsync(UnityScene.Bundle.LevelDemo03, LoadScene } else { - CoreFrames.USFrame.LoadScene(UnityScene.Bundle.LevelDemo03, LoadSceneMode.Additive); + CoreFrames.USFrame.LoadScene(UnityScene.Bundle.LevelDemo03, LoadSceneMode.Additive, (float progress, float currentCount, float totalCount) => + { + Debug.Log($"Progress: {progress}, CurrentCount: {currentCount}, TotalCount: {totalCount}"); + }); } } #endregion diff --git a/Assets/OxGFrame/Samples~/USFrameDemo/USFrameDemo.unity b/Assets/OxGFrame/Samples~/USFrameDemo/USFrameDemo.unity index fe5f0984..c4563483 100644 --- a/Assets/OxGFrame/Samples~/USFrameDemo/USFrameDemo.unity +++ b/Assets/OxGFrame/Samples~/USFrameDemo/USFrameDemo.unity @@ -350,6 +350,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f2b89c717717ffc4a8db4691afc1fdbc, type: 3} m_Name: m_EditorClassIdentifier: + syncMode: 0 --- !u!1 &892747931 GameObject: m_ObjectHideFlags: 0