From 5581c616c17fd910a6f9b24b1ee328708fe45239 Mon Sep 17 00:00:00 2001 From: Tungdv Date: Thu, 7 May 2026 17:58:42 +0700 Subject: [PATCH] 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; }