using System; using UnityEditor.AssetImporters; using UnityEditor.U2D.Sprites; using UnityEngine; namespace UnityEditor.U2D.PSD { public partial class PSDImporter : ScriptedImporter, ISpriteEditorDataProvider { /// /// Set this to true if you want texture data to be readable from scripts. Set it to false to prevent scripts from reading texture data. ///

In order for Texture2D.GetPixel, Texture2D.GetPixels, ImageConversion.EncodeToEXR, ImageConversion.EncodeToJPG, ImageConversion.EncodeToPNG and similar functions to work, the Texture must be readable from scripts. The isReadable setting determines whether scripts can access texture data through these functions. ///

Textures are not set as readable by default. ///

When a Texture is not readable, it consumes much less memory because an uncompressed copy of the texture data in system memory is not required after the texture is uploaded to the graphics API. Readable Textures require an uncompressed system memory copy of the texture data so that once edited, the updated texture data can be uploaded to the graphics API. ///
public bool isReadable { get => m_TextureImporterSettings.readable; set { m_TextureImporterSettings.readable = value; SetDirty(); } } /// /// Anisotropic filtering level of the texture. /// public int anisoLevel { get => m_TextureImporterSettings.aniso; set { m_TextureImporterSettings.aniso = value; SetDirty(); } } /// /// Keeps texture borders the same when generating mipmaps. /// public bool borderMipmap { get => m_TextureImporterSettings.borderMipmap; set { m_TextureImporterSettings.borderMipmap = value; SetDirty(); } } /// /// Fades out mip levels to a gray color. /// public bool fadeout { get => m_TextureImporterSettings.fadeOut; set { m_TextureImporterSettings.fadeOut = value; SetDirty(); } } /// /// Filtering mode of the texture. /// public FilterMode filterMode { get => m_TextureImporterSettings.filterMode; set { m_TextureImporterSettings.filterMode = value; SetDirty(); } } /// /// 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(); } } /// /// 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(); } } /// /// 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 { return (SpriteImportMode)m_TextureImporterSettings.spriteMode; } set { if (value == SpriteImportMode.Multiple || value == SpriteImportMode.Single) { m_TextureImporterSettings.spriteMode = (int)value; SetDirty(); } else throw new ArgumentException("Invalid value. Valid values are SpriteImportMode.Multiple or SpriteImportMode.Single"); } } /// /// Sets the type of mesh to ge generated for each Sprites. /// public SpriteMeshType spriteMeshType { get { return m_TextureImporterSettings.spriteMeshType; } set { m_TextureImporterSettings.spriteMeshType = value; SetDirty(); } } /// /// 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 { return (TextureImporterType)m_TextureImporterSettings.textureType; } set { if (value == TextureImporterType.Sprite || value == TextureImporterType.Default) { m_TextureImporterSettings.textureType = value; SetDirty(); } else throw new ArgumentException("Invalid value. Valid values are TextureImporterType.Sprite or TextureImporterType.Default"); } } /// /// 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(); } } /// /// The number of pixels in the sprite that correspond to one unit in world space. /// public float spritePixelsPerUnit { get => m_TextureImporterSettings.spritePixelsPerUnit; set { m_TextureImporterSettings.spritePixelsPerUnit = 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 TextureImporterUtilities.GetPlatformTextureSettings(buildTarget, in 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(); } /// /// Secondary textures for the imported Sprites. /// public SecondarySpriteTexture[] secondarySpriteTextures { get => secondaryTextures; set { secondaryTextures = value; SetDirty(); } } /// /// Sets if importer should generate a prefab as sub-asset. /// To generate a Prefab useMosaicMode needs to be set to true and importer needs to be set to import /// Sprites in multiple mode. /// public bool useCharacterMode { get => m_CharacterMode; set { m_CharacterMode = value; SetDirty(); } } /// /// Sets if importer should generate a mosaic texture from the source layers. /// To generate such texture, the importer needs to be set to import Sprites in multiple mode. /// public bool useMosaicMode { get => m_MosaicLayers; set { m_MosaicLayers = value; SetDirty(); } } /// /// Sets the padding between each Sprites in the mosaic texture. /// public uint mosiacPadding { get => (uint)m_Padding; set { m_Padding = (int)value; SetDirty(); } } /// /// Sets the value to increase the Sprite size by. /// public ushort spriteSizeExpand { get => m_SpriteSizeExpand; set { m_SpriteSizeExpand = value; m_SpriteSizeExpandChanged = true; SetDirty(); } } internal TextureImporterSwizzle swizzleR { get => m_TextureImporterSettings.swizzleR; set { m_TextureImporterSettings.swizzleR = value; SetDirty(); } } internal TextureImporterSwizzle swizzleG { get => m_TextureImporterSettings.swizzleG; set { m_TextureImporterSettings.swizzleG = value; SetDirty(); } } internal TextureImporterSwizzle swizzleB { get => m_TextureImporterSettings.swizzleB; set { m_TextureImporterSettings.swizzleB = value; SetDirty(); } } internal TextureImporterSwizzle swizzleA { get => m_TextureImporterSettings.swizzleA; set { m_TextureImporterSettings.swizzleA = value; SetDirty(); } } internal bool sRGBTexture { get => m_TextureImporterSettings.sRGBTexture; set { m_TextureImporterSettings.sRGBTexture = value; SetDirty(); } } void SetDirty() { EditorUtility.SetDirty(this); } } }