Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

PSDImporterAPI.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. using System;
  2. using UnityEditor.AssetImporters;
  3. using UnityEditor.U2D.Sprites;
  4. using UnityEngine;
  5. namespace UnityEditor.U2D.PSD
  6. {
  7. public partial class PSDImporter : ScriptedImporter, ISpriteEditorDataProvider
  8. {
  9. /// <summary>
  10. /// 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.
  11. /// <br/><br/>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.
  12. /// <br/><br/>Textures are not set as readable by default.
  13. /// <br/><br/>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.
  14. /// </summary>
  15. public bool isReadable
  16. {
  17. get => m_TextureImporterSettings.readable;
  18. set
  19. {
  20. m_TextureImporterSettings.readable = value;
  21. SetDirty();
  22. }
  23. }
  24. /// <summary>
  25. /// Anisotropic filtering level of the texture.
  26. /// </summary>
  27. public int anisoLevel
  28. {
  29. get => m_TextureImporterSettings.aniso;
  30. set
  31. {
  32. m_TextureImporterSettings.aniso = value;
  33. SetDirty();
  34. }
  35. }
  36. /// <summary>
  37. /// Keeps texture borders the same when generating mipmaps.
  38. /// </summary>
  39. public bool borderMipmap
  40. {
  41. get => m_TextureImporterSettings.borderMipmap;
  42. set
  43. {
  44. m_TextureImporterSettings.borderMipmap = value;
  45. SetDirty();
  46. }
  47. }
  48. /// <summary>
  49. /// Fades out mip levels to a gray color.
  50. /// </summary>
  51. public bool fadeout
  52. {
  53. get => m_TextureImporterSettings.fadeOut;
  54. set
  55. {
  56. m_TextureImporterSettings.fadeOut = value;
  57. SetDirty();
  58. }
  59. }
  60. /// <summary>
  61. /// Filtering mode of the texture.
  62. /// </summary>
  63. public FilterMode filterMode
  64. {
  65. get => m_TextureImporterSettings.filterMode;
  66. set
  67. {
  68. m_TextureImporterSettings.filterMode = value;
  69. SetDirty();
  70. }
  71. }
  72. /// <summary>
  73. /// Mip map bias of the texture.
  74. /// </summary>
  75. public float mipMapBias
  76. {
  77. get => m_TextureImporterSettings.mipmapBias;
  78. set
  79. {
  80. m_TextureImporterSettings.mipmapBias = value;
  81. SetDirty();
  82. }
  83. }
  84. /// <summary>
  85. /// Generate Mip Maps.
  86. /// <br/><br/>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.
  87. /// </summary>
  88. public bool mipmapEnabled
  89. {
  90. get => m_TextureImporterSettings.mipmapEnabled;
  91. set
  92. {
  93. m_TextureImporterSettings.mipmapEnabled = value;
  94. SetDirty();
  95. }
  96. }
  97. /// <summary>
  98. /// Mip level where texture is faded out completely.
  99. /// </summary>
  100. public int mipmapFadeDistanceEnd
  101. {
  102. get => m_TextureImporterSettings.mipmapFadeDistanceEnd;
  103. set
  104. {
  105. m_TextureImporterSettings.mipmapFadeDistanceEnd = value;
  106. SetDirty();
  107. }
  108. }
  109. /// <summary>
  110. /// Mip level where texture begins to fade out.
  111. /// </summary>
  112. public int mipmapFadeDistanceStart
  113. {
  114. get => m_TextureImporterSettings.mipmapFadeDistanceStart;
  115. set
  116. {
  117. m_TextureImporterSettings.mipmapFadeDistanceEnd = value;
  118. SetDirty();
  119. }
  120. }
  121. /// <summary>
  122. /// Mip level where texture is faded out completely.
  123. /// </summary>
  124. public TextureImporterMipFilter mipmapFilter
  125. {
  126. get => m_TextureImporterSettings.mipmapFilter;
  127. set
  128. {
  129. m_TextureImporterSettings.mipmapFilter = value;
  130. SetDirty();
  131. }
  132. }
  133. /// <summary>
  134. /// Enables or disables coverage-preserving alpha mipmapping.
  135. /// <br/><br/>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).
  136. /// </summary>
  137. public bool mipMapsPreserveCoverage
  138. {
  139. get => m_TextureImporterSettings.mipMapsPreserveCoverage;
  140. set
  141. {
  142. m_TextureImporterSettings.mipMapsPreserveCoverage = value;
  143. SetDirty();
  144. }
  145. }
  146. /// <summary>
  147. /// Selects Single or Manual import mode for Sprite textures.
  148. /// </summary>
  149. /// <value>Valid values are SpriteImportMode.Multiple or SpriteImportMode.Single.</value>
  150. /// <exception cref="ArgumentException">Exception when non valid values are set.</exception>
  151. public SpriteImportMode spriteImportMode
  152. {
  153. get { return (SpriteImportMode)m_TextureImporterSettings.spriteMode; }
  154. set
  155. {
  156. if (value == SpriteImportMode.Multiple || value == SpriteImportMode.Single)
  157. {
  158. m_TextureImporterSettings.spriteMode = (int)value;
  159. SetDirty();
  160. }
  161. else
  162. throw new ArgumentException("Invalid value. Valid values are SpriteImportMode.Multiple or SpriteImportMode.Single");
  163. }
  164. }
  165. /// <summary>
  166. /// Sets the type of mesh to ge generated for each Sprites.
  167. /// </summary>
  168. public SpriteMeshType spriteMeshType
  169. {
  170. get { return m_TextureImporterSettings.spriteMeshType; }
  171. set
  172. {
  173. m_TextureImporterSettings.spriteMeshType = value;
  174. SetDirty();
  175. }
  176. }
  177. /// <summary>
  178. /// Which type of texture are we dealing with here.
  179. /// </summary>
  180. /// <value>Valid values are TextureImporterType.Default or TextureImporterType.Sprite.</value>
  181. /// <exception cref="ArgumentException">Exception when non valid values are set.</exception>
  182. public TextureImporterType textureType
  183. {
  184. get { return (TextureImporterType)m_TextureImporterSettings.textureType; }
  185. set
  186. {
  187. if (value == TextureImporterType.Sprite || value == TextureImporterType.Default)
  188. {
  189. m_TextureImporterSettings.textureType = value;
  190. SetDirty();
  191. }
  192. else
  193. throw new ArgumentException("Invalid value. Valid values are TextureImporterType.Sprite or TextureImporterType.Default");
  194. }
  195. }
  196. /// <summary>
  197. /// Texture coordinate wrapping mode.
  198. /// <br/><br/>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).
  199. /// </summary>
  200. public TextureWrapMode wrapMode
  201. {
  202. get => m_TextureImporterSettings.wrapMode;
  203. set
  204. {
  205. m_TextureImporterSettings.wrapMode = value;
  206. SetDirty();
  207. }
  208. }
  209. /// <summary>
  210. /// Texture U coordinate wrapping mode.
  211. /// <br/><br/>Controls wrapping mode along texture U (horizontal) axis.
  212. /// </summary>
  213. public TextureWrapMode wrapModeU
  214. {
  215. get => m_TextureImporterSettings.wrapModeU;
  216. set
  217. {
  218. m_TextureImporterSettings.wrapModeU = value;
  219. SetDirty();
  220. }
  221. }
  222. /// <summary>
  223. /// Texture V coordinate wrapping mode.
  224. /// <br/><br/>Controls wrapping mode along texture V (vertical) axis.
  225. /// </summary>
  226. public TextureWrapMode wrapModeV
  227. {
  228. get => m_TextureImporterSettings.wrapModeV;
  229. set
  230. {
  231. m_TextureImporterSettings.wrapModeV = value;
  232. SetDirty();
  233. }
  234. }
  235. /// <summary>
  236. /// Texture W coordinate wrapping mode for Texture3D.
  237. /// <br/><br/>Controls wrapping mode along texture W (depth, only relevant for Texture3D) axis.
  238. /// </summary>
  239. public TextureWrapMode wrapModeW
  240. {
  241. get => m_TextureImporterSettings.wrapModeW;
  242. set
  243. {
  244. m_TextureImporterSettings.wrapModeW = value;
  245. SetDirty();
  246. }
  247. }
  248. /// <summary>
  249. /// The number of pixels in the sprite that correspond to one unit in world space.
  250. /// </summary>
  251. public float spritePixelsPerUnit
  252. {
  253. get => m_TextureImporterSettings.spritePixelsPerUnit;
  254. set
  255. {
  256. m_TextureImporterSettings.spritePixelsPerUnit = value;
  257. SetDirty();
  258. }
  259. }
  260. /// <summary>
  261. /// Retrieves the platform settings used by the importer for a given build target.
  262. /// </summary>
  263. /// <param name="buildTarget">The build target to query.</param>
  264. /// <returns>TextureImporterPlatformSettings used for importing the texture for the build target.</returns>
  265. public TextureImporterPlatformSettings GetImporterPlatformSettings(BuildTarget buildTarget)
  266. {
  267. return TextureImporterUtilities.GetPlatformTextureSettings(buildTarget, in m_PlatformSettings);
  268. }
  269. /// <summary>
  270. /// Sets the platform settings used by the importer for a given build target.
  271. /// </summary>
  272. /// <param name="setting">TextureImporterPlatformSettings to be used by the importer for the build target indicated by TextureImporterPlatformSettings.</param>
  273. public void SetImporterPlatformSettings(TextureImporterPlatformSettings setting)
  274. {
  275. SetPlatformTextureSettings(setting);
  276. SetDirty();
  277. }
  278. /// <summary>
  279. /// Secondary textures for the imported Sprites.
  280. /// </summary>
  281. public SecondarySpriteTexture[] secondarySpriteTextures
  282. {
  283. get => secondaryTextures;
  284. set
  285. {
  286. secondaryTextures = value;
  287. SetDirty();
  288. }
  289. }
  290. /// <summary>
  291. /// Sets if importer should generate a prefab as sub-asset.
  292. /// To generate a Prefab useMosaicMode needs to be set to true and importer needs to be set to import
  293. /// Sprites in multiple mode.
  294. /// </summary>
  295. public bool useCharacterMode
  296. {
  297. get => m_CharacterMode;
  298. set
  299. {
  300. m_CharacterMode = value;
  301. SetDirty();
  302. }
  303. }
  304. /// <summary>
  305. /// Sets if importer should generate a mosaic texture from the source layers.
  306. /// To generate such texture, the importer needs to be set to import Sprites in multiple mode.
  307. /// </summary>
  308. public bool useMosaicMode
  309. {
  310. get => m_MosaicLayers;
  311. set
  312. {
  313. m_MosaicLayers = value;
  314. SetDirty();
  315. }
  316. }
  317. /// <summary>
  318. /// Sets the padding between each Sprites in the mosaic texture.
  319. /// </summary>
  320. public uint mosiacPadding
  321. {
  322. get => (uint)m_Padding;
  323. set
  324. {
  325. m_Padding = (int)value;
  326. SetDirty();
  327. }
  328. }
  329. /// <summary>
  330. /// Sets the value to increase the Sprite size by.
  331. /// </summary>
  332. public ushort spriteSizeExpand
  333. {
  334. get => m_SpriteSizeExpand;
  335. set
  336. {
  337. m_SpriteSizeExpand = value;
  338. m_SpriteSizeExpandChanged = true;
  339. SetDirty();
  340. }
  341. }
  342. internal TextureImporterSwizzle swizzleR
  343. {
  344. get => m_TextureImporterSettings.swizzleR;
  345. set
  346. {
  347. m_TextureImporterSettings.swizzleR = value;
  348. SetDirty();
  349. }
  350. }
  351. internal TextureImporterSwizzle swizzleG
  352. {
  353. get => m_TextureImporterSettings.swizzleG;
  354. set
  355. {
  356. m_TextureImporterSettings.swizzleG = value;
  357. SetDirty();
  358. }
  359. }
  360. internal TextureImporterSwizzle swizzleB
  361. {
  362. get => m_TextureImporterSettings.swizzleB;
  363. set
  364. {
  365. m_TextureImporterSettings.swizzleB = value;
  366. SetDirty();
  367. }
  368. }
  369. internal TextureImporterSwizzle swizzleA
  370. {
  371. get => m_TextureImporterSettings.swizzleA;
  372. set
  373. {
  374. m_TextureImporterSettings.swizzleA = value;
  375. SetDirty();
  376. }
  377. }
  378. internal bool sRGBTexture
  379. {
  380. get => m_TextureImporterSettings.sRGBTexture;
  381. set
  382. {
  383. m_TextureImporterSettings.sRGBTexture = value;
  384. SetDirty();
  385. }
  386. }
  387. void SetDirty()
  388. {
  389. EditorUtility.SetDirty(this);
  390. }
  391. }
  392. }