update logic select last role

This commit is contained in:
NguyenVanDat
2026-05-26 10:39:47 +07:00
parent fa322512db
commit df3f4c2839
4 changed files with 41 additions and 12 deletions
@@ -111,7 +111,7 @@ namespace BrewMonster.Scripts
/// Loads one preview instance per role (via <see cref="NPCManager.GetModelPlayer"/>). /// Loads one preview instance per role (via <see cref="NPCManager.GetModelPlayer"/>).
/// All instances stay hidden until <see cref="ShowPlayerModel"/> is called. /// All instances stay hidden until <see cref="ShowPlayerModel"/> is called.
/// </summary> /// </summary>
public async void ShowAllPlayerModels(List<RoleInfo> roleInfos) public async UniTask<bool> ShowAllPlayerModels(List<RoleInfo> roleInfos)
{ {
BMLogger.Log($"ShowAllPlayerModels: {roleInfos.Count}"); BMLogger.Log($"ShowAllPlayerModels: {roleInfos.Count}");
_loadVersion++; _loadVersion++;
@@ -121,7 +121,7 @@ namespace BrewMonster.Scripts
{ {
ClearModels(); ClearModels();
_suppressHierarchyWatch = false; _suppressHierarchyWatch = false;
return; return false;
} }
List<GameObject> oldModels = new List<GameObject>(playerModels); List<GameObject> oldModels = new List<GameObject>(playerModels);
@@ -139,7 +139,7 @@ namespace BrewMonster.Scripts
if (version != _loadVersion) if (version != _loadVersion)
{ {
Destroy(model); Destroy(model);
return; return false;
} }
model.transform.SetParent(modelRoot, false); model.transform.SetParent(modelRoot, false);
@@ -164,6 +164,7 @@ namespace BrewMonster.Scripts
_suppressHierarchyWatch = false; _suppressHierarchyWatch = false;
if (_inventoryPreviewActive) if (_inventoryPreviewActive)
SyncHierarchyBaseline(); SyncHierarchyBaseline();
return true;
} }
/// <summary> /// <summary>
@@ -431,7 +432,7 @@ namespace BrewMonster.Scripts
_lastPreviewRoleInfo = roleInfo; _lastPreviewRoleInfo = roleInfo;
_suppressHierarchyWatch = true; _suppressHierarchyWatch = true;
ShowAllPlayerModels(new List<RoleInfo> { roleInfo }); ShowAllPlayerModels(new List<RoleInfo> { roleInfo }).Forget();
ShowPlayerModel(roleInfo.roleid); ShowPlayerModel(roleInfo.roleid);
} }
@@ -11,6 +11,7 @@ using UnityEngine.UI;
using BrewMonster.Scripts; using BrewMonster.Scripts;
using BrewMonster.PerfectWorld.Scripts.Utility.ChatFilter; using BrewMonster.PerfectWorld.Scripts.Utility.ChatFilter;
using System.Collections.Generic; using System.Collections.Generic;
using Cysharp.Threading.Tasks;
namespace BrewMonster.UI namespace BrewMonster.UI
{ {
@@ -402,7 +403,7 @@ namespace BrewMonster.UI
} }
} }
PlayerModelPreview.Instance.ShowAllPlayerModels(_roleInfos); PlayerModelPreview.Instance.ShowAllPlayerModels(_roleInfos).Forget();
} }
private void LoadShowModel(int prof, int gender) private void LoadShowModel(int prof, int gender)
+7 -2
View File
@@ -19,7 +19,8 @@ public class CharacterItemUI : MonoBehaviour
private void OnEnable() private void OnEnable()
{ {
_goFocusImage.SetActive(false); if(_goFocusImage!=null)
_goFocusImage.SetActive(false);
} }
// Start is called once before the first execution of Update after the MonoBehaviour is created // Start is called once before the first execution of Update after the MonoBehaviour is created
@@ -53,7 +54,11 @@ public class CharacterItemUI : MonoBehaviour
} }
} }
public void OnClickBtn() private void OnClickBtn()
{
onClick?.Invoke(this);
}
public void ForceClickBtn()
{ {
onClick?.Invoke(this); onClick?.Invoke(this);
} }
+26 -4
View File
@@ -6,6 +6,7 @@ using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using BrewMonster; using BrewMonster;
using System.Collections; using System.Collections;
using Cysharp.Threading.Tasks;
namespace BrewMonster.UI namespace BrewMonster.UI
{ {
@@ -26,6 +27,7 @@ namespace BrewMonster.UI
private Action<RoleInfo> _onCreateCharacterComplete; private Action<RoleInfo> _onCreateCharacterComplete;
private Action _onExit; private Action _onExit;
private List<RoleInfo> _roleInfos; private List<RoleInfo> _roleInfos;
private List<CharacterItemUI> _characterItems = new List<CharacterItemUI>();
private Coroutine _showModelReadyCoroutine; private Coroutine _showModelReadyCoroutine;
private int _pendingShowModelRoleId = -1; private int _pendingShowModelRoleId = -1;
@@ -42,7 +44,7 @@ namespace BrewMonster.UI
if (_roleInfos != null && _roleInfos.Count > 0) if (_roleInfos != null && _roleInfos.Count > 0)
{ {
PlayerModelPreview.Instance?.ShowAllPlayerModels(_roleInfos); PlayerModelPreview.Instance?.ShowAllPlayerModels(_roleInfos).Forget();
} }
else else
{ {
@@ -71,11 +73,12 @@ namespace BrewMonster.UI
} }
} }
public void InitScreen(List<RoleInfo> roleInfos, Action<RoleInfo> OnClickItemChar, Action<RoleInfo> onCreateCharacterComplete = null, Action onExit = null) public async UniTask<bool> InitScreen(List<RoleInfo> roleInfos, Action<RoleInfo> OnClickItemChar, Action<RoleInfo> onCreateCharacterComplete = null, Action onExit = null)
{ {
_onClickItemChar = OnClickItemChar; _onClickItemChar = OnClickItemChar;
_onCreateCharacterComplete = onCreateCharacterComplete; _onCreateCharacterComplete = onCreateCharacterComplete;
_onExit = onExit; _onExit = onExit;
_characterItems.Clear();
// Clear existing items // Clear existing items
if (parentItems != null) if (parentItems != null)
@@ -91,14 +94,24 @@ namespace BrewMonster.UI
// Create character items // Create character items
if (roleInfos != null) if (roleInfos != null)
{ {
RoleInfo lastRoleInfo = null;
int lastTimeLogin = int.MinValue;
foreach (RoleInfo info in roleInfos) foreach (RoleInfo info in roleInfos)
{ {
if (characterItemPrefab != null && parentItems != null) if (characterItemPrefab != null && parentItems != null)
{ {
CharacterItemUI item = Instantiate(characterItemPrefab, parentItems).GetComponent<CharacterItemUI>(); CharacterItemUI item = Instantiate(characterItemPrefab, parentItems).GetComponent<CharacterItemUI>();
item.InitItem(info, OnSelectCharacter); item.InitItem(info, OnSelectCharacter);
_characterItems.Add(item);
if (info.lastlogin_time > lastTimeLogin)
{
lastTimeLogin = info.lastlogin_time;
_selectingCharacterItemUI = item;
}
} }
} }
_selectingCharacterItemUI.ForceClickBtn();
_selectingCharacterItemUI.SetFocus(true);
// If number of roles < 8, spawn addCharacterItemPrefab and hide createCharacterButton // If number of roles < 8, spawn addCharacterItemPrefab and hide createCharacterButton
if (roleInfos.Count < 8) if (roleInfos.Count < 8)
@@ -137,18 +150,27 @@ namespace BrewMonster.UI
} }
// Load player preview 3D models // Load player preview 3D models
PlayerModelPreview.Instance?.ShowAllPlayerModels(roleInfos); if (PlayerModelPreview.Instance != null)
{
var success = await PlayerModelPreview.Instance.ShowAllPlayerModels(roleInfos);
if (success)
{
_selectingCharacterItemUI.ForceClickBtn();
_selectingCharacterItemUI.SetFocus(true);
}
}
} }
else else
{ {
if (PlayerModelPreview.Instance != null) if (PlayerModelPreview.Instance != null)
PlayerModelPreview.Instance.ShowAllPlayerModels(null); _ = await PlayerModelPreview.Instance.ShowAllPlayerModels(null);
// If roleInfos is null, show createCharacterButton // If roleInfos is null, show createCharacterButton
if (createCharacterButton != null) if (createCharacterButton != null)
{ {
createCharacterButton.gameObject.SetActive(true); createCharacterButton.gameObject.SetActive(true);
} }
} }
return true;
} }
private void OnSelectCharacter(CharacterItemUI characterItemUI) private void OnSelectCharacter(CharacterItemUI characterItemUI)