38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
|
|
namespace Code.Infrastructure.Configs
|
|
{
|
|
// Слабое место кода
|
|
public interface IConfigLocator
|
|
{
|
|
AssetReference TryGetConfigAssetReference<T>();
|
|
string TryGetManyConfigAssetReferences<T>();
|
|
}
|
|
public partial class ConfigLocator : IConfigLocator
|
|
{
|
|
private readonly Dictionary<Type, AssetReference> _singleConfigReferences = new();
|
|
private readonly Dictionary<Type, string> _multipleConfigReferences = new();
|
|
|
|
private ConfigReferences _configReferences;
|
|
|
|
public AssetReference TryGetConfigAssetReference<T>() => _singleConfigReferences.GetValueOrDefault(typeof(T), null);
|
|
public string TryGetManyConfigAssetReferences<T>() => _multipleConfigReferences.GetValueOrDefault(typeof(T), null);
|
|
|
|
partial void LoadConfigs();
|
|
|
|
public ConfigLocator()
|
|
{
|
|
LoadConfigReferences();
|
|
|
|
LoadConfigs();
|
|
}
|
|
|
|
private void LoadConfigReferences()
|
|
{
|
|
_configReferences = Resources.Load<ConfigReferences>("ConfigReferences");
|
|
}
|
|
}
|
|
} |