Init
This commit is contained in:
1 parent
a73338916a
commit
fbc1cc8d3e
207 files changed
+10327
-2
No files matched your search
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Code.Infrastructure.SceneLoader;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace Code.Infrastructure.Configs
|
||||
{
|
||||
public partial class ConfigLocator : IConfigLocator
|
||||
{
|
||||
private Dictionary<Type, AssetReference> _singleConfigReferences = new();
|
||||
private Dictionary<Type, string> _multipleConfigReferences = new();
|
||||
|
||||
public AssetReference TryGetConfigAssetReference<T>() => _singleConfigReferences.GetValueOrDefault(typeof(T), null);
|
||||
public string TryGetManyConfigAssetReferences<T>() => _multipleConfigReferences.GetValueOrDefault(typeof(T), null);
|
||||
|
||||
partial void LoadConfigs();
|
||||
|
||||
public ConfigLocator()
|
||||
{
|
||||
LoadSystemConfigs();
|
||||
|
||||
LoadConfigs();
|
||||
}
|
||||
|
||||
private void LoadSystemConfigs()
|
||||
{
|
||||
SystemConfigsReferences systemConfigsReferences = Resources.Load<SystemConfigsReferences>("SystemConfigsReferences");
|
||||
|
||||
_singleConfigReferences.Add(typeof(ScenesAssetReferences), systemConfigsReferences.scenesAssetReferences);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42496064fd5d42fea1c889f91e6a7e98
|
||||
timeCreated: 1765711330
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Code.Infrastructure.Configs
|
||||
{
|
||||
public enum LayerMaskType
|
||||
{
|
||||
PlatformerGround
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0aab84d976cf4045b47f347ad8d77c79
|
||||
timeCreated: 1770907660
|
||||
@@ -0,0 +1,53 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Code.Infrastructure.EventBus;
|
||||
using Code.Infrastructure.Generators;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Attributes;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace Code.Infrastructure.Configs
|
||||
{
|
||||
[Config("Configs/LayerMasksConfig", true)]
|
||||
public struct LayerMasksConfig
|
||||
{
|
||||
[ToConfig] public LayerMask mask;
|
||||
[ToConfig] public LayerMaskType type;
|
||||
}
|
||||
|
||||
public class LayerMasks
|
||||
{
|
||||
public static Dictionary<LayerMaskType, LayerMask> Masks { get; } = new();
|
||||
|
||||
private static void SetMasks(IList<LayerMasksConfigConfig> configs)
|
||||
{
|
||||
foreach (var config in configs.Where(config => !Masks.ContainsKey(config.type)))
|
||||
Masks.Add(config.type, config.mask);
|
||||
}
|
||||
|
||||
public LayerMasks(IConfigLocator configLocator, EventBus.EventBus eventBus)
|
||||
{
|
||||
SetupMasks(configLocator, eventBus).Forget();
|
||||
}
|
||||
private async UniTaskVoid SetupMasks(IConfigLocator configLocator, EventBus.EventBus eventBus)
|
||||
{
|
||||
var handle =
|
||||
Addressables.LoadAssetsAsync<LayerMasksConfigConfig>(
|
||||
configLocator.TryGetManyConfigAssetReferences<LayerMasksConfigConfig>(), null, Addressables.MergeMode.Union);
|
||||
|
||||
await handle.ToUniTask();
|
||||
|
||||
SetMasks(handle.Result);
|
||||
|
||||
Addressables.Release(handle);
|
||||
|
||||
eventBus.RaiseEvent<ILayerMasksInitializedHandle>(x => x.LayerMasksInitialized());
|
||||
}
|
||||
}
|
||||
|
||||
public interface ILayerMasksInitializedHandle : IGlobalSubscriber
|
||||
{
|
||||
void LayerMasksInitialized();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2fe6e42771fc4a48a37acbe4fa992e4a
|
||||
timeCreated: 1770906616
|
||||
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
|
||||
namespace Code.Infrastructure.Configs
|
||||
{
|
||||
[CreateAssetMenu(fileName = "SystemConfigsReferences", menuName = "Configs/SystemConfigsReferences")]
|
||||
public partial class SystemConfigsReferences : ScriptableObject
|
||||
{
|
||||
public AssetReference scenesAssetReferences;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 728b0ad306a64bd28d47fc4d052c5e81
|
||||
timeCreated: 1766325607
|
||||
Reference in new issue
Block a user