UI Update, volumes
This commit is contained in:
1 parent
e2d0974b3c
commit
0f0c8bab43
100 files changed
+10862
-734
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user