static TextureGenerationOutput GenerateTexture(NativeArray <Color32> imageBuffer, int imageBufferWidth, int imageBufferHeight, TextureImporterType type, TextureImporterPlatformSettings platformSettings, params ITextureSettings[] otherSettings) { var textureGenerationSettings = new TextureGenerationSettings(); textureGenerationSettings.platformSettings = platformSettings; textureGenerationSettings.sourceTextureInformation = new SourceTextureInformation(); textureGenerationSettings.sourceTextureInformation.height = imageBufferHeight; textureGenerationSettings.sourceTextureInformation.width = imageBufferWidth; textureGenerationSettings.textureImporterSettings = new TextureImporterSettings(); textureGenerationSettings.textureImporterSettings.textureType = type; textureGenerationSettings.textureImporterSettings.textureShape = TextureImporterShape.Texture2D; textureGenerationSettings.textureImporterSettings.alphaIsTransparency = false; textureGenerationSettings.textureImporterSettings.convertToNormalMap = false; textureGenerationSettings.textureImporterSettings.mipmapEnabled = false; textureGenerationSettings.textureImporterSettings.sRGBTexture = true; textureGenerationSettings.textureImporterSettings.readable = false; textureGenerationSettings.textureImporterSettings.fadeOut = false; textureGenerationSettings.textureImporterSettings.wrapMode = TextureWrapMode.Repeat; textureGenerationSettings.textureImporterSettings.wrapModeU = TextureWrapMode.Repeat; textureGenerationSettings.textureImporterSettings.wrapModeV = TextureWrapMode.Repeat; textureGenerationSettings.textureImporterSettings.wrapModeW = TextureWrapMode.Repeat; foreach (var otherSetting in otherSettings) { if (otherSetting != null) { otherSetting.FillTextureGenerationSettings(ref textureGenerationSettings); } } return(TextureGenerator.GenerateTexture(textureGenerationSettings, imageBuffer)); }
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings) { settings.textureImporterSettings.wrapMode = wrapMode; settings.textureImporterSettings.wrapModeU = wrapModeU; settings.textureImporterSettings.wrapModeV = wrapModeV; settings.textureImporterSettings.wrapModeW = wrapModeW; }
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings) { settings.textureImporterSettings.textureShape = TextureImporterShape.TextureCube; settings.textureImporterSettings.cubemapConvolution = convolution; settings.textureImporterSettings.generateCubemap = mode; settings.textureImporterSettings.seamlessCubemap = seamless; }
private void GenerateTexture(string assetPath) { SourceTextureInformation textureInformation = new SourceTextureInformation() { containsAlpha = true, hdr = false, height = textureHeight, width = textureWidth }; TextureImporterPlatformSettings platformSettings = new TextureImporterPlatformSettings() { overridden = false }; TextureGenerationSettings settings = new TextureGenerationSettings() { assetPath = assetPath, spriteImportData = ConvertAseFileSpriteImportDataToUnity(SpriteImportData), textureImporterSettings = TextureImportSettings.ToImporterSettings(), enablePostProcessor = false, sourceTextureInformation = textureInformation, qualifyForSpritePacking = true, platformSettings = platformSettings, spritePackingTag = "aseprite", secondarySpriteTextures = new SecondarySpriteTexture[0] }; TextureGenerationOutput output = TextureGenerator.GenerateTexture(settings, new Unity.Collections.NativeArray <Color32>(atlas.GetPixels32(), Unity.Collections.Allocator.Temp)); Texture = output.texture; thumbnail = output.thumbNail; sprites = output.sprites; }
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings) { settings.textureImporterSettings.spritePixelsPerUnit = pixelsPerUnit; settings.textureImporterSettings.spriteMeshType = meshType; settings.textureImporterSettings.spriteExtrude = extrudeEdges; settings.spritePackingTag = packingTag; settings.qualifyForSpritePacking = qualifyForPacking; settings.spriteImportData = spriteSheetData; }
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings) { settings.textureImporterSettings.mipmapEnabled = true; settings.textureImporterSettings.mipmapFilter = filter; settings.textureImporterSettings.borderMipmap = borderMipmap; settings.textureImporterSettings.fadeOut = fadeout; settings.textureImporterSettings.mipmapFadeDistanceStart = fadeDistanceStart; settings.textureImporterSettings.mipmapFadeDistanceEnd = fadeDistanceEnd; settings.textureImporterSettings.mipMapsPreserveCoverage = preserveCoverage; }
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings) { settings.textureImporterSettings.sRGBTexture = colorTexture; settings.textureImporterSettings.readable = readable; settings.textureImporterSettings.npotScale = npotScale; settings.textureImporterSettings.filterMode = filterMode; settings.textureImporterSettings.aniso = aniso; settings.assetPath = assetPath; settings.enablePostProcessor = enablePostProcessor; settings.sourceTextureInformation.containsAlpha = containsAlpha; settings.sourceTextureInformation.hdr = hdr; }
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings) { settings.textureImporterSettings.normalMapFilter = filter; settings.textureImporterSettings.convertToNormalMap = generateFromGrayScale; settings.textureImporterSettings.heightmapScale = bumpiness; }
void ITextureSettings.FillTextureGenerationSettings(ref TextureGenerationSettings settings) { settings.textureImporterSettings.alphaIsTransparency = alphaSource != TextureImporterAlphaSource.None; settings.textureImporterSettings.alphaSource = alphaSource; settings.textureImporterSettings.alphaTestReferenceValue = alphaTolerance; }
public override void OnImportAsset(AssetImportContext ctx) { name = GetFileName(ctx.assetPath); AseFile aseFile = ReadAseFile(ctx.assetPath); int frameCount = aseFile.Header.Frames; SpriteAtlasBuilder atlasBuilder = new SpriteAtlasBuilder(textureSettings, aseFile.Header.Width, aseFile.Header.Height); Texture2D[] frames = null; if (importType != AseFileImportType.LayerToSprite) { frames = aseFile.GetFrames(textureSettings.ignoreBackground); } else { frames = aseFile.GetLayersAsFrames(); } SpriteImportData[] spriteImportData; //if (textureSettings.transparentMask) //{ // atlas = atlasBuilder.GenerateAtlas(frames, out spriteImportData, textureSettings.transparentColor, false); //} //else //{ // atlas = atlasBuilder.GenerateAtlas(frames, out spriteImportData, false); //} atlas = atlasBuilder.GenerateAtlas(frames, name, out spriteImportData, textureSettings.transparencyMode, false); atlas.filterMode = textureSettings.filterMode; atlas.alphaIsTransparency = textureSettings.transparencyMode == TransparencyMode.Alpha; atlas.wrapMode = textureSettings.wrapMode; atlas.name = "Texture"; MetaData[] metadatas = aseFile.GetMetaData(textureSettings.spritePivot, textureSettings.pixelsPerUnit); List <SecondarySpriteTexture> secondarySpriteTextures = new List <SecondarySpriteTexture>(); // Find any metadata with a secondary texture foreach (var metadata in metadatas) { if (metadata.Type == MetaDataType.SECONDARY_TEXTURE) { var textureName = metadata.Args[0]; var secondaryTextureFrames = aseFile.GetLayerTexture(metadata.LayerIndex, metadata.Layer); Texture2D secondaryTexture = atlasBuilder.GenerateAtlas(secondaryTextureFrames.ToArray(), name, out _, textureSettings.transparencyMode, false); secondaryTexture.alphaIsTransparency = textureSettings.transparencyMode == TransparencyMode.Alpha;; secondaryTexture.wrapMode = textureSettings.wrapMode; secondaryTexture.filterMode = textureSettings.filterMode; secondaryTexture.name = textureName; secondarySpriteTextures.Add(new SecondarySpriteTexture() { name = textureName, texture = secondaryTexture }); } } TextureGenerationSettings generationSettings = new TextureGenerationSettings(); generationSettings.platformSettings = new TextureImporterPlatformSettings(); generationSettings.spriteImportData = spriteImportData; generationSettings.secondarySpriteTextures = secondarySpriteTextures.ToArray(); generationSettings.sourceTextureInformation = new SourceTextureInformation() { width = atlas.width, height = atlas.height, containsAlpha = true, }; generationSettings.textureImporterSettings = new TextureImporterSettings { textureType = TextureImporterType.Sprite, textureShape = TextureImporterShape.Texture2D, alphaIsTransparency = textureSettings.transparencyMode == TransparencyMode.Alpha, alphaSource = TextureImporterAlphaSource.FromInput, spritePixelsPerUnit = textureSettings.pixelsPerUnit, spritePivot = textureSettings.spritePivot, spriteMeshType = SpriteMeshType.Tight, convertToNormalMap = false, mipmapEnabled = false, sRGBTexture = true, readable = false, fadeOut = false, wrapMode = TextureWrapMode.Clamp, wrapModeU = TextureWrapMode.Clamp, wrapModeV = TextureWrapMode.Clamp, wrapModeW = TextureWrapMode.Clamp }; var imageBuffer = atlas.GetRawTextureData <Color32>(); var generatedOutput = TextureGenerator.GenerateTexture(generationSettings, imageBuffer); generatedOutput.texture.name = "Texture"; // Main texture atlas ctx.AddObjectToAsset("Texture", generatedOutput.texture); ctx.SetMainObject(generatedOutput.texture); // Add secondary textures foreach (var secondarySpriteTexture in secondarySpriteTextures) { ctx.AddObjectToAsset("SecondaryTex_" + secondarySpriteTexture.name, secondarySpriteTexture.texture); } // Add sprites foreach (var sprite in generatedOutput.sprites) { ctx.AddObjectToAsset(sprite.name, sprite); } // Add animations if (importType == AseFileImportType.Sprite) { GenerateAnimations(ctx, aseFile, generatedOutput.sprites, metadatas); } switch (importType) { case AseFileImportType.LayerToSprite: case AseFileImportType.Sprite: // ImportSprites(ctx, aseFile, spriteImportData, metadatas); break; case AseFileImportType.Tileset: ImportTileset(ctx, atlas); break; } }