コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】Addressable Asset System で PlatformMappingService.GetAddressablesPlatformInternal をリフレクションで参照する関数

概要

private static AddressablesPlatform GetPlatform( BuildTarget target )
{
    const string methodName = "GetAddressablesPlatformInternal";
    
    var serviceType = typeof( PlatformMappingService );
    var targetType  = typeof( BuildTarget );
    var methods     = serviceType.GetMethods( BindingFlags.Static | BindingFlags.NonPublic );
    var method      = methods.FirstOrDefault( c => c.Name == methodName && c.GetParameters()[ 0 ].ParameterType == targetType );
    var platform    = ( AddressablesPlatform ) method.Invoke( null, new object[] { target } );

    return platform;
}