update logic select last role
This commit is contained in:
@@ -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