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.

ImporterStructures.cs 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. using System;
  2. using System.Collections.Generic;
  3. using Unity.Collections;
  4. using UnityEngine;
  5. using UnityEngine.Serialization;
  6. namespace UnityEditor.U2D.Aseprite
  7. {
  8. [Serializable]
  9. internal class Layer
  10. {
  11. [SerializeField] int m_LayerIndex;
  12. [SerializeField] int m_Guid;
  13. [SerializeField] string m_Name;
  14. [SerializeField] LayerFlags m_LayerFlags;
  15. [SerializeField] LayerTypes m_LayerType;
  16. [SerializeField] BlendModes m_BlendMode;
  17. [SerializeField] List<Cell> m_Cells = new List<Cell>();
  18. [SerializeField] List<LinkedCell> m_LinkedCells = new List<LinkedCell>();
  19. [SerializeField] int m_ParentIndex = -1;
  20. [NonSerialized] public float opacity;
  21. public int index
  22. {
  23. get => m_LayerIndex;
  24. set => m_LayerIndex = value;
  25. }
  26. public int guid
  27. {
  28. get => m_Guid;
  29. set => m_Guid = value;
  30. }
  31. public string name
  32. {
  33. get => m_Name;
  34. set => m_Name = value;
  35. }
  36. public LayerFlags layerFlags
  37. {
  38. get => m_LayerFlags;
  39. set => m_LayerFlags = value;
  40. }
  41. public LayerTypes layerType
  42. {
  43. get => m_LayerType;
  44. set => m_LayerType = value;
  45. }
  46. public BlendModes blendMode
  47. {
  48. get => m_BlendMode;
  49. set => m_BlendMode = value;
  50. }
  51. public List<Cell> cells
  52. {
  53. get => m_Cells;
  54. set => m_Cells = value;
  55. }
  56. public List<LinkedCell> linkedCells
  57. {
  58. get => m_LinkedCells;
  59. set => m_LinkedCells = value;
  60. }
  61. public int parentIndex
  62. {
  63. get => m_ParentIndex;
  64. set => m_ParentIndex = value;
  65. }
  66. public static int GenerateGuid(Layer layer)
  67. {
  68. var hash = layer.name.GetHashCode();
  69. hash = (hash * 397) ^ layer.index.GetHashCode();
  70. return hash;
  71. }
  72. }
  73. [Serializable]
  74. internal struct Cell
  75. {
  76. [SerializeField] string m_Name;
  77. [SerializeField] int m_FrameIndex;
  78. [SerializeField] int m_AdditiveSortOrder;
  79. [SerializeField] RectInt m_CellRect;
  80. [SerializeField] string m_SpriteId;
  81. [NonSerialized] public bool updatedCellRect;
  82. [NonSerialized] public float opacity;
  83. [NonSerialized] public BlendModes blendMode;
  84. [NonSerialized] public NativeArray<Color32> image;
  85. public string name
  86. {
  87. get => m_Name;
  88. set => m_Name = value;
  89. }
  90. public int frameIndex
  91. {
  92. get => m_FrameIndex;
  93. set => m_FrameIndex = value;
  94. }
  95. public int additiveSortOrder
  96. {
  97. get => m_AdditiveSortOrder;
  98. set => m_AdditiveSortOrder = value;
  99. }
  100. public RectInt cellRect
  101. {
  102. get => m_CellRect;
  103. set => m_CellRect = value;
  104. }
  105. public GUID spriteId
  106. {
  107. get => new GUID(m_SpriteId);
  108. set => m_SpriteId = value.ToString();
  109. }
  110. }
  111. [Serializable]
  112. internal class LinkedCell
  113. {
  114. [SerializeField] int m_FrameIndex;
  115. [SerializeField] int m_LinkedToFrame;
  116. public int frameIndex
  117. {
  118. get => m_FrameIndex;
  119. set => m_FrameIndex = value;
  120. }
  121. public int linkedToFrame
  122. {
  123. get => m_LinkedToFrame;
  124. set => m_LinkedToFrame = value;
  125. }
  126. }
  127. internal class Frame
  128. {
  129. int m_Duration;
  130. string[] m_EventStrings;
  131. public int duration
  132. {
  133. get => m_Duration;
  134. set => m_Duration = value;
  135. }
  136. public string[] eventStrings
  137. {
  138. get => m_EventStrings;
  139. set => m_EventStrings = value;
  140. }
  141. }
  142. internal class Tag
  143. {
  144. public string name { get; set; }
  145. public int fromFrame { get; set; }
  146. public int toFrame { get; set; }
  147. public int noOfRepeats { get; set; }
  148. public int noOfFrames => toFrame - fromFrame;
  149. public bool isRepeating => noOfRepeats == 0;
  150. }
  151. /// <summary>
  152. /// Import modes for the file.
  153. /// </summary>
  154. public enum FileImportModes
  155. {
  156. SpriteSheet = 0,
  157. AnimatedSprite = 1,
  158. }
  159. /// <summary>
  160. /// Import modes for all layers.
  161. /// </summary>
  162. public enum LayerImportModes
  163. {
  164. /// <summary>
  165. /// Every layer per frame generates a Sprite.
  166. /// </summary>
  167. IndividualLayers,
  168. /// <summary>
  169. /// All layers per frame are merged into one Sprite.
  170. /// </summary>
  171. MergeFrame
  172. }
  173. /// <summary>
  174. /// The space the Sprite pivots are being calculated.
  175. /// </summary>
  176. public enum PivotSpaces
  177. {
  178. /// <summary>
  179. /// Canvas space. Calculate the pivot based on where the Sprite is positioned on the source asset's canvas.
  180. /// This is useful if the Sprite is being swapped out in an animation.
  181. /// </summary>
  182. Canvas,
  183. /// <summary>
  184. /// Local space. This is the normal pivot space.
  185. /// </summary>
  186. Local
  187. }
  188. }