/// <summary> /// Builds an Android App Bundle at a location specified in a file save dialog. /// The AAB will include asset packs configured in Asset Delivery Settings. /// </summary> public static void Build() { // Check that we're ready to build before displaying the file save dialog. var appBundleBuilder = CreateAppBundleBuilder(); if (!appBundleBuilder.Initialize(new BuildToolLogger())) { return; } var aabFilePath = EditorUtility.SaveFilePanel("Create Android App Bundle", null, null, "aab"); if (string.IsNullOrEmpty(aabFilePath)) { // Assume cancelled. return; } var buildSettings = new AppBundleBuildSettings { buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(aabFilePath), assetPackConfig = AssetPackConfigSerializer.LoadConfig() }; Build(appBundleBuilder, buildSettings); }
/// <summary> /// First builds the current project as an APK or Android App Bundle, and then installs and runs it on a /// connected Android device. /// </summary> private static void BuildAndRunDefault() { var assetPackConfig = AssetPackConfigSerializer.LoadConfig(); if (assetPackConfig.HasDeliveredAssetPacks()) { AppBundlePublisher.BuildAndRun(assetPackConfig); } else { EmulateUnityBuildAndRun(); } }
public static void Configure() { if (!DisplayDeletionWarning("Configure Asset Delivery Demo")) { return; } AssetPackConfigSerializer.SaveConfig(CreateAssetPackConfig()); Debug.Log( "Configured Asset Delivery settings for sample app. " + "Select the AssetDeliveryDemo scene in build settings and run \"Google -> Build & Run\" to test the " + "Asset Delivery demo."); }
/// <summary> /// Builds an Android App Bundle to a temp directory and then runs it on device. /// </summary> public static void BuildAndRun() { var buildSettings = new AppBundleBuildSettings { requirePrerequisiteChecks = true, runOnDevice = true }; var appBundleBuilder = CreateAppBundleBuilder(); var tempOutputFilePath = Path.Combine(appBundleBuilder.WorkingDirectoryPath, "temp.aab"); var buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(tempOutputFilePath); var assetPackConfig = AssetPackConfigSerializer.LoadConfig(); Build(appBundleBuilder, buildPlayerOptions, assetPackConfig, buildSettings); }
/// <summary> /// Builds an Android App Bundle to a temp directory and then runs it on device. /// The AAB will include asset packs configured in Asset Delivery Settings. /// </summary> public static void BuildAndRun() { var appBundleBuilder = CreateAppBundleBuilder(); if (!appBundleBuilder.Initialize(new BuildToolLogger())) { return; } var tempOutputFilePath = Path.Combine(appBundleBuilder.WorkingDirectoryPath, "temp.aab"); var buildSettings = new AppBundleBuildSettings { buildPlayerOptions = AndroidBuildHelper.CreateBuildPlayerOptions(tempOutputFilePath), assetPackConfig = AssetPackConfigSerializer.LoadConfig(), runOnDevice = true }; Build(appBundleBuilder, buildSettings); }
/** * Create the Play Asset Delivery configuration. */ public static AssetPackConfig CreateAssetPacks(TextureCompressionFormat textureCompressionFormat, string buildPath = null) { if (string.IsNullOrEmpty(buildPath)) { buildPath = GetLocalBuildPath(); } Debug.LogFormat("[{0}.{1}] path={2}", nameof(AssetPackBuilder), nameof(CreateAssetPacks), buildPath); AssetPackConfig assetPackConfig = new AssetPackConfig { DefaultTextureCompressionFormat = textureCompressionFormat }; if (!Directory.Exists(buildPath)) { return(null); } var bundles = GetBundles(buildPath); if (Directory.Exists(BuildPath)) { Directory.Delete(BuildPath, true); } Directory.CreateDirectory(BuildPath); foreach (var bundle in bundles) { string targetPath = Path.Combine(BuildPath, bundle.Name); Directory.CreateDirectory(targetPath); string bundlePath = Path.Combine(targetPath, Path.GetFileNameWithoutExtension(bundle.Bundle)); File.Copy(bundle.Bundle, bundlePath); assetPackConfig.AssetPacks.Add(bundle.Name, bundle.CreateAssetPack(textureCompressionFormat, bundlePath)); } WriteAssetPackConfig(bundles); AssetPackConfigSerializer.SaveConfig(assetPackConfig); return(assetPackConfig); }
static void BuildRTAssets_AssetPacks_Scripted() { // Save the current setting MobileTextureSubtarget originalSetting = EditorUserBuildSettings.androidBuildSubtarget; // Clean out any old data DeleteTargetDirectory(streamingName); DeleteTargetDirectory(assetPacksName); // Build the AssetBundles, both in ETC2 and ASTC texture formats BuildAssetBundles(assetPacksName, astcSuffix, MobileTextureSubtarget.ASTC); BuildAssetBundles(assetPacksName, "", MobileTextureSubtarget.ETC2); AssetDatabase.Refresh(); // Copy our discrete test image asset into a new directory // which will be used for the 'discrete' asset pack source string discreteFileName = "Discrete1.jpg"; string discretePackName = "discretepack"; string discretePath = Path.Combine(Path.GetTempPath(), discretePackName); Directory.CreateDirectory(discretePath); string destPath = Path.Combine(discretePath, discreteFileName); if (File.Exists(destPath)) { File.Delete(destPath); } string sourcePath = Path.Combine(Application.dataPath, "Images"); sourcePath = Path.Combine(sourcePath, discreteFileName); File.Copy(sourcePath, destPath); Debug.Log("Copied discrete file to : " + destPath); // Create an AssetPackConfig and start creating asset packs AssetPackConfig assetPackConfig = new AssetPackConfig(); // Create asset packs using AssetBundles string assetBundlePath = Path.Combine(Application.dataPath, assetPacksName); // Add the default ETC2 bundles assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath, "installtime"), AssetPackDeliveryMode.InstallTime); assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath, "fastfollow"), AssetPackDeliveryMode.FastFollow); assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath, "ondemand"), AssetPackDeliveryMode.OnDemand); // Add the ASTC bundles assetBundlePath += astcSuffix; assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath, "installtime"), AssetPackDeliveryMode.InstallTime); assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath, "fastfollow"), AssetPackDeliveryMode.FastFollow); assetPackConfig.AddAssetBundle(Path.Combine(assetBundlePath, "ondemand"), AssetPackDeliveryMode.OnDemand); // Create an asset pack from our discrete directory assetPackConfig.AddAssetsFolder(discretePackName, discretePath, AssetPackDeliveryMode.OnDemand); // Configures the build system to use the newly created // assetPackConfig when calling Google > Build and Run or // Google > Build Android App Bundle. AssetPackConfigSerializer.SaveConfig(assetPackConfig); EditorUserBuildSettings.androidBuildSubtarget = originalSetting; }