ProjectDDD/Assets/_DDD/_Scripts/GameUi/UiManager.cs

62 lines
1.5 KiB
C#
Raw Normal View History

2025-07-21 07:53:39 +00:00
using System.Threading.Tasks;
2025-08-18 04:26:18 +00:00
using UnityEngine;
using UnityEngine.AddressableAssets;
2025-07-21 07:53:39 +00:00
namespace DDD
{
2025-08-18 04:26:18 +00:00
public class UiManager : Singleton<UiManager>, IManager, IGameFlowHandler
2025-07-21 07:53:39 +00:00
{
2025-08-18 04:26:18 +00:00
[SerializeField] private AssetReference _popupUiState;
[SerializeField] private Transform _popupUiRoot;
2025-07-21 07:53:39 +00:00
2025-08-18 04:26:18 +00:00
public PopupUiState PopupUiState { get; private set; }
2025-07-21 07:53:39 +00:00
private void OnDestroy()
{
2025-08-18 04:26:18 +00:00
GameFlowManager.Instance?.FlowHandlers?.Remove(this);
2025-07-21 07:53:39 +00:00
}
2025-08-18 04:26:18 +00:00
public void PreInit()
2025-07-21 07:53:39 +00:00
{
2025-08-18 04:26:18 +00:00
GameFlowManager.Instance.FlowHandlers.Add(this);
2025-07-21 07:53:39 +00:00
2025-08-18 04:26:18 +00:00
foreach (Transform child in _popupUiRoot)
2025-07-21 07:53:39 +00:00
{
2025-08-18 04:26:18 +00:00
Destroy(child.gameObject);
2025-07-21 07:53:39 +00:00
}
}
2025-08-18 04:26:18 +00:00
public async Task Init()
2025-07-21 07:53:39 +00:00
{
2025-08-18 04:26:18 +00:00
await LoadData();
2025-07-21 07:53:39 +00:00
}
2025-08-18 04:26:18 +00:00
public void PostInit()
2025-07-21 07:53:39 +00:00
{
2025-07-22 07:46:37 +00:00
}
2025-08-18 04:26:18 +00:00
public Task OnReadyNewFlow(GameFlowState newFlowState)
2025-07-22 07:46:37 +00:00
{
2025-08-18 04:26:18 +00:00
PopupUiState.CreateMatchingPopupUis(newFlowState, _popupUiRoot);
return Task.CompletedTask;
2025-07-22 07:46:37 +00:00
}
2025-08-05 05:14:39 +00:00
2025-08-18 04:26:18 +00:00
public Task OnExitCurrentFlow(GameFlowState exitingFlowState)
2025-07-22 07:46:37 +00:00
{
2025-08-18 04:26:18 +00:00
PopupUiState.DestroyMatchingPopupUis(exitingFlowState);
return Task.CompletedTask;
2025-08-05 05:14:39 +00:00
}
2025-08-18 04:26:18 +00:00
private async Task LoadData()
2025-08-05 05:14:39 +00:00
{
2025-08-18 04:26:18 +00:00
var handle = _popupUiState.LoadAssetAsync<PopupUiState>();
await handle.Task;
PopupUiState = handle.Result;
2025-08-05 05:14:39 +00:00
2025-08-18 04:26:18 +00:00
Debug.Assert(PopupUiState != null, "PopupUiState is null");
PopupUiState.Initialize();
2025-07-21 07:53:39 +00:00
}
}
}