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)];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91110ad324dd6984a996ba9e842f00d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Utilities.ConfigsManagement
|
||||
{
|
||||
public interface IConfigsLoader
|
||||
{
|
||||
IEnumerator LoadAsync(Action<Dictionary<Type, object>> onConfigsLoaded);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3fdc549c53a2ce342b7735b0d0a1fd1b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
using Assets._Project.Develop.Runtime.Utilities.AssetsManagement;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Assets._Project.Develop.Runtime.Utilities.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Utilities.ConfigsManagement
|
||||
{
|
||||
public class ResourcesConfigsLoader : IConfigsLoader
|
||||
{
|
||||
private readonly ResourcesAssetsLoader _resources;
|
||||
|
||||
private readonly Dictionary<Type, string> _configsResourcesPaths = new (PathToResources.ScriptableObject);
|
||||
|
||||
public ResourcesConfigsLoader(ResourcesAssetsLoader resources)
|
||||
{
|
||||
_resources = resources;
|
||||
}
|
||||
|
||||
public IEnumerator LoadAsync(Action<Dictionary<Type, object>> onConfigsLoaded)
|
||||
{
|
||||
Dictionary<Type, object> loadedConfigs = new();
|
||||
|
||||
foreach (KeyValuePair<Type, string> configResourcesPath in _configsResourcesPaths)
|
||||
{
|
||||
ScriptableObject config = _resources.Load<ScriptableObject>(configResourcesPath.Value);
|
||||
loadedConfigs.Add(configResourcesPath.Key, config);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
onConfigsLoaded?.Invoke(loadedConfigs);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a5f12d91469c594f9809cd92473593c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user