UI Update, volumes

This commit is contained in:
ThomasCharester committed 2026-01-23 20:39:55 +03:00
1 parent e2d0974b3c
commit 0f0c8bab43
100 files changed
+10862 -734

No files matched your search

+83 -32
View File
@@ -1,75 +1,101 @@
using System;
using Code.Infrastructure.Camera;
using Code.Infrastructure.Configs;
using Code.Infrastructure.Input;
using Code.Infrastructure.Loadings;
using Code.Infrastructure.SceneLoader;
using Code.Infrastructure.UI;
using Code.Infrastructure.Volume;
using Reflex.Core;
using Reflex.Enums;
using UnityEngine;
using UnityEngine.Rendering.Universal;
using Resolution = Reflex.Enums.Resolution;
namespace Code.Infrastructure.App
{
public class PapaInstaller : MonoBehaviour, IInstaller,
public class PapaInstaller : MonoBehaviour, IInstaller,
ISceneConfigsLoadedHandle,
IInputServiceInitializedHandle,
ICameraInitializedHandle,
IUIInitializedHandle,
IUIPanelLoaded
IUIPanelLoaded,
IVolumesInitializedHandle,
IVolumeLoaded
{
public void InstallBindings(ContainerBuilder containerBuilder)
{
containerBuilder.RegisterType(typeof(EventBus.EventBus), Lifetime.Singleton, Resolution.Eager);
containerBuilder.RegisterType(typeof(ConfigLocator), new[] { typeof(IConfigLocator) }, Lifetime.Singleton, Resolution.Eager);
containerBuilder.RegisterType(typeof(ConfigLocator), new[] { typeof(IConfigLocator) }, Lifetime.Singleton,
Resolution.Eager);
containerBuilder.RegisterType(typeof(SceneLoader.SceneLoader), Lifetime.Singleton, Resolution.Eager);
containerBuilder.RegisterType(typeof(InputService),new[] { typeof(IInputService) }, Lifetime.Singleton, Resolution.Eager);
containerBuilder.RegisterType(typeof(InputService), new[] { typeof(IInputService) }, Lifetime.Singleton,
Resolution.Eager);
containerBuilder.OnContainerBuilt += Bootstrap;
containerBuilder.RegisterType(typeof(AppStateMachine), Lifetime.Singleton, Resolution.Lazy);
containerBuilder.RegisterType(typeof(AppStateMachineContext), Lifetime.Singleton, Resolution.Lazy);
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);
containerBuilder.RegisterType(typeof(AppStateMachine), Lifetime.Singleton, Resolution.Lazy);
containerBuilder.RegisterType(typeof(AppStateMachineContext), Lifetime.Singleton, Resolution.Lazy);
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);
containerBuilder.RegisterType(typeof(VolumeService), new[] { typeof(IVolumeService) }, Lifetime.Singleton,
Resolution.Lazy);
containerBuilder.RegisterType(typeof(VolumeFactory), new[] { typeof(IVolumeFactory) }, Lifetime.Singleton,
Resolution.Eager);
// UIFactory
// Logo
// Scene configs
// Input service
// Camera
_initialLoading = new Loading(5, () => EssentialLoadEnded(_thatRightContainer));
// Volume Factory
// Loading volume
_initialLoading = new Loading(7, () => EssentialLoadEnded(_thatRightContainer));
_ui2CamLoading = new Loading(2,
() =>
{
_thatRightContainer.Resolve<IUIService>().SetCanvasCamera(_thatRightContainer
.Resolve<CameraStateMachineContext>().cameraLoadedData.Camera);
});
}
private Loading _initialLoading;
private Loading _ui2CamLoading;
private Container _thatRightContainer;
private void Bootstrap(Container container)
{
_thatRightContainer = container;
container.Resolve<EventBus.EventBus>().Subscribe(this);
container.Resolve<CameraFactory>().CreateCameraStateMachine(container.Resolve<CameraStateMachine>()).Forget();
container.Resolve<CameraFactory>().CreateCameraStateMachine(container.Resolve<CameraStateMachine>())
.Forget();
}
private void EssentialLoadEnded(Container container)
{
container.Resolve<EventBus.EventBus>().Unsubscribe(this);
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap).AllowStateTransition(AppStates.Gameplay);
container.Resolve<AppStateMachine>().SwitchState(AppStates.Bootstrap)
.AllowStateTransition(AppStates.Gameplay);
}
public void SceneConfigsLoaded()
{
{
_initialLoading.DoProgress();
}
public void InputServiceInitialized()
{
{
_initialLoading.DoProgress();
}
@@ -77,34 +103,59 @@ namespace Code.Infrastructure.App
{
_thatRightContainer.Resolve<CameraStateMachineContext>().cameraLoadedData = data;
_thatRightContainer.Resolve<CameraStateMachine>().SwitchState(CameraMode.None)
.AllowStateTransition(CameraMode.FirstPerson);
.AllowStateTransition(CameraMode.FirstPerson);
data.Camera.GetUniversalAdditionalCameraData().renderPostProcessing = true;
_ui2CamLoading.DoProgress();
_initialLoading.DoProgress();
}
public void UIInitialized()
{
_ui2CamLoading.DoProgress();
_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;
default:
Application.Quit();
break;
}
}
}
public void VolumesInitialized()
{
_initialLoading.DoProgress();
_thatRightContainer.Resolve<IVolumeService>().TryLoadVolume(VolumeId.MenuRetro);
}
public void VolumeLoaded(VolumeId volumeId)
{
switch (volumeId)
{
case VolumeId.MenuRetro:
_initialLoading.DoProgress();
break;
default:
Application.Quit();
break;
}
}
}
}
@@ -1,3 +1,4 @@
#if UNITY_EDITOR
using System.Linq;
using Unity.VisualScripting;
using UnityCodeGen;
@@ -106,4 +107,5 @@ public class {cfg.Name}Config : ScriptableObject
context.AddCode($"SystemConfigsReferences.Generated.cs", configOfConfigsCode);
}
}
}
}
#endif
@@ -1,5 +1,4 @@
using System.Linq;
using Unity.VisualScripting;
#if UNITY_EDITOR
using UnityCodeGen;
using UnityEditor;
using UnityEngine;
@@ -145,4 +144,5 @@ partial void SetupScenesInfo(){{
// context.AddCode($"SystemConfigsReferences.Generated.cs", configOfConfigsCode);
}
}
}
}
#endif
@@ -1,3 +1,4 @@
#if UNITY_EDITOR
using System.Linq;
using Unity.VisualScripting;
using UnityCodeGen;
@@ -128,4 +129,5 @@ namespace {st.Namespace}
}
}
}
}
}
#endif
@@ -1,4 +1,5 @@
using System;
using System;
using UnityEngine;
namespace Code.Infrastructure.Loadings
{
@@ -1,16 +1,22 @@
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
namespace Code.Infrastructure.UI.Panels
{
public class LogoPanel : UIPanel
{
{
[SerializeField] private Image image;
[SerializeField] private Color shownColor;
[SerializeField] private Color hiddenColor;
public override void Open()
{
Debug.Log("Logo panel opened");
{
image.DOColor(shownColor, 1f);
}
public override void Close()
{
image.DOColor(hiddenColor, 1f);
}
}
}
@@ -14,6 +14,7 @@ namespace Code.Infrastructure.UI
{
UniTaskVoid LoadPanel(UIPanelType panelType);
void ReleasePanel(UIPanel panel);
Canvas Canvas { get; }
}
public class UIFactory : IDisposable, IUIFactory
@@ -26,8 +27,11 @@ namespace Code.Infrastructure.UI
private AsyncOperationHandle<IList<UIPanelSettingsConfig>> _configsHandle;
private AsyncOperationHandle<CanvasSettingsConfig> _canvasSettingsHandle;
private CanvasSettingsConfig _canvasConfig;
private GameObject _canvas;
public Canvas Canvas { get; private set; }
public UIFactory(IConfigLocator configLocator, EventBus.EventBus eventBus)
{
_eventBus = eventBus;
@@ -63,6 +67,8 @@ namespace Code.Infrastructure.UI
_canvas = await Addressables.InstantiateAsync(_canvasConfig.Prefab).ToUniTask();
UnityEngine.Object.DontDestroyOnLoad(_canvas);
Canvas = _canvas.GetComponent<Canvas>();
_eventBus.RaiseEvent<IUIInitializedHandle>(ui => ui.UIInitialized());
}
+8 -4
View File
@@ -14,6 +14,7 @@ namespace Code.Infrastructure.UI
void ClosePanel(UIPanelType uiPanelType);
void TryLoadPanel(UIPanelType uiPanelType);
void TryRemovePanel(UIPanelType panelType);
void SetCanvasCamera(UnityEngine.Camera camera);
}
public class UIService : IUIPanelLoadedHandle, IUIService
@@ -30,15 +31,18 @@ namespace Code.Infrastructure.UI
eventBus.Subscribe(this);
}
public void SetCanvasCamera(UnityEngine.Camera camera)
{
_factory.Canvas.worldCamera = camera;
}
public void OpenPanel(UIPanelType uiPanelType)
{
_loadedPanels[uiPanelType].gameObject.SetActive(true); // TODO Братуха реально реши надо вкл\выкл или это очередная хренооптимизация
_loadedPanels[uiPanelType].Open();
_loadedPanels[uiPanelType].Open();
}
public void ClosePanel(UIPanelType uiPanelType)
{
_loadedPanels[uiPanelType].gameObject.SetActive(false);
{
_loadedPanels[uiPanelType].Close();
}
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c53f6bd5c7a84002a173846cefd54093
timeCreated: 1769169770
@@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Code.Infrastructure.Configs;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using Object = UnityEngine.Object;
namespace Code.Infrastructure.Volume
{
public interface IVolumeFactory
{
UniTaskVoid LoadVolume(VolumeId volumeId, Transform transform = null);
void ReleaseVolume(UnityEngine.Rendering.Volume volume);
}
public class VolumeFactory : IDisposable, IVolumeFactory
{
private EventBus.EventBus _eventBus;
private Dictionary<VolumeId, VolumeSettingsConfig> _configs;
private AsyncOperationHandle<IList<VolumeSettingsConfig>> _configsHandle;
private string _configsLabel;
public VolumeFactory(IConfigLocator configLocator, EventBus.EventBus eventBus)
{
_eventBus = eventBus;
_configsLabel = configLocator.TryGetManyConfigAssetReferences<VolumeSettingsConfig>();
LoadConfigs().Forget();
}
private async UniTaskVoid LoadConfigs()
{
_configsHandle = Addressables.LoadAssetsAsync<VolumeSettingsConfig>(_configsLabel);
await _configsHandle.ToUniTask();
_configs = _configsHandle.Result.ToDictionary(c => c.id);
_eventBus.RaiseEvent<IVolumesInitializedHandle>(ui => ui.VolumesInitialized());
}
public async UniTaskVoid LoadVolume(VolumeId volumeId, Transform transform = null)
{
UnityEngine.Rendering.Volume volume = transform == null
? (await Addressables.InstantiateAsync(_configs[volumeId].prefab, transform).ToUniTask())
.GetComponent<UnityEngine.Rendering.Volume>()
: (await Addressables.InstantiateAsync(_configs[volumeId].prefab).ToUniTask())
.GetComponent<UnityEngine.Rendering.Volume>();
if(_configs[volumeId].doNotDestroyOnLoad)
Object.DontDestroyOnLoad(volume.gameObject);
_eventBus.RaiseEvent<IVolumeLoadedHandle>(ui => ui.VolumeLoaded(volume, volumeId));
}
public void ReleaseVolume(UnityEngine.Rendering.Volume volume)
{
Addressables.ReleaseInstance(volume.gameObject);
}
public void Dispose()
{
Addressables.Release(_configsHandle);
}
}
internal interface IVolumesInitializedHandle : IGlobalSubscriber
{
void VolumesInitialized();
}
internal interface IVolumeLoadedHandle : IGlobalSubscriber
{
void VolumeLoaded(UnityEngine.Rendering.Volume volume, VolumeId volumeId);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c607472c188d483a8bb65a5b4a775e44
timeCreated: 1769169793
@@ -0,0 +1,7 @@
namespace Code.Infrastructure.Volume
{
public enum VolumeId
{
MenuRetro
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fc1ca5d8022249c58205c664b7ff628d
timeCreated: 1769169852
@@ -0,0 +1,50 @@
using System.Collections.Generic;
using Code.Infrastructure.EventBus;
namespace Code.Infrastructure.Volume
{
public interface IVolumeService
{
void TryLoadVolume(VolumeId volumeId);
void TryRemoveVolume(VolumeId volumeId);
}
public class VolumeService : IVolumeLoadedHandle, IVolumeService
{
private Dictionary<VolumeId, UnityEngine.Rendering.Volume> _loadedVolumes = new();
private EventBus.EventBus _eventBus;
private IVolumeFactory _factory;
public VolumeService(EventBus.EventBus eventBus, IVolumeFactory factory)
{
_eventBus = eventBus;
_eventBus.Subscribe(this);
_factory = factory;
}
public void TryLoadVolume(VolumeId volumeId) => _factory.LoadVolume(volumeId);
public void VolumeLoaded(UnityEngine.Rendering.Volume volume, VolumeId volumeId)
{
_loadedVolumes.Add(volumeId, volume);
_eventBus.RaiseEvent<IVolumeLoaded>(ui=> ui.VolumeLoaded(volumeId));
}
public void TryRemoveVolume(VolumeId volumeId)
{
// TODO Close it
RemoveVolume(volumeId);
}
private void RemoveVolume(VolumeId volumeId)
{
_factory.ReleaseVolume(_loadedVolumes[volumeId]);
_loadedVolumes.Remove(volumeId);
}
}
public interface IVolumeLoaded : IGlobalSubscriber
{
void VolumeLoaded(VolumeId volumeId);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c301e693e9ef44d9b5395e9d9627f87b
timeCreated: 1769171742
@@ -0,0 +1,13 @@
using Code.Infrastructure.Generators;
using UnityEngine.AddressableAssets;
namespace Code.Infrastructure.Volume
{
[Config("Configs/PostProcessing/VolumeSetting", true)]
public class VolumeSettings
{
[ToConfig] public AssetReference prefab;
[ToConfig] public VolumeId id;
[ToConfig] public bool doNotDestroyOnLoad;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 765e27414fb74f3b9bd11835ae098f92
timeCreated: 1769170079