From 5581c616c17fd910a6f9b24b1ee328708fe45239 Mon Sep 17 00:00:00 2001 From: Tungdv Date: Thu, 7 May 2026 17:58:42 +0700 Subject: [PATCH 1/3] fix: update move when done load terrain and lit. --- .../Scripts/World/AddressableObject.cs | 6 ++-- .../Scripts/World/LitModelHolder.cs | 31 ++++++++++++++++--- .../Scripts/World/TerrainHolder.cs | 28 +++++++++++++++-- Assets/Scripts/CECHostPlayer.World.cs | 2 ++ Assets/Scripts/CECHostPlayer.cs | 4 ++- 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/World/AddressableObject.cs b/Assets/PerfectWorld/Scripts/World/AddressableObject.cs index ae97a06678..f0ad2fabd1 100644 --- a/Assets/PerfectWorld/Scripts/World/AddressableObject.cs +++ b/Assets/PerfectWorld/Scripts/World/AddressableObject.cs @@ -1,6 +1,8 @@ using BrewMonster.Scripts; using Cysharp.Threading.Tasks; using UnityEngine; +using System; + #if UNITY_EDITOR using UnityEditor; @@ -35,7 +37,7 @@ namespace BrewMonster } - public async UniTask LoadAsset() + public async UniTask LoadAsset(Action actDone = null) { if (string.IsNullOrEmpty(assetPath)) { @@ -50,7 +52,7 @@ namespace BrewMonster _isLoading = true; int requestId = ++_loadRequestId; var model = await AddressableManager.Instance.LoadPrefabAsync(assetPath); - + actDone?.Invoke(); // Object might have been destroyed while awaiting. if (this == null || gameObject == null) { diff --git a/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs b/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs index 8651386e9a..b4e286ca33 100644 --- a/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs +++ b/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -67,7 +68,13 @@ public class LitModelHolder : MonoSingleton // if load flag is set, process the load and unload objects. if (_needToProcessLoadAndUnload) { - ProcessLoadAndUnloadObjects(); + ProcessLoadAndUnloadObjects(() => + { + if (_hostPlayer != null) + { + _hostPlayer.isLitToReady = true; + } + }); _needToProcessLoadAndUnload = false; } } @@ -284,14 +291,30 @@ public class LitModelHolder : MonoSingleton } _needToProcessLoadAndUnload = true; + //if (_hostPlayer != null) + //{ + // Debug.LogError("ProcessLoadAndUnload Lit _hostPlayer.isLitToReady = false "); + // _hostPlayer.isLitToReady = false; + //} } - private void ProcessLoadAndUnloadObjects() + private void ProcessLoadAndUnloadObjects(Action actDone) { + int begin = 0; + int end = _candidatesForLoading.Count; + Action actLoadingDone = () => + { + begin++; + Debug.LogError("ProcessLoadAndUnload Lit || begin = " + begin + " || end = " + end); + if (begin >= end) + { + actDone?.Invoke(); + } + }; // load the objects that are in the loading range long enough. (_candidateWaitTimeSeconds) foreach (var kvp in _candidatesForLoading) { - kvp.Key.LoadAsset().Forget(); + kvp.Key.LoadAsset(actLoadingDone).Forget(); _loadedObjects.Add(kvp.Key); } _candidatesForLoading.Clear(); @@ -444,4 +467,4 @@ public class LitModelHolder : MonoSingleton $"- anchorsWithMoreThanOneChild={multiChildCount}"); } #endif -} \ No newline at end of file +} diff --git a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs index d7b6142b0c..f7489116cd 100644 --- a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs +++ b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs @@ -48,7 +48,13 @@ namespace BrewMonster UpdateGlobalDataForStreaming(); if (_needToProcessLoadAndUnload) { - ProcessLoadAndUnload(); + ProcessLoadAndUnload(() => + { + if (_hostPlayer != null) + { + _hostPlayer.isTerrainToReady = true; + } + }); _needToProcessLoadAndUnload = false; } } @@ -174,6 +180,11 @@ namespace BrewMonster } _needToProcessLoadAndUnload = true; + //if (_hostPlayer != null) + //{ + // Debug.LogError("ProcessLoadAndUnload Terain _hostPlayer.isTerrainToReady = false"); + // _hostPlayer.isTerrainToReady = false; + //} } } @@ -181,11 +192,22 @@ namespace BrewMonster /// /// process to call Load and Unload on each addressable object that we need to. /// - private void ProcessLoadAndUnload() + private void ProcessLoadAndUnload(Action actDone) { + int begin = 0; + int end = _candidatesForLoading.Count; + Action actLoadingDone = () => + { + begin++; + Debug.LogError("ProcessLoadAndUnload Terain || begin = " + begin + " || end = " + end); + if(begin >= end) + { + actDone?.Invoke(); + } + }; for (int i = 0; i < _candidatesForLoading.Count; i++) { - _candidatesForLoading[i].LoadAsset().Forget(); + _candidatesForLoading[i].LoadAsset(actLoadingDone).Forget(); } _candidatesForLoading.Clear(); diff --git a/Assets/Scripts/CECHostPlayer.World.cs b/Assets/Scripts/CECHostPlayer.World.cs index c7839afe91..ac98b65b39 100644 --- a/Assets/Scripts/CECHostPlayer.World.cs +++ b/Assets/Scripts/CECHostPlayer.World.cs @@ -230,6 +230,8 @@ namespace BrewMonster m_MoveCtrl.SetHostLastPos(EC_Utility.ToA3DVECTOR3(vPos)); m_MoveCtrl.SetLastSevPos(EC_Utility.ToA3DVECTOR3(vPos)); + isLitToReady = false; + isTerrainToReady = false; // Update camera if available // 如果可用则更新相机 // UpdateFollowCamera(false, 10); // Uncomment if UpdateFollowCamera method exists diff --git a/Assets/Scripts/CECHostPlayer.cs b/Assets/Scripts/CECHostPlayer.cs index af988a5e55..9f29163251 100644 --- a/Assets/Scripts/CECHostPlayer.cs +++ b/Assets/Scripts/CECHostPlayer.cs @@ -169,6 +169,8 @@ namespace BrewMonster Ray ray; RaycastHit[] hits = new RaycastHit[5]; bool isDataAwaitToReady = false; + public bool isTerrainToReady = false; + public bool isLitToReady = false; private BaseVfxObject m_pSelectedGFX; private BaseVfxObject m_pHoverGFX; @@ -395,7 +397,7 @@ namespace BrewMonster { base.Update(); - if (!isDataAwaitToReady) + if (!isDataAwaitToReady || !isTerrainToReady || !isLitToReady) { return; } From 21269c6cdf407a18fb6c770b826598baf5dfb9d1 Mon Sep 17 00:00:00 2001 From: Tungdv Date: Fri, 8 May 2026 11:04:46 +0700 Subject: [PATCH 2/3] fix: Update callback loading done assset, remove anonymous function. --- .../Scripts/World/LitModelHolder.cs | 40 +++++++++--------- .../Scripts/World/TerrainHolder.cs | 41 ++++++++++--------- 2 files changed, 41 insertions(+), 40 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs b/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs index b4e286ca33..5cfe319733 100644 --- a/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs +++ b/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs @@ -68,13 +68,7 @@ public class LitModelHolder : MonoSingleton // if load flag is set, process the load and unload objects. if (_needToProcessLoadAndUnload) { - ProcessLoadAndUnloadObjects(() => - { - if (_hostPlayer != null) - { - _hostPlayer.isLitToReady = true; - } - }); + ProcessLoadAndUnloadObjects(); _needToProcessLoadAndUnload = false; } } @@ -297,24 +291,17 @@ public class LitModelHolder : MonoSingleton // _hostPlayer.isLitToReady = false; //} } + int _currentIdxAsset = 0; + int _maxIdxAsset = 0; - private void ProcessLoadAndUnloadObjects(Action actDone) + private void ProcessLoadAndUnloadObjects() { - int begin = 0; - int end = _candidatesForLoading.Count; - Action actLoadingDone = () => - { - begin++; - Debug.LogError("ProcessLoadAndUnload Lit || begin = " + begin + " || end = " + end); - if (begin >= end) - { - actDone?.Invoke(); - } - }; + _currentIdxAsset = 0; + _maxIdxAsset = _candidatesForLoading.Count; // load the objects that are in the loading range long enough. (_candidateWaitTimeSeconds) foreach (var kvp in _candidatesForLoading) { - kvp.Key.LoadAsset(actLoadingDone).Forget(); + kvp.Key.LoadAsset(CallBackAssetLoadingDone).Forget(); _loadedObjects.Add(kvp.Key); } _candidatesForLoading.Clear(); @@ -330,6 +317,19 @@ public class LitModelHolder : MonoSingleton _objectsToUnload.Clear(); } + private void CallBackAssetLoadingDone() + { + _currentIdxAsset++; + if (_currentIdxAsset >= _maxIdxAsset) + { + if (_hostPlayer != null) + { + _hostPlayer.isLitToReady = true; + } + _currentIdxAsset = -1; + _maxIdxAsset = 0; + } + } /// /// Get the Host Player instance. /// diff --git a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs index f7489116cd..edc0a669a7 100644 --- a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs +++ b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs @@ -48,13 +48,7 @@ namespace BrewMonster UpdateGlobalDataForStreaming(); if (_needToProcessLoadAndUnload) { - ProcessLoadAndUnload(() => - { - if (_hostPlayer != null) - { - _hostPlayer.isTerrainToReady = true; - } - }); + ProcessLoadAndUnload(); _needToProcessLoadAndUnload = false; } } @@ -189,25 +183,18 @@ namespace BrewMonster } + int _currentIdxAsset = 0; + int _maxIdxAsset = 0; /// /// process to call Load and Unload on each addressable object that we need to. /// - private void ProcessLoadAndUnload(Action actDone) + private void ProcessLoadAndUnload() { - int begin = 0; - int end = _candidatesForLoading.Count; - Action actLoadingDone = () => - { - begin++; - Debug.LogError("ProcessLoadAndUnload Terain || begin = " + begin + " || end = " + end); - if(begin >= end) - { - actDone?.Invoke(); - } - }; + _currentIdxAsset = 0; + _maxIdxAsset = _candidatesForLoading.Count; for (int i = 0; i < _candidatesForLoading.Count; i++) { - _candidatesForLoading[i].LoadAsset(actLoadingDone).Forget(); + _candidatesForLoading[i].LoadAsset(CallBackAssetLoadingDone).Forget(); } _candidatesForLoading.Clear(); @@ -218,6 +205,20 @@ namespace BrewMonster _objectsToUnload.Clear(); } + private void CallBackAssetLoadingDone() + { + _currentIdxAsset++; + if (_currentIdxAsset >= _maxIdxAsset) + { + if (_hostPlayer != null) + { + _hostPlayer.isTerrainToReady = true; + } + _currentIdxAsset = -1; + _maxIdxAsset = 0; + } + } + /// /// Main-thread anchor for terrain streaming: host position, or navigate clone when force-navigate is active (same idea as LitModelHolder). /// 地形流式锚点:普通用宿主;强制导航用导航克隆(与 LitModelHolder 一致)。 From 9be9c28582e8f44b098da3f55f81980fb54f7581 Mon Sep 17 00:00:00 2001 From: Tungdv Date: Fri, 8 May 2026 11:20:02 +0700 Subject: [PATCH 3/3] fix: update summary for funtion loading asset. --- .../PerfectWorld/Scripts/World/LitModelHolder.cs | 16 +++++++++------- .../PerfectWorld/Scripts/World/TerrainHolder.cs | 10 ++++++++-- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs b/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs index 5cfe319733..70038d877f 100644 --- a/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs +++ b/Assets/PerfectWorld/Scripts/World/LitModelHolder.cs @@ -285,14 +285,7 @@ public class LitModelHolder : MonoSingleton } _needToProcessLoadAndUnload = true; - //if (_hostPlayer != null) - //{ - // Debug.LogError("ProcessLoadAndUnload Lit _hostPlayer.isLitToReady = false "); - // _hostPlayer.isLitToReady = false; - //} } - int _currentIdxAsset = 0; - int _maxIdxAsset = 0; private void ProcessLoadAndUnloadObjects() { @@ -317,6 +310,14 @@ public class LitModelHolder : MonoSingleton _objectsToUnload.Clear(); } + int _currentIdxAsset = 0; // The current counter for loaded assets. + int _maxIdxAsset = 0; // Limit the number of assets that have finished loading. + + /// + /// isLitToReady is a condition used by _hostPlayer to wait until the Lit assets have finished loading. + /// This function counts the number of assets successfully loaded from the Addressable system, + /// and once the required number is reached, it sets _hostPlayer.isLitToReady = true. + /// private void CallBackAssetLoadingDone() { _currentIdxAsset++; @@ -330,6 +331,7 @@ public class LitModelHolder : MonoSingleton _maxIdxAsset = 0; } } + /// /// Get the Host Player instance. /// diff --git a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs index edc0a669a7..8cfe0ed009 100644 --- a/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs +++ b/Assets/PerfectWorld/Scripts/World/TerrainHolder.cs @@ -183,8 +183,6 @@ namespace BrewMonster } - int _currentIdxAsset = 0; - int _maxIdxAsset = 0; /// /// process to call Load and Unload on each addressable object that we need to. /// @@ -205,6 +203,14 @@ namespace BrewMonster _objectsToUnload.Clear(); } + int _currentIdxAsset = 0; // The current counter for loaded assets. + int _maxIdxAsset = 0; // Limit the number of assets that have finished loading. + + /// + /// isLitToReady is a condition used by _hostPlayer to wait until the Terrain assets have finished loading. + /// This function counts the number of assets successfully loaded from the Addressable system, + /// and once the required number is reached, it sets _hostPlayer.isLitToReady = true. + /// private void CallBackAssetLoadingDone() { _currentIdxAsset++;