load sound into map collection
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
using UnityEngine.AddressableAssets.ResourceLocators;
|
||||
@@ -12,6 +13,7 @@ namespace BrewMonster.Scripts
|
||||
public class AddressableManager : MonoSingleton<AddressableManager>
|
||||
{
|
||||
private bool _isInitialized = false;
|
||||
private UniTaskCompletionSource _initializationTcs;
|
||||
|
||||
private Dictionary<string, AsyncOperationHandle<GameObject>> _loadedPrefabAssets = new();
|
||||
private Dictionary<string, AsyncOperationHandle<TextAsset>> _loadedTextAssets = new();
|
||||
@@ -31,10 +33,21 @@ namespace BrewMonster.Scripts
|
||||
|
||||
public bool IsInitialized() => _isInitialized;
|
||||
|
||||
/// <summary>
|
||||
/// Returns immediately if already initialized; otherwise waits for the
|
||||
/// Addressables initialization callback without per-frame polling.
|
||||
/// </summary>
|
||||
public UniTask WaitUntilInitializedAsync()
|
||||
{
|
||||
if (_isInitialized) return UniTask.CompletedTask;
|
||||
return _initializationTcs.Task;
|
||||
}
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_isInitialized = false;
|
||||
_initializationTcs = new UniTaskCompletionSource();
|
||||
Addressables.InitializeAsync().Completed += OnInitializeComplete;
|
||||
}
|
||||
|
||||
@@ -68,6 +81,7 @@ namespace BrewMonster.Scripts
|
||||
if (handle.Status == AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
_isInitialized = true;
|
||||
_initializationTcs.TrySetResult();
|
||||
BMLogger.Log($"AddressableManager: Initialized");
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user