using System;
using UnityEditor.AssetImporters;
using UnityEngine;
namespace UnityEditor.U2D.Aseprite
{
public partial class AsepriteImporter
{
///
/// A parsed representation of the Aseprite file.
///
public AsepriteFile asepriteFile => m_AsepriteFile;
///
/// How the file should be imported.
///
public FileImportModes importMode
{
get => m_AsepriteImporterSettings.fileImportMode;
set => m_AsepriteImporterSettings.fileImportMode = value;
}
///
/// Which type of texture are we dealing with here.
///
/// Valid values are TextureImporterType.Default or TextureImporterType.Sprite.
/// Exception when non valid values are set.
public TextureImporterType textureType
{
get => m_TextureImporterSettings.textureType;
set
{
if (value == TextureImporterType.Sprite || value == TextureImporterType.Default)
{
m_TextureImporterSettings.textureType = value;
SetDirty();
}
else
throw new System.ArgumentException("Invalid value. Valid values are TextureImporterType.Sprite or TextureImporterType.Default");
}
}
///
/// Selects Single or Manual import mode for Sprite textures.
///
/// Valid values are SpriteImportMode.Multiple or SpriteImportMode.Single.
/// Exception when non valid values are set.
public SpriteImportMode spriteImportMode
{
get => (SpriteImportMode)m_TextureImporterSettings.spriteMode;
set
{
if (value == SpriteImportMode.Multiple || value == SpriteImportMode.Single)
{
m_TextureImporterSettings.spriteMode = (int)value;
SetDirty();
}
else
throw new System.ArgumentException("Invalid value. Valid values are SpriteImportMode.Multiple or SpriteImportMode.Single");
}
}
///
/// The number of pixels in the sprite that correspond to one unit in world space.
///
public float spritePixelsPerUnit
{
get => m_TextureImporterSettings.spritePixelsPerUnit;
set
{
var newPpu = Mathf.Max(1f, value);
m_TextureImporterSettings.spritePixelsPerUnit = newPpu;
SetDirty();
}
}
///
/// Sets the type of mesh to ge generated for each Sprites.
///
public SpriteMeshType spriteMeshType
{
get => m_TextureImporterSettings.spriteMeshType;
set
{
m_TextureImporterSettings.spriteMeshType = value;
SetDirty();
}
}
///
/// If enabled, generates a default physics shape from the outline of the Sprite/s when a physics shape has not been set in the Sprite Editor.
///
public bool generatePhysicsShape
{
get => m_GeneratePhysicsShape;
set
{
m_GeneratePhysicsShape = value;
SetDirty();
}
}
///
/// The number of blank pixels to leave between the edge of the graphic and the mesh.
///
public uint spriteExtrude
{
get => m_TextureImporterSettings.spriteExtrude;
set
{
m_TextureImporterSettings.spriteExtrude = value;
SetDirty();
}
}
///
/// The canvas size of the source file.
///
public Vector2 canvasSize => m_CanvasSize;
///
/// Should include hidden layers from the source file.
///
public bool includeHiddenLayers
{
get => m_AsepriteImporterSettings.importHiddenLayers;
set => m_AsepriteImporterSettings.importHiddenLayers = value;
}
///
/// The import mode for all layers in the file.
///
public LayerImportModes layerImportMode
{
get => m_AsepriteImporterSettings.layerImportMode;
set => m_AsepriteImporterSettings.layerImportMode = value;
}
///
/// The space the Sprite pivots are being calculated.
///
public PivotSpaces pivotSpace
{
get => m_AsepriteImporterSettings.defaultPivotSpace;
set => m_AsepriteImporterSettings.defaultPivotSpace = value;
}
///
/// How a Sprite's graphic rectangle is aligned with its pivot point.
///
public SpriteAlignment pivotAlignment
{
get => m_AsepriteImporterSettings.defaultPivotAlignment;
set => m_AsepriteImporterSettings.defaultPivotAlignment = value;
}
///
/// Normalized position of the custom pivot.
///
public Vector2 customPivotPosition
{
get => m_AsepriteImporterSettings.customPivotPosition;
set => m_AsepriteImporterSettings.customPivotPosition = value;
}
///
/// External padding between each SpriteRect, in pixels.
///
public uint mosaicPadding
{
get => m_AsepriteImporterSettings.mosaicPadding;
set => m_AsepriteImporterSettings.mosaicPadding = value;
}
///
/// Internal padding within each SpriteRect, in pixels.
///
public uint spritePadding
{
get => m_AsepriteImporterSettings.spritePadding;
set => m_AsepriteImporterSettings.spritePadding = value;
}
///
/// Generate a Model Prefab based on the layers of the source asset.
///
public bool generateModelPrefab
{
get => m_AsepriteImporterSettings.generateModelPrefab;
set => m_AsepriteImporterSettings.generateModelPrefab = value;
}
///
/// Add a Sorting Group component to the root of the generated model prefab if it has more than one Sprite Renderer.
///
public bool addSortingGroup
{
get => m_AsepriteImporterSettings.addSortingGroup;
set
{
m_AsepriteImporterSettings.addSortingGroup = value;
SetDirty();
}
}
#if UNITY_2023_1_OR_NEWER
///
/// Add Shadow Casters to the generated GameObjects with SpriteRenderers.
///
public bool addShadowCasters
{
get => m_AsepriteImporterSettings.addShadowCasters;
set
{
m_AsepriteImporterSettings.addShadowCasters = value;
SetDirty();
}
}
#endif
///
/// Generate Animation Clips based on the frame data of the source asset.
///
public bool generateAnimationClips
{
get => m_AsepriteImporterSettings.generateAnimationClips;
set => m_AsepriteImporterSettings.generateAnimationClips = value;
}
///
/// Texture coordinate wrapping mode.
///
Using wrapMode sets the same wrapping mode on all axes. Different per-axis wrap modes can be set using wrapModeU, wrapModeV, wrapModeW. Querying the value returns the U axis wrap mode (same as wrapModeU getter).
///
public TextureWrapMode wrapMode
{
get => m_TextureImporterSettings.wrapMode;
set
{
m_TextureImporterSettings.wrapMode = value;
SetDirty();
}
}
///
/// Texture U coordinate wrapping mode.
///
Controls wrapping mode along texture U (horizontal) axis.
///
public TextureWrapMode wrapModeU
{
get => m_TextureImporterSettings.wrapModeU;
set
{
m_TextureImporterSettings.wrapModeU = value;
SetDirty();
}
}
///
/// Texture V coordinate wrapping mode.
///
Controls wrapping mode along texture V (vertical) axis.
///
public TextureWrapMode wrapModeV
{
get => m_TextureImporterSettings.wrapModeV;
set
{
m_TextureImporterSettings.wrapModeV = value;
SetDirty();
}
}
///
/// Texture W coordinate wrapping mode for Texture3D.
///
Controls wrapping mode along texture W (depth, only relevant for Texture3D) axis.
///
public TextureWrapMode wrapModeW
{
get => m_TextureImporterSettings.wrapModeW;
set
{
m_TextureImporterSettings.wrapModeW = value;
SetDirty();
}
}
///
/// Filtering mode of the texture.
///
public FilterMode filterMode
{
get => m_TextureImporterSettings.filterMode;
set
{
m_TextureImporterSettings.filterMode = value;
SetDirty();
}
}
///
/// Anisotropic filtering level of the texture.
///
public int aniso
{
get => m_TextureImporterSettings.aniso;
set
{
m_TextureImporterSettings.aniso = value;
SetDirty();
}
}
#if UNITY_2022_2_OR_NEWER
///
/// Whether this texture stores data in sRGB (also called gamma) color space.
///
public bool sRGBTexture
{
get => m_TextureImporterSettings.sRGBTexture;
set
{
m_TextureImporterSettings.sRGBTexture = value;
SetDirty();
}
}
#endif
///
/// Mip map bias of the texture.
///
public float mipMapBias
{
get => m_TextureImporterSettings.mipmapBias;
set
{
m_TextureImporterSettings.mipmapBias = value;
SetDirty();
}
}
///
/// Generate Mip Maps.
///
Select this to enable mip-map generation. Mipmaps are smaller versions of the Texture that get used when the Texture is very small on screen.
///
public bool mipmapEnabled
{
get => m_TextureImporterSettings.mipmapEnabled;
set
{
m_TextureImporterSettings.mipmapEnabled = value;
SetDirty();
}
}
///
/// Mip level where texture is faded out completely.
///
public int mipmapFadeDistanceEnd
{
get => m_TextureImporterSettings.mipmapFadeDistanceEnd;
set
{
m_TextureImporterSettings.mipmapFadeDistanceEnd = value;
SetDirty();
}
}
///
/// Mip level where texture begins to fade out.
///
public int mipmapFadeDistanceStart
{
get => m_TextureImporterSettings.mipmapFadeDistanceStart;
set
{
m_TextureImporterSettings.mipmapFadeDistanceEnd = value;
SetDirty();
}
}
///
/// Enable mipmap streaming for the texture.
///
Only load larger mipmaps as needed to render the current game cameras. Requires texture streaming to be enabled in quality settings.
///
public bool streamingMipmaps
{
get => m_TextureImporterSettings.streamingMipmaps;
set
{
m_TextureImporterSettings.streamingMipmaps = value;
SetDirty();
}
}
///
/// Mipmap streaming priority when there's contention for resources. Positive numbers represent higher priority. Valid range is -128 to 127.
///
public int streamingMipmapsPriority
{
get => m_TextureImporterSettings.streamingMipmapsPriority;
set
{
m_TextureImporterSettings.streamingMipmapsPriority = Mathf.Clamp(value, -128, 127);
SetDirty();
}
}
///
/// Mip level where texture is faded out completely.
///
public TextureImporterMipFilter mipmapFilter
{
get => m_TextureImporterSettings.mipmapFilter;
set
{
m_TextureImporterSettings.mipmapFilter = value;
SetDirty();
}
}
///
/// Enables or disables coverage-preserving alpha mipmapping.
///
Enable this to rescale the alpha values of computed mipmaps so coverage is preserved. This means a higher percentage of pixels passes the alpha test and lower mipmap levels do not become more transparent. This is disabled by default (set to false).
///
public bool mipMapsPreserveCoverage
{
get => m_TextureImporterSettings.mipMapsPreserveCoverage;
set
{
m_TextureImporterSettings.mipMapsPreserveCoverage = value;
SetDirty();
}
}
///
/// Retrieves the platform settings used by the importer for a given build target.
///
/// The build target to query.
/// TextureImporterPlatformSettings used for importing the texture for the build target.
public TextureImporterPlatformSettings GetImporterPlatformSettings(BuildTarget buildTarget)
{
return TextureImporterPlatformUtilities.GetPlatformTextureSettings(buildTarget, m_PlatformSettings);
}
///
/// Sets the platform settings used by the importer for a given build target.
///
/// TextureImporterPlatformSettings to be used by the importer for the build target indicated by TextureImporterPlatformSettings.
public void SetImporterPlatformSettings(TextureImporterPlatformSettings setting)
{
SetPlatformTextureSettings(setting);
SetDirty();
}
///
/// Structure used for Aseprite Import Events.
///
public readonly struct ImportEventArgs
{
///
/// The Aseprite Importer that fired the event.
///
public readonly AsepriteImporter importer;
///
/// The Asset Import Context that is being used for the import.
///
public readonly AssetImportContext context;
///
/// Constructor for ImportEventArgs.
///
/// The Aseprite Importer that fired the event.
/// The Asset Import Context that is being used for the import.
public ImportEventArgs(AsepriteImporter importer, AssetImportContext context)
{
this.importer = importer;
this.context = context;
}
}
///
/// Delegate for Aseprite Import Events.
///
/// The ImportEventArgs that are being used for the import.
public delegate void AsepriteImportEventHandler(ImportEventArgs args);
///
/// Event that is fired at the last step of the Aseprite import process.
///
public AsepriteImportEventHandler OnPostAsepriteImport { get; set; }
}
}