Second commit
This commit is contained in:
commit
36840f3ad4
999 files changed
+61364
No files matched your search
@@ -0,0 +1,30 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
namespace Code.Infrastructure.Utils
|
||||
{
|
||||
public static class AddressablesUtilities
|
||||
{
|
||||
public static async UniTask<bool> CheckLabelExists(string labelName)
|
||||
{
|
||||
if (labelName is null) return false;
|
||||
|
||||
var handle = Addressables.LoadResourceLocationsAsync(labelName);
|
||||
|
||||
await handle.ToUniTask();
|
||||
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
if (handle.Result.Count > 0)
|
||||
{
|
||||
Addressables.Release(handle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Addressables.Release(handle);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 607f50d5faeb41f585a2b4079902fbc6
|
||||
timeCreated: 1774778444
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Code.Infrastructure.Configs;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Reflex.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
|
||||
namespace Code.Infrastructure.Utils
|
||||
{
|
||||
public class MultipleConfig<TConfig> : IDisposable where TConfig : ScriptableObject
|
||||
{
|
||||
private AsyncOperationHandle<IList<TConfig>> _configsHandle;
|
||||
|
||||
public IList<TConfig> Configs => _configsHandle.Result;
|
||||
|
||||
public async UniTask<IList<TConfig>> LoadConfigs()
|
||||
{
|
||||
if (_configsHandle.IsValid()) return _configsHandle.Result;
|
||||
var configLocator = Container.RootContainer.Resolve<IConfigLocator>();
|
||||
|
||||
var label = configLocator.TryGetManyConfigAssetReferences<TConfig>();
|
||||
|
||||
_configsHandle = Addressables.LoadAssetsAsync<TConfig>(label);
|
||||
|
||||
await _configsHandle;
|
||||
|
||||
return _configsHandle.Result;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if(_configsHandle.IsValid()) _configsHandle.Release();
|
||||
}
|
||||
}
|
||||
public class SingleConfig<TConfig> : IDisposable where TConfig : ScriptableObject
|
||||
{
|
||||
private AsyncOperationHandle<TConfig> _configHandle;
|
||||
public TConfig Config => _configHandle.IsDone ? _configHandle.Result : null;
|
||||
|
||||
public async UniTask<TConfig> LoadConfig()
|
||||
{
|
||||
if (_configHandle.IsValid()) return _configHandle.Result;
|
||||
var configLocator = Container.RootContainer.Resolve<IConfigLocator>();
|
||||
|
||||
var label = configLocator.TryGetConfigAssetReference<TConfig>();
|
||||
|
||||
_configHandle = Addressables.LoadAssetAsync<TConfig>(label);
|
||||
|
||||
await _configHandle;
|
||||
|
||||
return _configHandle.Result;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if(_configHandle.IsValid()) _configHandle.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d66e152012484170908388987ee81821
|
||||
timeCreated: 1783878002
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Code.Infrastructure.Utils
|
||||
{
|
||||
// Source - https://stackoverflow.com/a/972323
|
||||
// Posted by JaredPar, modified by community. See post 'Timeline' for change history
|
||||
// Retrieved 2026-07-22, License - CC BY-SA 4.0
|
||||
// Thanks to him :)
|
||||
public static class EnumUtil {
|
||||
public static IEnumerable<T> GetValues<T>() {
|
||||
return Enum.GetValues(typeof(T)).Cast<T>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d87b3cb42445428888da6391d1e23d87
|
||||
timeCreated: 1784729151
|
||||
Reference in new issue
Block a user