WuhuIslandTesting/Library/PackageCache/com.unity.addressables@1.21.12/Samples~/AddressablesUtility/AddressablesUtility.cs

28 lines
924 B
C#
Raw Normal View History

2025-01-07 02:06:59 +01:00
using UnityEngine.AddressableAssets;
/// <summary>
/// A utility class for various Addressables functionality
/// </summary>
public static class AddressablesUtility
{
/// <summary>
/// Get the address of a given AssetReference.
/// </summary>
/// <param name="reference">The AssetReference you want to find the address of.</param>
/// <returns>The address of a given AssetReference.</returns>
public static string GetAddressFromAssetReference(AssetReference reference)
{
var loadResourceLocations = Addressables.LoadResourceLocationsAsync(reference);
var result = loadResourceLocations.WaitForCompletion();
if (result.Count > 0)
{
string key = result[0].PrimaryKey;
Addressables.Release(loadResourceLocations);
return key;
}
Addressables.Release(loadResourceLocations);
return string.Empty;
}
}