UI service frame
This commit is contained in:
1 parent
12a27f85c5
commit
e2d0974b3c
45 files changed
+1138
-927
No files matched your search
@@ -2,7 +2,8 @@ using Code.Infrastructure.Camera;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.Input;
|
||||
using Code.Infrastructure.Loadings;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Code.Infrastructure.UI;
|
||||
using Reflex.Core;
|
||||
using Reflex.Enums;
|
||||
using UnityEngine;
|
||||
@@ -10,7 +11,12 @@ using Resolution = Reflex.Enums.Resolution;
|
||||
|
||||
namespace Code.Infrastructure.App
|
||||
{
|
||||
public class PapaInstaller : MonoBehaviour, IInstaller, ISceneConfigsLoadedHandle, IInputServiceInitializedHandle, ICameraInitializedHandle
|
||||
public class PapaInstaller : MonoBehaviour, IInstaller,
|
||||
ISceneConfigsLoadedHandle,
|
||||
IInputServiceInitializedHandle,
|
||||
ICameraInitializedHandle,
|
||||
IUIInitializedHandle,
|
||||
IUIPanelLoaded
|
||||
{
|
||||
public void InstallBindings(ContainerBuilder containerBuilder)
|
||||
{
|
||||
@@ -27,7 +33,16 @@ namespace Code.Infrastructure.App
|
||||
containerBuilder.RegisterType(typeof(CameraFactory), Lifetime.Singleton, Resolution.Lazy);
|
||||
containerBuilder.RegisterType(typeof(CameraStateMachine), Lifetime.Singleton, Resolution.Lazy);
|
||||
containerBuilder.RegisterType(typeof(CameraStateMachineContext), Lifetime.Singleton, Resolution.Lazy);
|
||||
|
||||
|
||||
containerBuilder.RegisterType(typeof(UIFactory), new []{typeof(IUIFactory)}, Lifetime.Singleton, Resolution.Eager);
|
||||
containerBuilder.RegisterType(typeof(UIService), new []{typeof(IUIService)}, Lifetime.Singleton, Resolution.Eager);
|
||||
|
||||
// UIFactory
|
||||
// Logo
|
||||
// Scene configs
|
||||
// Input service
|
||||
// Camera
|
||||
_initialLoading = new Loading(5, () => EssentialLoadEnded(_thatRightContainer));
|
||||
}
|
||||
|
||||
private Loading _initialLoading;
|
||||
@@ -40,13 +55,12 @@ namespace Code.Infrastructure.App
|
||||
|
||||
container.Resolve<CameraFactory>().CreateCameraStateMachine(container.Resolve<CameraStateMachine>()).Forget();
|
||||
|
||||
_initialLoading = new Loading(3, () => EssentialLoadEnded(container));
|
||||
}
|
||||
|
||||
private void EssentialLoadEnded(Container container)
|
||||
{
|
||||
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap).AllowStateTransition(AppStates.Gameplay);
|
||||
container.Resolve<EventBus.EventBus>().Unsubscribe(this);
|
||||
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap).AllowStateTransition(AppStates.Gameplay);
|
||||
}
|
||||
|
||||
public void SceneConfigsLoaded()
|
||||
@@ -64,7 +78,33 @@ namespace Code.Infrastructure.App
|
||||
_thatRightContainer.Resolve<CameraStateMachineContext>().cameraLoadedData = data;
|
||||
_thatRightContainer.Resolve<CameraStateMachine>().SwitchState(CameraMode.None)
|
||||
.AllowStateTransition(CameraMode.FirstPerson);
|
||||
|
||||
_initialLoading.DoProgress();
|
||||
}
|
||||
|
||||
public void UIInitialized()
|
||||
{
|
||||
_initialLoading.DoProgress();
|
||||
|
||||
_thatRightContainer.Resolve<IUIService>().TryLoadPanel(UIPanelType.Logo);
|
||||
_thatRightContainer.Resolve<IUIService>().TryLoadPanel(UIPanelType.Loading);
|
||||
}
|
||||
|
||||
public void UILoaded(UIPanelType uiPanelType)
|
||||
{
|
||||
if (_initialLoading.Completed) return;
|
||||
|
||||
switch (uiPanelType)
|
||||
{
|
||||
case UIPanelType.Logo:
|
||||
_thatRightContainer.Resolve<IUIService>().OpenPanel(UIPanelType.Logo);
|
||||
|
||||
_initialLoading.DoProgress();
|
||||
break;
|
||||
case UIPanelType.Loading:
|
||||
// _thatRightContainer.Resolve<IUIService>().OpenPanel(UIPanelType.Logo);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace Code.Infrastructure.App.States
|
||||
|
||||
public void OnGameplaySceneLoaded()
|
||||
{
|
||||
Debug.Log("Spermageddon");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ namespace Code.Infrastructure.App.States
|
||||
|
||||
public void OnGameplaySceneLoaded()
|
||||
{
|
||||
Debug.Log("Spermageddon");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Code.Infrastructure.Loadings
|
||||
public class Loading
|
||||
{
|
||||
private int _progress;
|
||||
public bool Completed { get; private set; }
|
||||
private Action _completed;
|
||||
private Action<Loading> _loadProgress;
|
||||
|
||||
@@ -23,7 +24,12 @@ namespace Code.Infrastructure.Loadings
|
||||
{
|
||||
_progress--;
|
||||
_loadProgress?.Invoke(this);
|
||||
if(_progress <= 0) _completed();
|
||||
|
||||
if(_progress <= 0) // Зачем инвертировать, если так читается лучше, райдер соси
|
||||
{
|
||||
Completed = true;
|
||||
_completed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b66d89a2d3ef45eab0c8a5571e1517b0
|
||||
timeCreated: 1768984741
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
public class LoadingPanel : UIPanel
|
||||
{
|
||||
public override void Open()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a950957bc3374bb8b1c3acfbb7ad2dd2
|
||||
timeCreated: 1768984735
|
||||
@@ -0,0 +1,16 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Infrastructure.UI.Panels
|
||||
{
|
||||
public class LogoPanel : UIPanel
|
||||
{
|
||||
public override void Open()
|
||||
{
|
||||
Debug.Log("Logo panel opened");
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4adfc2a9c5ae4354a32b651c09840b40
|
||||
timeCreated: 1768984716
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
@@ -18,22 +19,27 @@ namespace Code.Infrastructure.UI
|
||||
public class UIFactory : IDisposable, IUIFactory
|
||||
{
|
||||
private Dictionary<UIPanelType, UIPanelSettingsConfig> _configs;
|
||||
private AssetReference _canvasConfigReference;
|
||||
private string _configsLabel;
|
||||
private EventBus.EventBus _eventBus;
|
||||
|
||||
private AsyncOperationHandle<IList<UIPanelSettingsConfig>> _configsHandle;
|
||||
private AsyncOperationHandle<CanvasSettingsConfig> _canvasSettingsHandle;
|
||||
private CanvasSettingsConfig _canvasConfig;
|
||||
private GameObject _canvas;
|
||||
|
||||
public UIFactory(IConfigLocator configLocator, EventBus.EventBus eventBus)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
_configsLabel = configLocator.TryGetManyConfigAssetReferences<UIPanelSettingsConfig>();
|
||||
_canvasConfigReference = configLocator.TryGetConfigAssetReference<CanvasSettingsConfig>();
|
||||
|
||||
LoadConfigs().Forget();
|
||||
}
|
||||
|
||||
public async UniTaskVoid LoadPanel(UIPanelType panelType)
|
||||
{
|
||||
var panel = (await Addressables.InstantiateAsync(_configs[panelType]).ToUniTask()).GetComponent<UIPanel>();
|
||||
var panel = (await Addressables.InstantiateAsync(_configs[panelType].Prefab, _canvas.transform).ToUniTask()).GetComponent<UIPanel>();
|
||||
|
||||
_eventBus.RaiseEvent<IUIPanelLoadedHandle>(ui => ui.UIPanelLoaded(panel, panelType));
|
||||
}
|
||||
@@ -46,16 +52,25 @@ namespace Code.Infrastructure.UI
|
||||
private async UniTaskVoid LoadConfigs()
|
||||
{
|
||||
_configsHandle = Addressables.LoadAssetsAsync<UIPanelSettingsConfig>(_configsLabel);
|
||||
_canvasSettingsHandle = Addressables.LoadAssetAsync<CanvasSettingsConfig>(_canvasConfigReference);
|
||||
|
||||
await _configsHandle.ToUniTask();
|
||||
await _canvasSettingsHandle.ToUniTask();
|
||||
|
||||
_canvasConfig = _canvasSettingsHandle.Result;
|
||||
|
||||
_configs = _configsHandle.Result.ToDictionary(c => c.UIPanelType);
|
||||
|
||||
_canvas = await Addressables.InstantiateAsync(_canvasConfig.Prefab).ToUniTask();
|
||||
UnityEngine.Object.DontDestroyOnLoad(_canvas);
|
||||
|
||||
_eventBus.RaiseEvent<IUIInitializedHandle>(ui => ui.UIInitialized());
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
Addressables.Release(_configsHandle);
|
||||
Addressables.Release(_canvasSettingsHandle);
|
||||
Addressables.ReleaseInstance(_canvas);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,4 +9,10 @@ namespace Code.Infrastructure.UI
|
||||
[ToConfig] public AssetReference Prefab;
|
||||
[ToConfig] public UIPanelType UIPanelType;
|
||||
}
|
||||
|
||||
[Config("Configs/UI/CanvasSettings")]
|
||||
public class CanvasSettings
|
||||
{
|
||||
[ToConfig] public AssetReference Prefab;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Reflex.Core;
|
||||
using Reflex.Extensions;
|
||||
using Reflex.Injectors;
|
||||
@@ -49,11 +51,13 @@ namespace Code.Infrastructure.UI
|
||||
if(panel.InjectMeSenpai)
|
||||
GameObjectInjector.InjectRecursive(panel.gameObject, Container.RootContainer);
|
||||
// GameObjectInjector.InjectRecursive(panel.gameObject, SceneManager.GetActiveScene().GetSceneContainer()); // Скорее всего будут нужны компоненты текущей сцены
|
||||
|
||||
_eventBus.RaiseEvent<IUIPanelLoaded>(ui=> ui.UILoaded(panelType));
|
||||
}
|
||||
|
||||
public void TryRemovePanel(UIPanelType panelType)
|
||||
{
|
||||
//
|
||||
// TODO Close it
|
||||
RemovePanel(panelType);
|
||||
}
|
||||
|
||||
@@ -63,4 +67,8 @@ namespace Code.Infrastructure.UI
|
||||
_loadedPanels.Remove(panelType);
|
||||
}
|
||||
}
|
||||
public interface IUIPanelLoaded : IGlobalSubscriber
|
||||
{
|
||||
void UILoaded(UIPanelType uiPanelType);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user