Bez popisu
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.0KB

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