Merge pull request 'fix move when load terrain and lit resource' (#416) from feature/HP_move_when_load_terrain_lit into develop
Reviewed-on: https://git.pthub.vn/Unity/perfect-world-unity/pulls/416 Reviewed-by: anhld <ptitducanh@gmail.com>
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@@ -288,10 +289,12 @@ public class LitModelHolder : MonoSingleton<LitModelHolder>
|
||||
|
||||
private void ProcessLoadAndUnloadObjects()
|
||||
{
|
||||
_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().Forget();
|
||||
kvp.Key.LoadAsset(CallBackAssetLoadingDone).Forget();
|
||||
_loadedObjects.Add(kvp.Key);
|
||||
}
|
||||
_candidatesForLoading.Clear();
|
||||
@@ -307,6 +310,28 @@ public class LitModelHolder : MonoSingleton<LitModelHolder>
|
||||
_objectsToUnload.Clear();
|
||||
}
|
||||
|
||||
int _currentIdxAsset = 0; // The current counter for loaded assets.
|
||||
int _maxIdxAsset = 0; // Limit the number of assets that have finished loading.
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
private void CallBackAssetLoadingDone()
|
||||
{
|
||||
_currentIdxAsset++;
|
||||
if (_currentIdxAsset >= _maxIdxAsset)
|
||||
{
|
||||
if (_hostPlayer != null)
|
||||
{
|
||||
_hostPlayer.isLitToReady = true;
|
||||
}
|
||||
_currentIdxAsset = -1;
|
||||
_maxIdxAsset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the Host Player instance.
|
||||
/// </summary>
|
||||
@@ -444,4 +469,4 @@ public class LitModelHolder : MonoSingleton<LitModelHolder>
|
||||
$"- anchorsWithMoreThanOneChild={multiChildCount}");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +174,11 @@ namespace BrewMonster
|
||||
}
|
||||
|
||||
_needToProcessLoadAndUnload = true;
|
||||
//if (_hostPlayer != null)
|
||||
//{
|
||||
// Debug.LogError("ProcessLoadAndUnload Terain _hostPlayer.isTerrainToReady = false");
|
||||
// _hostPlayer.isTerrainToReady = false;
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -183,9 +188,11 @@ namespace BrewMonster
|
||||
/// </summary>
|
||||
private void ProcessLoadAndUnload()
|
||||
{
|
||||
_currentIdxAsset = 0;
|
||||
_maxIdxAsset = _candidatesForLoading.Count;
|
||||
for (int i = 0; i < _candidatesForLoading.Count; i++)
|
||||
{
|
||||
_candidatesForLoading[i].LoadAsset().Forget();
|
||||
_candidatesForLoading[i].LoadAsset(CallBackAssetLoadingDone).Forget();
|
||||
}
|
||||
_candidatesForLoading.Clear();
|
||||
|
||||
@@ -196,6 +203,28 @@ 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.
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
private void CallBackAssetLoadingDone()
|
||||
{
|
||||
_currentIdxAsset++;
|
||||
if (_currentIdxAsset >= _maxIdxAsset)
|
||||
{
|
||||
if (_hostPlayer != null)
|
||||
{
|
||||
_hostPlayer.isTerrainToReady = true;
|
||||
}
|
||||
_currentIdxAsset = -1;
|
||||
_maxIdxAsset = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Main-thread anchor for terrain streaming: host position, or navigate clone when force-navigate is active (same idea as LitModelHolder).
|
||||
/// 地形流式锚点:普通用宿主;强制导航用导航克隆(与 LitModelHolder 一致)。
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user