Timeline工具
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
@@ -94,6 +94,31 @@ namespace AibisDream.Framework
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步加载 Addressable 资源,callback 接收完整 handle。调用方需在适当时机调用 Release 释放。
|
||||
/// </summary>
|
||||
public static void LoadAssetAsyncWithHandle<T>(string key, Action<AsyncOperationHandle<T>> callback) where T : UnityEngine.Object
|
||||
{
|
||||
var handle = Addressables.LoadAssetAsync<T>(key);
|
||||
handle.Completed += operation =>
|
||||
{
|
||||
if (operation.Status != AsyncOperationStatus.Succeeded)
|
||||
{
|
||||
Debug.Log($"资源{key}不存在");
|
||||
}
|
||||
callback(operation);
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放 Addressable 加载的 handle
|
||||
/// </summary>
|
||||
public static void Release<T>(AsyncOperationHandle<T> handle)
|
||||
{
|
||||
if (handle.IsValid())
|
||||
Addressables.Release(handle);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public static bool GetAssetAddressableKey<T>(T asset, out string addressableKey) where T : UnityEngine.Object
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user