暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TilesetChunk.cs 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.IO;
  3. namespace UnityEditor.U2D.Aseprite
  4. {
  5. /// <summary>
  6. /// Flags to define where data for a tileset is stored.
  7. /// </summary>
  8. [Flags]
  9. public enum TileSetFlags
  10. {
  11. IncludesLinkToExternal = 1,
  12. IncludesTilesInFile = 2,
  13. Misc = 4,
  14. }
  15. /// <summary>
  16. /// Parsed representation of an Aseprite Tileset chunk.
  17. /// </summary>
  18. /// <note>Not supported yet.</note>
  19. public class TilesetChunk : BaseChunk
  20. {
  21. public override ChunkTypes chunkType => ChunkTypes.Tileset;
  22. /// <summary>
  23. /// The ID of the tileset.
  24. /// </summary>
  25. public uint tileSetId { get; private set; }
  26. /// <summary>
  27. /// Flags to define where data for a tileset is stored.
  28. /// </summary>
  29. public TileSetFlags tileSetFlags { get; private set; }
  30. /// <summary>
  31. /// The number of tiles in the tileset.
  32. /// </summary>
  33. public uint noOfTiles { get; private set; }
  34. /// <summary>
  35. /// Tile width in pixels.
  36. /// </summary>
  37. public ushort width { get; private set; }
  38. /// <summary>
  39. /// Tile height in pixels.
  40. /// </summary>
  41. public ushort height { get; private set; }
  42. /// <summary>
  43. /// The name of the tileset.
  44. /// </summary>
  45. public string tileSetName { get; private set; }
  46. readonly ushort m_ColorDepth;
  47. readonly PaletteChunk m_PaletteChunk;
  48. readonly byte m_AlphaPaletteEntry;
  49. internal TilesetChunk(uint chunkSize, ushort colorDepth, PaletteChunk paletteChunk, byte alphaPaletteEntry) : base(chunkSize)
  50. {
  51. m_ColorDepth = colorDepth;
  52. m_PaletteChunk = paletteChunk;
  53. m_AlphaPaletteEntry = alphaPaletteEntry;
  54. }
  55. protected override void InternalRead(BinaryReader reader)
  56. {
  57. tileSetId = reader.ReadUInt32();
  58. tileSetFlags = (TileSetFlags)reader.ReadUInt32();
  59. noOfTiles = reader.ReadUInt32();
  60. width = reader.ReadUInt16();
  61. height = reader.ReadUInt16();
  62. var baseIndex = reader.ReadInt16();
  63. var reservedBytes = reader.ReadBytes(14);
  64. tileSetName = AsepriteUtilities.ReadString(reader);
  65. // Not supported yet.
  66. if ((tileSetFlags & TileSetFlags.IncludesLinkToExternal) != 0)
  67. {
  68. var idOfExternalFile = reader.ReadUInt32();
  69. var tileSetIdInExternal = reader.ReadUInt32();
  70. }
  71. if ((tileSetFlags & TileSetFlags.IncludesTilesInFile) != 0)
  72. {
  73. var compressedDataLength = (int)reader.ReadUInt32();
  74. var decompressedData = AsepriteUtilities.ReadAndDecompressedData(reader, compressedDataLength);
  75. var image = AsepriteUtilities.GenerateImageData(m_ColorDepth, decompressedData, m_PaletteChunk, m_AlphaPaletteEntry);
  76. // Disposing for now.
  77. image.Dispose();
  78. }
  79. }
  80. }
  81. }