protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TextureAsset asset, AssetCompilerResult result) { if (asset.Source == null) { result.Error("Source cannot be null for Texture Asset [{0}]", asset); return; } // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, asset.Source); result.BuildSteps = new ListBuildStep { new TextureConvertCommand(urlInStorage, new TextureConvertParameters(assetSource, asset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), false)) }; }
protected Dictionary <TImageInfo, int> CompileGroup(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TGroupAsset asset, AssetCompilerResult result) { result.BuildSteps = new AssetBuildStep(AssetItem); // Evaluate if we need to use a separate the alpha texture SeparateAlphaTexture = TextureCommandHelper.ShouldSeparateAlpha(asset.Alpha, asset.Format, context.Platform, context.GetGraphicsProfile()); // create the registry containing the sprite assets texture index association var imageToTextureIndex = new Dictionary <TImageInfo, int>(); // create and add import texture commands if (asset.Images != null) { // sort sprites by referenced texture. var spriteByTextures = asset.Images.GroupBy(x => x.Source).ToArray(); for (int i = 0; i < spriteByTextures.Length; i++) { // skip the texture if the file is not valid. var textureFile = spriteByTextures[i].Key; if (!TextureFileIsValid(textureFile)) { continue; } var spriteAssetArray = spriteByTextures[i].ToArray(); foreach (var spriteAsset in spriteAssetArray) { imageToTextureIndex[spriteAsset] = i; } // create an texture asset. var textureAsset = new TextureAsset { Id = Guid.Empty, // CAUTION: It is important to use an empty GUID here, as we don't want the command to be rebuilt (by default, a new asset is creating a new guid) Alpha = asset.Alpha, Format = asset.Format, GenerateMipmaps = asset.GenerateMipmaps, PremultiplyAlpha = asset.PremultiplyAlpha, ColorKeyColor = asset.ColorKeyColor, ColorKeyEnabled = asset.ColorKeyEnabled, }; // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, spriteAssetArray[0].Source); // add the texture build command. result.BuildSteps.Add( new TextureAssetCompiler.TextureConvertCommand( ImageGroupAsset.BuildTextureUrl(urlInStorage, i), new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), SeparateAlphaTexture))); } result.BuildSteps.Add(new WaitBuildStep()); // wait the textures to be imported } return(imageToTextureIndex); }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TextureAsset asset, AssetCompilerResult result) { if (!EnsureSourceExists(result, asset, assetAbsolutePath)) { return; } // Get absolute path of asset source on disk var assetSource = GetAbsolutePath(assetAbsolutePath, asset.Source); var parameter = new TextureConvertParameters(assetSource, asset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality()); result.BuildSteps = new AssetBuildStep(AssetItem) { new TextureConvertCommand(urlInStorage, parameter) }; }
protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TGroupAsset asset, AssetCompilerResult result) { result.BuildSteps = new ListBuildStep(); // Evaluate if we need to use a separate the alpha texture SeparateAlphaTexture = context.Platform == PlatformType.Android && asset.Alpha != AlphaFormat.None && asset.Format == TextureFormat.Compressed; // create the registry containing the sprite assets texture index association SpriteToTextureIndex = new Dictionary <TImageInfo, int>(); // create and add import texture commands if (asset.Images != null) { // return compilation error if one or more of the sprite does not have a valid texture var noSourceAsset = asset.Images.FirstOrDefault(x => !TextureFileIsValid(x.Source)); if (noSourceAsset != null) { result.Error("The texture of image '{0}' either does not exist or is invalid", noSourceAsset.Name); return; } // sort sprites by referenced texture. var spriteByTextures = asset.Images.GroupBy(x => x.Source).ToArray(); for (int i = 0; i < spriteByTextures.Length; i++) { var spriteAssetArray = spriteByTextures[i].ToArray(); foreach (var spriteAsset in spriteAssetArray) { SpriteToTextureIndex[spriteAsset] = i; } // create an texture asset. var textureAsset = new TextureAsset { Id = Guid.Empty, // CAUTION: It is important to use an empty GUID here, as we don't want the command to be rebuilt (by default, a new asset is creating a new guid) Alpha = asset.Alpha, Format = asset.Format, GenerateMipmaps = asset.GenerateMipmaps, PremultiplyAlpha = asset.PremultiplyAlpha, ColorKeyColor = asset.ColorKeyColor, ColorKeyEnabled = asset.ColorKeyEnabled, }; // Get absolute path of asset source on disk var assetDirectory = assetAbsolutePath.GetParent(); var assetSource = UPath.Combine(assetDirectory, spriteAssetArray[0].Source); // add the texture build command. result.BuildSteps.Add( new TextureAssetCompiler.TextureConvertCommand( ImageGroupAsset.BuildTextureUrl(urlInStorage, i), new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), SeparateAlphaTexture))); } result.BuildSteps.Add(new WaitBuildStep()); // wait the textures to be imported } }