update logic select last role
This commit is contained in:
@@ -111,7 +111,7 @@ namespace BrewMonster.Scripts
|
||||
/// Loads one preview instance per role (via <see cref="NPCManager.GetModelPlayer"/>).
|
||||
/// All instances stay hidden until <see cref="ShowPlayerModel"/> is called.
|
||||
/// </summary>
|
||||
public async void ShowAllPlayerModels(List<RoleInfo> roleInfos)
|
||||
public async UniTask<bool> ShowAllPlayerModels(List<RoleInfo> roleInfos)
|
||||
{
|
||||
BMLogger.Log($"ShowAllPlayerModels: {roleInfos.Count}");
|
||||
_loadVersion++;
|
||||
@@ -121,7 +121,7 @@ namespace BrewMonster.Scripts
|
||||
{
|
||||
ClearModels();
|
||||
_suppressHierarchyWatch = false;
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
List<GameObject> oldModels = new List<GameObject>(playerModels);
|
||||
@@ -139,7 +139,7 @@ namespace BrewMonster.Scripts
|
||||
if (version != _loadVersion)
|
||||
{
|
||||
Destroy(model);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
model.transform.SetParent(modelRoot, false);
|
||||
@@ -164,6 +164,7 @@ namespace BrewMonster.Scripts
|
||||
_suppressHierarchyWatch = false;
|
||||
if (_inventoryPreviewActive)
|
||||
SyncHierarchyBaseline();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -431,7 +432,7 @@ namespace BrewMonster.Scripts
|
||||
|
||||
_lastPreviewRoleInfo = roleInfo;
|
||||
_suppressHierarchyWatch = true;
|
||||
ShowAllPlayerModels(new List<RoleInfo> { roleInfo });
|
||||
ShowAllPlayerModels(new List<RoleInfo> { roleInfo }).Forget();
|
||||
ShowPlayerModel(roleInfo.roleid);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ using UnityEngine.UI;
|
||||
using BrewMonster.Scripts;
|
||||
using BrewMonster.PerfectWorld.Scripts.Utility.ChatFilter;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace BrewMonster.UI
|
||||
{
|
||||
@@ -106,7 +107,7 @@ namespace BrewMonster.UI
|
||||
ClearValidationError();
|
||||
|
||||
UpdateConfirmButtonState();
|
||||
|
||||
|
||||
SetupRoleInfos();
|
||||
}
|
||||
|
||||
@@ -402,7 +403,7 @@ namespace BrewMonster.UI
|
||||
}
|
||||
}
|
||||
|
||||
PlayerModelPreview.Instance.ShowAllPlayerModels(_roleInfos);
|
||||
PlayerModelPreview.Instance.ShowAllPlayerModels(_roleInfos).Forget();
|
||||
}
|
||||
|
||||
private void LoadShowModel(int prof, int gender)
|
||||
|
||||
@@ -19,7 +19,8 @@ public class CharacterItemUI : MonoBehaviour
|
||||
|
||||
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
|
||||
@@ -53,7 +54,11 @@ public class CharacterItemUI : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void OnClickBtn()
|
||||
private void OnClickBtn()
|
||||
{
|
||||
onClick?.Invoke(this);
|
||||
}
|
||||
public void ForceClickBtn()
|
||||
{
|
||||
onClick?.Invoke(this);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using BrewMonster;
|
||||
using System.Collections;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace BrewMonster.UI
|
||||
{
|
||||
@@ -26,6 +27,7 @@ namespace BrewMonster.UI
|
||||
private Action<RoleInfo> _onCreateCharacterComplete;
|
||||
private Action _onExit;
|
||||
private List<RoleInfo> _roleInfos;
|
||||
private List<CharacterItemUI> _characterItems = new List<CharacterItemUI>();
|
||||
|
||||
private Coroutine _showModelReadyCoroutine;
|
||||
private int _pendingShowModelRoleId = -1;
|
||||
@@ -42,7 +44,7 @@ namespace BrewMonster.UI
|
||||
|
||||
if (_roleInfos != null && _roleInfos.Count > 0)
|
||||
{
|
||||
PlayerModelPreview.Instance?.ShowAllPlayerModels(_roleInfos);
|
||||
PlayerModelPreview.Instance?.ShowAllPlayerModels(_roleInfos).Forget();
|
||||
}
|
||||
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;
|
||||
_onCreateCharacterComplete = onCreateCharacterComplete;
|
||||
_onExit = onExit;
|
||||
_characterItems.Clear();
|
||||
|
||||
// Clear existing items
|
||||
if (parentItems != null)
|
||||
@@ -91,14 +94,24 @@ namespace BrewMonster.UI
|
||||
// Create character items
|
||||
if (roleInfos != null)
|
||||
{
|
||||
RoleInfo lastRoleInfo = null;
|
||||
int lastTimeLogin = int.MinValue;
|
||||
foreach (RoleInfo info in roleInfos)
|
||||
{
|
||||
if (characterItemPrefab != null && parentItems != null)
|
||||
{
|
||||
CharacterItemUI item = Instantiate(characterItemPrefab, parentItems).GetComponent<CharacterItemUI>();
|
||||
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 (roleInfos.Count < 8)
|
||||
@@ -137,18 +150,27 @@ namespace BrewMonster.UI
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
if (PlayerModelPreview.Instance != null)
|
||||
PlayerModelPreview.Instance.ShowAllPlayerModels(null);
|
||||
_ = await PlayerModelPreview.Instance.ShowAllPlayerModels(null);
|
||||
// If roleInfos is null, show createCharacterButton
|
||||
if (createCharacterButton != null)
|
||||
{
|
||||
createCharacterButton.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnSelectCharacter(CharacterItemUI characterItemUI)
|
||||
|
||||
Reference in New Issue
Block a user