mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
init: add project
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Unity.VisualScripting;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Utilities.ConfigsManagement
|
||||
{
|
||||
public class ConfigsProviderService
|
||||
{
|
||||
private readonly Dictionary<Type, object> _configs = new();
|
||||
|
||||
private readonly IConfigsLoader[] _loaders;
|
||||
|
||||
public ConfigsProviderService(params IConfigsLoader[] loaders)
|
||||
{
|
||||
_loaders = loaders;
|
||||
}
|
||||
|
||||
public IEnumerator LoadAsync()
|
||||
{
|
||||
_configs.Clear();
|
||||
|
||||
foreach (IConfigsLoader loader in _loaders)
|
||||
yield return loader.LoadAsync(loadedConfigs => _configs.AddRange(loadedConfigs));
|
||||
}
|
||||
|
||||
public T GetConfig<T>() where T : class
|
||||
{
|
||||
if (_configs.ContainsKey(typeof(T)) == false)
|
||||
throw new InvalidOperationException($"Not found config by {typeof(T)}");
|
||||
|
||||
return (T)_configs[typeof(T)];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user