62 lines
1.5 KiB
C#
62 lines
1.5 KiB
C#
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
|
|
namespace DDD
|
|
{
|
|
public class UiManager : Singleton<UiManager>, IManager, IGameFlowHandler
|
|
{
|
|
[SerializeField] private AssetReference _popupUiState;
|
|
[SerializeField] private Transform _popupUiRoot;
|
|
|
|
public PopupUiState PopupUiState { get; private set; }
|
|
|
|
private void OnDestroy()
|
|
{
|
|
GameFlowManager.Instance?.FlowHandlers?.Remove(this);
|
|
}
|
|
|
|
public void PreInit()
|
|
{
|
|
GameFlowManager.Instance.FlowHandlers.Add(this);
|
|
|
|
foreach (Transform child in _popupUiRoot)
|
|
{
|
|
Destroy(child.gameObject);
|
|
}
|
|
}
|
|
|
|
public async Task Init()
|
|
{
|
|
await LoadData();
|
|
}
|
|
|
|
public void PostInit()
|
|
{
|
|
|
|
}
|
|
|
|
public Task OnReadyNewFlow(GameFlowState newFlowState)
|
|
{
|
|
PopupUiState.CreateMatchingPopupUis(newFlowState, _popupUiRoot);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public Task OnExitCurrentFlow(GameFlowState exitingFlowState)
|
|
{
|
|
PopupUiState.DestroyMatchingPopupUis(exitingFlowState);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private async Task LoadData()
|
|
{
|
|
var handle = _popupUiState.LoadAssetAsync<PopupUiState>();
|
|
await handle.Task;
|
|
PopupUiState = handle.Result;
|
|
|
|
Debug.Assert(PopupUiState != null, "PopupUiState is null");
|
|
|
|
PopupUiState.Initialize();
|
|
}
|
|
}
|
|
} |