@@ -235,6 +235,18 @@ public enum PlayerConnectionInitiateMode
235235 PlayerListens
236236 }
237237
238+
239+ [ StructLayout ( LayoutKind . Sequential ) ]
240+ public struct BuildAssetBundlesParameters
241+ {
242+ public string outputPath { get ; set ; }
243+ public AssetBundleBuild [ ] bundleDefinitions { get ; set ; }
244+ public BuildAssetBundleOptions options { get ; set ; }
245+ public BuildTarget targetPlatform { get ; set ; }
246+ public int subtarget { get ; set ; }
247+ public string [ ] extraScriptingDefines { get ; set ; }
248+ }
249+
238250 // Lets you programmatically build players or AssetBundles which can be loaded from the web.
239251 [ NativeHeader ( "Editor/Mono/BuildPipeline.bindings.h" ) ]
240252 [ StaticAccessor ( "BuildPipeline" , StaticAccessorType . DoubleColon ) ]
@@ -540,7 +552,7 @@ public static bool BuildAssetBundle(UnityEngine.Object mainAsset, UnityEngine.Ob
540552 return BuildAssetBundle ( mainAsset , assets , pathName , out crc , assetBundleOptions , targetPlatformGroup , targetPlatform , EditorUserBuildSettings . GetActiveSubtargetFor ( targetPlatform ) ) ;
541553 }
542554
543- // Builds an AssetBundle.
555+ // Builds an AssetBundle (Obsolete)
544556 internal static bool BuildAssetBundle ( UnityEngine . Object mainAsset , UnityEngine . Object [ ] assets , string pathName , out uint crc , BuildAssetBundleOptions assetBundleOptions , BuildTargetGroup targetPlatformGroup , BuildTarget targetPlatform , int subtarget )
545557 {
546558 crc = 0 ;
@@ -571,7 +583,7 @@ public static bool BuildAssetBundleExplicitAssetNames(UnityEngine.Object[] asset
571583 return BuildAssetBundleExplicitAssetNames ( assets , assetNames , pathName , out crc , assetBundleOptions , targetPlatformGroup , targetPlatform , EditorUserBuildSettings . GetActiveSubtargetFor ( targetPlatform ) ) ;
572584 }
573585
574- // Builds an AssetBundle, with custom names for the assets.
586+ // Builds an AssetBundle, with custom names for the assets (Obsolete)
575587 internal static bool BuildAssetBundleExplicitAssetNames ( UnityEngine . Object [ ] assets , string [ ] assetNames , string pathName , out uint crc , BuildAssetBundleOptions assetBundleOptions , BuildTargetGroup targetPlatformGroup , BuildTarget targetPlatform , int subtarget )
576588 {
577589 crc = 0 ;
@@ -588,51 +600,63 @@ internal static bool BuildAssetBundleExplicitAssetNames(UnityEngine.Object[] ass
588600
589601#pragma warning restore 618
590602
603+ //Obsolete
591604 private static extern bool BuildAssetBundleInternal ( UnityEngine . Object mainAsset , UnityEngine . Object [ ] assets , string [ ] assetNames , string pathName , BuildAssetBundleOptions assetBundleOptions , BuildTargetGroup targetPlatformGroup , BuildTarget targetPlatform , int subtarget , out uint crc ) ;
592605
593606 public static AssetBundleManifest BuildAssetBundles ( string outputPath , BuildAssetBundleOptions assetBundleOptions , BuildTarget targetPlatform )
594607 {
595- BuildTargetGroup targetPlatformGroup = BuildPipeline . GetBuildTargetGroup ( targetPlatform ) ;
596- return BuildAssetBundles ( outputPath , assetBundleOptions , targetPlatformGroup , targetPlatform , EditorUserBuildSettings . GetActiveSubtargetFor ( targetPlatform ) ) ;
608+ BuildAssetBundlesParameters input = new BuildAssetBundlesParameters
609+ {
610+ outputPath = outputPath ,
611+ bundleDefinitions = null , // Bundle assignment will be read from AssetDatabase
612+ options = assetBundleOptions ,
613+ targetPlatform = targetPlatform ,
614+ subtarget = EditorUserBuildSettings . GetActiveSubtargetFor ( targetPlatform ) ,
615+ } ;
616+
617+ return BuildAssetBundles ( input ) ;
597618 }
598619
599- internal static AssetBundleManifest BuildAssetBundles ( string outputPath , BuildAssetBundleOptions assetBundleOptions , BuildTargetGroup targetPlatformGroup , BuildTarget targetPlatform , int subtarget )
620+ public static AssetBundleManifest BuildAssetBundles ( string outputPath , AssetBundleBuild [ ] builds , BuildAssetBundleOptions assetBundleOptions , BuildTarget targetPlatform )
600621 {
601- if ( isBuildingPlayer )
602- throw new InvalidOperationException ( "Cannot build asset bundles while a build is in progress." ) ;
622+ if ( builds == null )
623+ // This signature is specifically meant for specifying the bundle definition array, so it is not optional
624+ throw new ArgumentException ( "AssetBundleBuild cannot be null." ) ;
603625
604- if ( ! System . IO . Directory . Exists ( outputPath ) )
605- throw new ArgumentException ( "The output path \" " + outputPath + "\" doesn't exist" ) ;
626+ BuildAssetBundlesParameters input = new BuildAssetBundlesParameters
627+ {
628+ outputPath = outputPath ,
629+ bundleDefinitions = builds ,
630+ options = assetBundleOptions ,
631+ targetPlatform = targetPlatform ,
632+ subtarget = EditorUserBuildSettings . GetActiveSubtargetFor ( targetPlatform ) ,
633+ } ;
606634
607- return BuildAssetBundlesInternal ( outputPath , assetBundleOptions , targetPlatformGroup , targetPlatform , subtarget ) ;
635+ return BuildAssetBundles ( input ) ;
608636 }
609637
610- [ NativeThrows ]
611- private static extern AssetBundleManifest BuildAssetBundlesInternal ( string outputPath , BuildAssetBundleOptions assetBundleOptions , BuildTargetGroup targetPlatformGroup , BuildTarget targetPlatform , int subtarget ) ;
612-
613- public static AssetBundleManifest BuildAssetBundles ( string outputPath , AssetBundleBuild [ ] builds , BuildAssetBundleOptions assetBundleOptions , BuildTarget targetPlatform )
638+ public static AssetBundleManifest BuildAssetBundles ( BuildAssetBundlesParameters buildParameters )
614639 {
615- BuildTargetGroup targetPlatformGroup = BuildPipeline . GetBuildTargetGroup ( targetPlatform ) ;
616- int subtarget = EditorUserBuildSettings . GetActiveSubtargetFor ( targetPlatform ) ;
617- return BuildAssetBundles ( outputPath , builds , assetBundleOptions , targetPlatformGroup , targetPlatform , subtarget ) ;
618- }
640+ if ( buildParameters . targetPlatform == 0 || buildParameters . targetPlatform == BuildTarget . NoTarget )
641+ {
642+ buildParameters . targetPlatform = EditorUserBuildSettings . activeBuildTarget ;
643+
644+ // Note: subtarget is associated with multiple enums, and 0 may have a specific meaning,
645+ // so we only auto-set it when the target is also coming from the build settings
646+ buildParameters . subtarget = EditorUserBuildSettings . GetActiveSubtargetFor ( buildParameters . targetPlatform ) ;
647+ }
619648
620- internal static AssetBundleManifest BuildAssetBundles ( string outputPath , AssetBundleBuild [ ] builds , BuildAssetBundleOptions assetBundleOptions , BuildTargetGroup targetPlatformGroup , BuildTarget targetPlatform , int subtarget )
621- {
622649 if ( isBuildingPlayer )
623650 throw new InvalidOperationException ( "Cannot build asset bundles while a build is in progress." ) ;
624651
625- if ( ! System . IO . Directory . Exists ( outputPath ) )
626- throw new ArgumentException ( "The output path \" " + outputPath + "\" doesn't exist" ) ;
627-
628- if ( builds == null )
629- throw new ArgumentException ( "AssetBundleBuild cannot be null." ) ;
652+ if ( ! System . IO . Directory . Exists ( buildParameters . outputPath ) )
653+ throw new ArgumentException ( "The output path \" " + buildParameters . outputPath + "\" doesn't exist" ) ;
630654
631- return BuildAssetBundlesWithInfoInternal ( outputPath , builds , assetBundleOptions , targetPlatformGroup , targetPlatform , subtarget ) ;
655+ return BuildAssetBundlesInternal ( buildParameters ) ;
632656 }
633657
634658 [ NativeThrows ]
635- private static extern AssetBundleManifest BuildAssetBundlesWithInfoInternal ( string outputPath , AssetBundleBuild [ ] builds , BuildAssetBundleOptions assetBundleOptions , BuildTargetGroup targetPlatformGroup , BuildTarget targetPlatform , int subtarget ) ;
659+ private static extern AssetBundleManifest BuildAssetBundlesInternal ( BuildAssetBundlesParameters buildParameters ) ;
636660
637661 [ FreeFunction ( "GetPlayerDataSessionId" ) ]
638662 internal static extern string GetSessionIdForBuildTarget ( BuildTarget target , int subtarget ) ;
0 commit comments