Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How to get address from IResourceLocation?

Discussion in 'Addressables' started by gtamrLailroe, Mar 13, 2019.

  1. gtamrLailroe

    gtamrLailroe

    Joined:
    Nov 10, 2017
    Posts:
    2
    I write this Extension
    Code (CSharp):
    1. public static class AddressablesExtensions
    2.     {
    3.         public static string GetAddress(this IResourceLocation location)
    4.         {
    5.             foreach (var locator in Addressables.ResourceLocators.OfType<ResourceLocationMap>())
    6.             {
    7.                 var address = (string) locator.Locations
    8.                     .Where(x => x.Value.Contains(location))
    9.                     .Select(x => x.Key)
    10.                     .FirstOrDefault();
    11.  
    12.                 if (!string.IsNullOrEmpty(address)) return address;
    13.             }
    14.  
    15.             throw new Exception("Ассета по внутреннему ID почему-то не нашлось ОО");
    16.         }
    17.     }
    Addressables have buildin function for this?

    P.S. This needed after get list by label and select for save some one
     
    mcurtiss and Coryatmarsden like this.
  2. Coryatmarsden

    Coryatmarsden

    Joined:
    May 22, 2018
    Posts:
    6
    Thank you for this! I was also trying to figure out if there was a built in function to do this but your solution works great.