Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using Cysharp.Threading.Tasks;
- using UnityEngine;
- using Dre0Dru.AddressableAssets.Loaders;
- using UnityEngine.AddressableAssets;
- using UnityEngine.ResourceManagement.AsyncOperations;
- namespace Dre0Dru.AddressableAssets.Loader
- {
- public class AssetsNameLoader<TAsset> : IAssetsLoader<string, TAsset> where TAsset : Object
- {
- private readonly Dictionary<int, AsyncOperationHandle<TAsset>> _operationHandles = new();
- public async void InitializeAsync()
- {
- Debug.Log("Start Addressables initializ.");
- var initHandle = Addressables.InitializeAsync();
- await initHandle.ToUniTask();
- if (initHandle.Status == AsyncOperationStatus.Succeeded)
- {
- Debug.Log("Addressables initialized successfully.");
- }
- else
- {
- Debug.LogError("Failed to initialize Addressables.");
- }
- }
- public UniTask PreloadAssetAsync(string name) => LoadAssetAsync(name);
- // ОСЬ ЦЕЙ МЕТОД ВСЕ МАЄ ЗАВАНТАЖУВАТИ
- public async UniTask<TAsset> LoadAssetAsync(string name)
- {
- try
- {
- Debug.LogError($"Start load sprite: {name}");
- AsyncOperationHandle<TAsset> handle = Addressables.LoadAssetAsync<TAsset>(name);
- Debug.LogError($"handle!!!");
- await handle.ToUniTask();
- Debug.LogError($"handle.ToUniTask!!!");
- if (handle.Status == AsyncOperationStatus.Succeeded)
- {
- Debug.LogError($"AsyncOperationStatus.Succeeded!!!");
- if (!_operationHandles.TryAdd(name.GetHashCode(), handle))
- {
- Addressables.Release(_operationHandles[name.GetHashCode()]); // Розвантажити попередню операцію
- _operationHandles[name.GetHashCode()] = handle; // Оновити дескриптор операції
- }
- Debug.LogError($"end load sprite: {name}");
- return handle.Result;
- }
- else
- {
- Debug.LogError($"Не вдалося завантажити ресурс: {name}");
- }
- }
- catch (System.Exception e)
- {
- Debug.LogError($"Сталася помилка під час завантаження ресурсу: {e.Message}");
- }
- return null;
- }
- public bool IsAssetLoaded(string name)
- {
- if (_operationHandles.TryGetValue(name.GetHashCode(), out AsyncOperationHandle<TAsset> handle))
- {
- return handle.Status == AsyncOperationStatus.Succeeded;
- }
- return false;
- }
- public TAsset GetAsset(string name)
- {
- return _operationHandles[name.GetHashCode()].Result;
- }
- public bool TryGetAsset(string name, out TAsset asset)
- {
- asset = default;
- if (IsAssetLoaded(name))
- {
- asset = GetAsset(name);
- return asset;
- }
- return false;
- }
- public void UnloadAsset(string name)
- {
- int hashKey = name.GetHashCode();
- if (_operationHandles.TryGetValue(hashKey, out AsyncOperationHandle<TAsset> handle))
- {
- Addressables.Release(handle);
- _operationHandles.Remove(hashKey);
- }
- }
- public void UnloadAllAssets()
- {
- foreach (var handle in _operationHandles.Values)
- {
- Addressables.Release(handle);
- }
- _operationHandles.Clear();
- }
- }
- }
- ПОМИЛКА
- 2024/10/02 17:29:51.102 4398 4417 Error Unity Start load sprite: Genres // мій дебаг
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #0 0x7bbbc6cc3c (libunity.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #1 0x7bbc13d0e0 (libunity.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #2 0x7bbb9410e0 (libunity.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #3 0x7bbb940fd0 (libunity.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #4 0x7bb6d10620 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #5 0x7bb6b7f768 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #6 0x7bb6ec813c (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #7 0x7bb6ec8068 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #8 0x7bb6b7a490 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #9 0x7bb6ad3514 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #10 0x7bb6b7a2c0 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #11 0x7bb6b8ba24 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #12 0x7bb6ad3514 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #13 0x7bb6b8af60 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #14 0x7bb6b8b26c (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #15 0x7bb6edc3d0 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #16 0x7bb68767f4 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #17 0x7bb6d651a0 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #18 0x7bb6edc558 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #19 0x7bb6af0ae4 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #20 0x7bb6edc3d0 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #21 0x7bb68767f4 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #22 0x7bb6d651a0 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #23 0x7bb777b720 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #24 0x7bb77ada88 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.102 4398 4417 Error Unity #25 0x7bb69c75b8 (libil2cpp.so) ? 0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity handle!!! // це мої дебаги
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #0 0x7bbbc6cc3c (libunity.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #1 0x7bbc13d0e0 (libunity.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #2 0x7bbb9410e0 (libunity.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #3 0x7bbb940fd0 (libunity.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #4 0x7bb6d10688 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #5 0x7bb6b7f768 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #6 0x7bb6ec813c (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #7 0x7bb6ec8068 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #8 0x7bb6b7a490 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #9 0x7bb6ad3514 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #10 0x7bb6b7a2c0 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #11 0x7bb6b8ba24 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #12 0x7bb6ad3514 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #13 0x7bb6b8af60 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #14 0x7bb6b8b26c (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #15 0x7bb6edc3d0 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #16 0x7bb68767f4 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #17 0x7bb6d651a0 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #18 0x7bb6edc558 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #19 0x7bb6af0ae4 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #20 0x7bb6edc3d0 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #21 0x7bb68767f4 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #22 0x7bb6d651a0 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #23 0x7bb777b720 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #24 0x7bb77ada88 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #25 0x7bb69c75b8 (libil2cpp.so) ? 0x0
- 2024/10/02 17:29:51.105 4398 4417 Error Unity #26 0x7bb69c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement