fix when click role char then appear model char of it

This commit is contained in:
VuNgocHaiC7
2026-04-23 16:49:15 +07:00
parent 2d056ff40e
commit 329da335d9
+35 -2
View File
@@ -5,6 +5,7 @@ using BrewMonster.Scripts;
using UnityEngine;
using UnityEngine.UI;
using BrewMonster;
using System.Collections;
namespace BrewMonster.UI
{
@@ -25,6 +26,9 @@ namespace BrewMonster.UI
private Action<RoleInfo> _onCreateCharacterComplete;
private List<RoleInfo> _roleInfos;
private Coroutine _showModelReadyCoroutine;
private int _pendingShowModelRoleId = -1;
private void OnEnable()
{
_btnEnterGame.onClick.AddListener(OnClickedEnterGame);
@@ -149,8 +153,37 @@ namespace BrewMonster.UI
_selectingCharacterItemUI.SetFocus(true);
_btnEnterGame.gameObject.SetActive(true);
if (playerModelPreview != null && characterItemUI.RoleInfo != null)
playerModelPreview.ShowPlayerModel(characterItemUI.RoleInfo.roleid);
if (playerModelPreview == null || characterItemUI.RoleInfo == null)
{
return;
}
_pendingShowModelRoleId = characterItemUI.RoleInfo.roleid;
if (_showModelReadyCoroutine != null)
{
StopCoroutine(_showModelReadyCoroutine);
}
_showModelReadyCoroutine = StartCoroutine(ShowSelectedModelWhenReady(_pendingShowModelRoleId));
}
private IEnumerator ShowSelectedModelWhenReady(int roleId)
{
while (isActiveAndEnabled && playerModelPreview != null)
{
if (_pendingShowModelRoleId != roleId)
{
yield break; // Role changed, stop this coroutine
}
if (playerModelPreview.playerModelIds != null && playerModelPreview.playerModelIds.Contains(roleId))
{
playerModelPreview.ShowPlayerModel(roleId);
_showModelReadyCoroutine = null;
yield break; // Model is ready, show it and stop this coroutine
}
yield return null;
}
_showModelReadyCoroutine = null;
}
private void OnCreateCharacterClicked()