Files
MojSadUnity/Assets/Code/Calendar/Constants/ConstantImagesService.cs
T

46 lines
1.5 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Code.Infrastructure.Configs;
using Code.Infrastructure.EventBus;
using Cysharp.Threading.Tasks;
using UnityEngine.AddressableAssets;
namespace Code.Calendar.Constants
{
// Написать кодрайтер, который будет находить конфиги и добавлять их сюда пока написано само
public class ConstantImagesService
{
private readonly EventBus _eventBus;
public List<ConstantImageConfig> Configs { get; private set; }
public ConstantImagesService(EventBus eventBus, IConfigLocator configLocator)
{
_eventBus = eventBus;
var label = configLocator.TryGetManyConfigAssetReferences<ConstantImageConfig>();
LoadImage(label).Forget();
}
private async UniTaskVoid LoadImage(string imagesLabel)
{
if ((await Addressables.LoadResourceLocationsAsync(imagesLabel).Task).Count != 0)
{
var images =
Addressables.LoadAssetsAsync<ConstantImageConfig>(imagesLabel, null, Addressables.MergeMode.Union);
await images.ToUniTask();
Configs = images.Result.ToList();
}
_eventBus.RaiseEvent<IConstantImagesServiceHandle>(x=> x.ImagesLoaded());
}
}
public interface IConstantImagesServiceHandle : IGlobalSubscriber
{
void ImagesLoaded();
}
}