44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System;
|
|
using System.Threading;
|
|
using Code.UI.Panels;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using Object = UnityEngine.Object;
|
|
|
|
namespace Code.UI
|
|
{
|
|
public class UIService : IUIService
|
|
{
|
|
private Canvas _canvas;
|
|
private IUIFactory _factory;
|
|
|
|
public UIElement CurrentPanel { get; private set; }
|
|
|
|
public LoadingScreen LoadingScreen { get; private set; }
|
|
|
|
public UIService(IUIFactory factory)
|
|
{
|
|
_factory = factory;
|
|
}
|
|
|
|
public async void Initialize(LoadingScreen loadingScreen)
|
|
{
|
|
LoadingScreen = loadingScreen;
|
|
LoadingScreen.Show();
|
|
|
|
_canvas = await _factory.CreateCanvas();
|
|
}
|
|
|
|
public async void SwitchPanelTo(UIPanel uiPanel, Action callback = null)
|
|
{
|
|
if (!_canvas) await UniTask.WaitUntil(() => _canvas );
|
|
|
|
if(CurrentPanel) Addressables.ReleaseInstance(CurrentPanel.gameObject);//Object.Destroy(CurrentPanel.gameObject);
|
|
|
|
CurrentPanel = await _factory.CreatePanel(_canvas, uiPanel);
|
|
|
|
callback?.Invoke();
|
|
}
|
|
}
|
|
} |