Second commit

This commit is contained in:
ThomasCharester committed 2026-09-20 15:26:03 +03:00
commit 36840f3ad4
999 files changed
+61364

No files matched your search

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Code.Infrastructure.Configs;
using Code.Infrastructure.Utils;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using Object = UnityEngine.Object;
namespace Code.Infrastructure.Volume
{
public interface IVolumeFactory
{
UniTask<UnityEngine.Rendering.Volume> LoadVolume(VolumeId volumeId, Transform transform = null);
void ReleaseVolume(UnityEngine.Rendering.Volume volume);
}
public interface IVolumeFactoryInitializer
{
UniTask LoadConfigs();
}
public class VolumeFactory : IDisposable, IVolumeFactory, IVolumeFactoryInitializer
{
private Dictionary<VolumeId, VolumeSettings> _configs;
private AsyncOperationHandle<IList<VolumeSettings>> _configsHandle;
private string _configsLabel;
public VolumeFactory(IConfigLocator configLocator)
{
_configsLabel = configLocator.TryGetManyConfigAssetReferences<VolumeSettings>();
}
public async UniTask LoadConfigs()
{
if(!await AddressablesUtilities.CheckLabelExists(_configsLabel))
{
_configs = new();
return;
}
_configsHandle = Addressables.LoadAssetsAsync<VolumeSettings>(_configsLabel);
await _configsHandle.ToUniTask();
_configs = _configsHandle.Result.ToDictionary(c => c.id);
}
public async UniTask<UnityEngine.Rendering.Volume> LoadVolume(VolumeId volumeId, Transform transform = null)
{
UnityEngine.Rendering.Volume volume = !transform
? (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);
return volume;
}
public void ReleaseVolume(UnityEngine.Rendering.Volume volume)
{
Addressables.ReleaseInstance(volume.gameObject);
}
public void Dispose()
{
if(_configsHandle.IsValid()) Addressables.Release(_configsHandle);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c607472c188d483a8bb65a5b4a775e44
timeCreated: 1769169793
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
namespace Code.Infrastructure.Volume
{
public interface IVolumeService
{
UniTask LoadVolume(VolumeId volumeId);
void RemoveVolume(VolumeId volumeId);
}
public class VolumeService : IVolumeService
{
private readonly Dictionary<VolumeId, UnityEngine.Rendering.Volume> _loadedVolumes = new();
private readonly IVolumeFactory _factory;
public VolumeService(IVolumeFactory factory)
{
_factory = factory;
}
public async UniTask LoadVolume(VolumeId volumeId)
{
var volume = await _factory.LoadVolume(volumeId);
_loadedVolumes.Add(volumeId, volume);
}
public void RemoveVolume(VolumeId volumeId)
{
_factory.ReleaseVolume(_loadedVolumes[volumeId]);
_loadedVolumes.Remove(volumeId);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c301e693e9ef44d9b5395e9d9627f87b
timeCreated: 1769171742
@@ -0,0 +1,15 @@
using Code.Infrastructure.Generators;
using UnityEngine;
using UnityEngine.AddressableAssets;
namespace Code.Infrastructure.Volume
{
[Config("Configs/PostProcessing/VolumeSetting", true)]
[CreateAssetMenu(fileName = "VolumeSettings", menuName = "Configs/PostProcessing/VolumeSetting")]
public class VolumeSettings : ScriptableObject
{
public AssetReference prefab;
public VolumeId id;
public bool doNotDestroyOnLoad;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 765e27414fb74f3b9bd11835ae098f92