From 329da335d99bb4ac53a6b3f5cd303c4289b2cfa3 Mon Sep 17 00:00:00 2001 From: VuNgocHaiC7 Date: Thu, 23 Apr 2026 16:49:15 +0700 Subject: [PATCH] fix when click role char then appear model char of it --- Assets/Scripts/SelecScreenCharacter.cs | 37 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Assets/Scripts/SelecScreenCharacter.cs b/Assets/Scripts/SelecScreenCharacter.cs index a60a9368e1..63c187e318 100644 --- a/Assets/Scripts/SelecScreenCharacter.cs +++ b/Assets/Scripts/SelecScreenCharacter.cs @@ -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 _onCreateCharacterComplete; private List _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()