/** * 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); }
/// <summary> /// Converts an RGBAImage object into a byte array that can be loaded into a texture. /// </summary> /// <param name="image">The Imgae object to convert.</param> /// <param name="format">The resulting texture format/compression.</param> /// <param name="mipmaps">Whether to generate mipmaps for the texture.</param> /// <returns> /// A byte array that can be loaded into a Unity Texture2D. /// </returns> public static byte[] ImageToTexture(RGBAImage image, TextureCompressionFormat format = TextureCompressionFormat.DXT5, bool mipmaps = true) { // Retrieve the raw pixel data from the image. byte[] srcBytes = new byte[image.Size]; image.CopyRawData(srcBytes); /* * Allocate a handle for the pixel data so that it doesn't get garbage collected. * This will allow a the pixel array to be reprsented as an pointer so that it * can be used by the Nvidia Texture Tools. */ GCHandle pinnedArray = GCHandle.Alloc(srcBytes, GCHandleType.Pinned); IntPtr srcBytesPtr = pinnedArray.AddrOfPinnedObject(); /* * Initialize an array to store the generated data with a size of zero. The array * will be resized as needed. A wrapper is used so that the array can be resized * within the lambda callback expression in the OutputOptions. */ BytesWrapper destBytes = new BytesWrapper() { Bytes = new byte[0] }; InputOptions inputOptions = GenerateInputOptions(srcBytesPtr, image.Width, image.Height, mipmaps); CompressionOptions compressionOptions = GenerateCompressionOptions(format); OutputOptions outputOptions = GenerateOutputOptions(destBytes); Compressor compressor = new Compressor(); compressor.Compress(inputOptions, compressionOptions, outputOptions); // Free the allocated handle so that it be garbage collected. pinnedArray.Free(); return(destBytes.Bytes); }
public static bool BuildBundleWithAssetPacks(BuildPlayerOptions buildPlayerOptions, MobileTextureSubtarget mobileTextureSubtarget, string buildPath) { TextureCompressionFormat textureCompressionFormat = ToTextureCompressionFormat(mobileTextureSubtarget); return(BuildBundleWithAssetPacks(buildPlayerOptions, textureCompressionFormat, buildPath)); }
public static bool BuildBundleWithAssetPacks(BuildPlayerOptions buildPlayerOptions, TextureCompressionFormat textureCompressionFormat, string buildPath) { if (buildPlayerOptions.target != BuildTarget.Android) { return(false); } return(AppBundlePublisher.Build(buildPlayerOptions, CreateAssetPacks(textureCompressionFormat, buildPath))); }
public AssetPack CreateAssetPack(TextureCompressionFormat textureCompressionFormat, string path) { return(Schema.CreateAssetPack(path, textureCompressionFormat)); }