No Description
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.

LayerChunk.cs 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using System.IO;
  3. namespace UnityEditor.U2D.Aseprite
  4. {
  5. /// <summary>
  6. /// Flags for layer options.
  7. /// </summary>
  8. [Flags]
  9. public enum LayerFlags
  10. {
  11. Visible = 1,
  12. Editable = 2,
  13. LockMovement = 4,
  14. Background = 8,
  15. PreferLinkedCels = 16,
  16. DisplayAsCollapsed = 32,
  17. ReferenceLayer = 64
  18. }
  19. /// <summary>
  20. /// Layer types.
  21. /// </summary>
  22. public enum LayerTypes
  23. {
  24. Normal = 0,
  25. Group = 1,
  26. Tilemap = 2
  27. }
  28. /// <summary>
  29. /// Layer blend modes.
  30. /// </summary>
  31. public enum BlendModes
  32. {
  33. Normal = 0,
  34. Multiply = 1,
  35. Screen = 2,
  36. Overlay = 3,
  37. Darken = 4,
  38. Lighten = 5,
  39. ColorDodge = 6,
  40. ColorBurn = 7,
  41. HardLight = 8,
  42. SoftLight = 9,
  43. Difference = 10,
  44. Exclusion = 11,
  45. Hue = 12,
  46. Saturation = 13,
  47. Color = 14,
  48. Luminosity = 15,
  49. Addition = 16,
  50. Subtract = 17,
  51. Divide = 18
  52. }
  53. /// <summary>
  54. /// Parsed representation of an Aseprite Layer chunk.
  55. /// </summary>
  56. public class LayerChunk : BaseChunk
  57. {
  58. public override ChunkTypes chunkType => ChunkTypes.Layer;
  59. /// <summary>
  60. /// Layer option flags.
  61. /// </summary>
  62. public LayerFlags flags { get; private set; }
  63. /// <summary>
  64. /// Type of layer.
  65. /// </summary>
  66. public LayerTypes layerType { get; private set; }
  67. /// <summary>
  68. /// The child level is used to show the relationship of this layer with the last one read.
  69. /// </summary>
  70. public ushort childLevel { get; private set; }
  71. /// <summary>
  72. /// Layer blend mode.
  73. /// </summary>
  74. public BlendModes blendMode { get; private set; }
  75. // Layer opacity (0 = transparent, 255 = opaque).
  76. public byte opacity { get; private set; }
  77. /// <summary>
  78. /// Layer name.
  79. /// </summary>
  80. public string name { get; private set; }
  81. /// <summary>
  82. /// Tileset index (Only available for Tilemap layers).
  83. /// </summary>
  84. public uint tileSetIndex { get; private set; }
  85. internal LayerChunk(uint chunkSize) : base(chunkSize) { }
  86. protected override void InternalRead(BinaryReader reader)
  87. {
  88. flags = (LayerFlags)reader.ReadUInt16();
  89. layerType = (LayerTypes)reader.ReadUInt16();
  90. childLevel = reader.ReadUInt16();
  91. var defaultLayerWidth = reader.ReadUInt16();
  92. var defaultLayerHeight = reader.ReadUInt16();
  93. blendMode = (BlendModes)reader.ReadUInt16();
  94. opacity = reader.ReadByte();
  95. // Not in use bytes
  96. for (var i = 0; i < 3; ++i)
  97. reader.ReadByte();
  98. name = AsepriteUtilities.ReadString(reader);
  99. if (layerType == LayerTypes.Tilemap)
  100. tileSetIndex = reader.ReadUInt32();
  101. }
  102. }
  103. }