ProjectDDD/Assets/_DDD/_Scripts/AssetManagement/AssetManager.cs

38 lines
978 B
C#
Raw Normal View History

2025-07-10 05:48:44 +00:00
using System;
2025-07-09 09:45:11 +00:00
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
namespace DDD
{
public class AssetManager : Singleton<AssetManager>, IManager
{
public void Init()
{
}
2025-07-10 05:48:44 +00:00
public async void PostInit()
2025-07-09 09:45:11 +00:00
{
2025-07-10 05:48:44 +00:00
try
{
await Addressables.InitializeAsync().Task;
}
catch (Exception e)
{
Debug.Assert(false, "Addressables initialization failed");
}
}
public static async Awaitable<T> LoadAsset<T>(string key) where T : UnityEngine.Object
{
var handle = Addressables.LoadAssetAsync<T>(key);
await handle.Task;
if (handle.Status == AsyncOperationStatus.Succeeded)
return handle.Result;
Debug.LogError($"Addressable load failed : {key}");
return null;
2025-07-09 09:45:11 +00:00
}
}
}