Search Unity

Custom Build Script for platform-specific assets

Discussion in 'Addressables' started by V0odo0, Jun 22, 2021.

  1. V0odo0

    V0odo0

    Joined:
    Jan 8, 2012
    Posts:
    328
    Let's say I have two asset variants: Standalone and Mobile. Such assets could be a texture, prefab or even scene with it's corresponding references. I want them both to be available in Use Asset Database Play Mode Script in Editor but one of them (and all it's references that are not referencing by other assets) should be excluded from final platform-specific generated bundles.

    I tried to achieve this with custom Build Script derived from BuildScriptPackedMode by removing labeled asset entries in overridden DoBuild / ProcessGroup methods with no luck.
     
  2. V0odo0

    V0odo0

    Joined:
    Jan 8, 2012
    Posts:
    328
    Ok I've found a temporary solution for this using custom AddressableAssetGroupSchema attached to groups.

    Custom build script
    Code (CSharp):
    1. public class PlatformSpecificBuildScript : BuildScriptPackedMode
    2.     {
    3.         protected override string ProcessGroup(AddressableAssetGroup assetGroup, AddressableAssetsBuildContext aaContext)
    4.         {
    5.             var platformSchema = assetGroup.GetSchema<PlatformSpecificGroupSchema>();
    6.             var groupSchema = assetGroup.GetSchema<BundledAssetGroupSchema>();
    7.             if (platformSchema != null && groupSchema != null)
    8.             {
    9.                 var activePlatform = PlatformMappingService.GetPlatform();
    10.                 groupSchema.IncludeInBuild = platformSchema.TargetPlatforms.Contains(activePlatform);
    11.             }
    12.  
    13.             return base.ProcessGroup(assetGroup, aaContext);
    14.         }
    15.     }
    Custom AddressableAssetGroupSchema
    Code (CSharp):
    1. public class PlatformSpecificGroupSchema : AddressableAssetGroupSchema
    2.     {
    3.         public AddressablesPlatform[] TargetPlatforms => _targetPlatforms;
    4.         [SerializeField] private AddressablesPlatform[] _targetPlatforms = new AddressablesPlatform[0];
    5.     }
    Group settings


    This is however requires a separate group for each platform. Still looking for better solution using labels for example.
     
    eastepp likes this.