ProjectDDD/Assets/_DDD/_Scripts/AssetManagement/AssetManager.cs
2025-07-10 14:48:44 +09:00

38 lines
978 B
C#

using System;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
namespace DDD
{
public class AssetManager : Singleton<AssetManager>, IManager
{
public void Init()
{
}
public async void PostInit()
{
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;
}
}
}