UI Started

This commit is contained in:
ThomasCharester committed 2026-01-21 10:58:05 +03:00
1 parent a3cd3e86a1
commit 12a27f85c5
26 files changed
+478 -24

No files matched your search

@@ -0,0 +1,70 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Code.Infrastructure.Configs;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
namespace Code.Infrastructure.UI
{
public interface IUIFactory
{
UniTaskVoid LoadPanel(UIPanelType panelType);
void ReleasePanel(UIPanel panel);
}
public class UIFactory : IDisposable, IUIFactory
{
private Dictionary<UIPanelType, UIPanelSettingsConfig> _configs;
private string _configsLabel;
private EventBus.EventBus _eventBus;
private AsyncOperationHandle<IList<UIPanelSettingsConfig>> _configsHandle;
public UIFactory(IConfigLocator configLocator, EventBus.EventBus eventBus)
{
_eventBus = eventBus;
_configsLabel = configLocator.TryGetManyConfigAssetReferences<UIPanelSettingsConfig>();
LoadConfigs().Forget();
}
public async UniTaskVoid LoadPanel(UIPanelType panelType)
{
var panel = (await Addressables.InstantiateAsync(_configs[panelType]).ToUniTask()).GetComponent<UIPanel>();
_eventBus.RaiseEvent<IUIPanelLoadedHandle>(ui => ui.UIPanelLoaded(panel, panelType));
}
public void ReleasePanel(UIPanel panel)
{
Addressables.ReleaseInstance(panel.gameObject);
}
private async UniTaskVoid LoadConfigs()
{
_configsHandle = Addressables.LoadAssetsAsync<UIPanelSettingsConfig>(_configsLabel);
await _configsHandle.ToUniTask();
_configs = _configsHandle.Result.ToDictionary(c => c.UIPanelType);
_eventBus.RaiseEvent<IUIInitializedHandle>(ui => ui.UIInitialized());
}
public void Dispose()
{
Addressables.Release(_configsHandle);
}
}
public interface IUIInitializedHandle : IGlobalSubscriber
{
void UIInitialized();
}
public interface IUIPanelLoadedHandle : IGlobalSubscriber
{
void UIPanelLoaded(UIPanel panel, UIPanelType panelType);
}
}