diff --git a/Assets/PerfectWorld/Scripts/Addressable/AddressableManager.cs b/Assets/PerfectWorld/Scripts/Addressable/AddressableManager.cs index 1dda787681..fa964853e1 100644 --- a/Assets/PerfectWorld/Scripts/Addressable/AddressableManager.cs +++ b/Assets/PerfectWorld/Scripts/Addressable/AddressableManager.cs @@ -14,6 +14,7 @@ namespace BrewMonster.Scripts private bool _isInitialized = false; private Dictionary> _loadedAssets = new(); + private Dictionary> _loadedTextAssets = new(); public event Action OnDispose; protected override void Initialize() @@ -23,6 +24,11 @@ namespace BrewMonster.Scripts Addressables.InitializeAsync().Completed += OnInitializeComplete; } + public bool IsInitialized() + { + return _isInitialized; + } + void OnInitializeComplete(AsyncOperationHandle handle) { if (handle.Status == AsyncOperationStatus.Succeeded) @@ -37,6 +43,33 @@ namespace BrewMonster.Scripts } } + /// + /// Load a text asset asynchronously. The address should look like this: "elements.data" + /// + /// + /// + /// + public async Task LoadAssetAsync(string assetPath) + { + if (_loadedAssets.ContainsKey(assetPath)) + { + return _loadedTextAssets[assetPath].Result; + } + + try + { + var handle = Addressables.LoadAssetAsync(assetPath); + await handle.Task; + _loadedTextAssets[assetPath] = handle; + return handle.Result; + } + catch (Exception e) + { + BMLogger.LogError(e.StackTrace); + return null; + } + } + /// /// Load an asset asynchronously. The address should look like this: "models/npcs/npc/魅灵首领/魅灵首领/魅灵首领.prefab" ///