Нема описа
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.

ISpriteEditorDataProvider.cs 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.U2D;
  5. using UnityObject = UnityEngine.Object;
  6. namespace UnityEditor.U2D.Sprites
  7. {
  8. /// <summary>An interface that allows Sprite Editor Window to edit Sprite data for user custom importer.</summary>
  9. /// <remarks>Implement this interface for [[ScriptedImporter]] to leverage on Sprite Editor Window to edit Sprite data.</remarks>
  10. public interface ISpriteEditorDataProvider
  11. {
  12. /// <summary>SpriteImportMode to indicate how Sprite data will be imported.</summary>
  13. SpriteImportMode spriteImportMode { get; }
  14. /// <summary>The number of pixels in the sprite that correspond to one unit in world space.</summary>
  15. float pixelsPerUnit { get; }
  16. /// <summary>The object that this data provider is acquiring its data from.</summary>
  17. UnityObject targetObject { get; }
  18. /// <summary>Returns an array of SpriteRect representing Sprite data the provider has.</summary>
  19. /// <returns>Array of SpriteRect.</returns>
  20. SpriteRect[] GetSpriteRects();
  21. /// <summary>Sets the data provider's current SpriteRect.</summary>
  22. /// <param name="spriteRects">Updated array of SpriteRect.</param>
  23. void SetSpriteRects(SpriteRect[] spriteRects);
  24. /// <summary>Applying any changed data.</summary>
  25. void Apply();
  26. /// <summary>Allows the data provider to initialize any data if needed.</summary>
  27. void InitSpriteEditorDataProvider();
  28. /// <summary>Gets other data providers that might be supported by ISpriteEditorDataProvider.targetObject.</summary>
  29. /// <typeparam name="T">The data provider type to acquire.</typeparam>
  30. /// <returns>Data provider type.</returns>
  31. T GetDataProvider<T>() where T : class;
  32. /// <summary>Queries if ISpriteEditorDataProvider.targetObject supports the data provider type.</summary>
  33. /// <param name="type">Data provider type.</param>
  34. /// <returns>True if supports, false otherwise.</returns>
  35. bool HasDataProvider(Type type);
  36. }
  37. /// <summary>
  38. /// Data Provider interface that deals with Sprite Bone data.
  39. /// </summary>
  40. public interface ISpriteBoneDataProvider
  41. {
  42. /// <summary>
  43. /// Returns the list of SpriteBone for the corresponding Sprite ID.
  44. /// </summary>
  45. /// <param name="guid">Sprite ID.</param>
  46. /// <returns>The list of SpriteBone associated with the Sprite</returns>
  47. List<SpriteBone> GetBones(GUID guid);
  48. /// <summary>Sets a new set of SpriteBone for the corresponding Sprite ID.</summary>
  49. /// <param name = "guid" > Sprite ID.</param>
  50. /// <param name = "bones" > List of SpriteBone to associate with the Sprite.</param>
  51. void SetBones(GUID guid, List<SpriteBone> bones);
  52. }
  53. /// <summary>
  54. /// Data provider that provides data for ID to be used given a SpriteRect's name.
  55. /// </summary>
  56. /// <remarks>
  57. /// The name and ID pair is used to allow mapping back a previous created SpriteRect.
  58. /// </remarks>
  59. public interface ISpriteNameFileIdDataProvider
  60. {
  61. /// <summary>Returns an IEnumerable of SpriteNameFileIdPair representing the name and file id pairs the provider has.</summary>
  62. /// <returns>Name and file id pairs.</returns>
  63. IEnumerable<SpriteNameFileIdPair> GetNameFileIdPairs();
  64. /// <summary>Sets the data provider's current NameFileIdPair.</summary>
  65. /// <param name="nameFileIdPairs">Updated IEnumerable of SpriteNameFileIdPair.</param>
  66. void SetNameFileIdPairs(IEnumerable<SpriteNameFileIdPair> nameFileIdPairs);
  67. }
  68. /// <summary>Data provider that provides the outline data for SpriteRect.</summary>
  69. /// <remarks>The outline data is used to tessellate a Sprite's mesh.</remarks>
  70. public interface ISpriteOutlineDataProvider
  71. {
  72. /// <summary>Given a GUID, returns the outline data used for tessellating the SpriteRect.</summary>
  73. /// <param name="guid">GUID of the SpriteRect.</param>
  74. /// <returns>Outline data for theSpriteRect.</returns>
  75. List<Vector2[]> GetOutlines(GUID guid);
  76. /// <summary>Given a GUID, sets the outline data used for tessellating the SpriteRect.</summary>
  77. /// <param name="guid">GUID of the SpriteRect.</param>
  78. /// <param name="data">Outline data for theSpriteRect.</param>
  79. void SetOutlines(GUID guid, List<Vector2[]> data);
  80. /// <summary>Given a GUID, returns the tessellation detail.Tessellation value should be between 0 to 1.</summary>
  81. /// <param name = "guid" > GUID of the SpriteRect.</param>
  82. /// <returns>The tessellation value.</returns>
  83. float GetTessellationDetail(GUID guid);
  84. /// <summary>Given a GUID, sets the tessellation detail.Tessellation value should be between 0 to 1.</summary>
  85. /// <param name = "guid" > GUID of the SpriteRect.</param>
  86. /// <param name="value">The tessellation value.</param>
  87. void SetTessellationDetail(GUID guid, float value);
  88. }
  89. /// <summary>Data provider that provides the Physics outline data for SpriteRect.</summary>
  90. /// <remarks>Uses the outline data to generate the Sprite's Physics shape for Polygon Collider 2D.</remarks>
  91. public interface ISpritePhysicsOutlineDataProvider
  92. {
  93. /// <summary>Given a GUID, returns the Physics outline data used for the SpriteRect.</summary>
  94. /// <param name="guid">GUID of the SpriteRect.</param>
  95. /// <returns>Physics outline data for the SpriteRect.</returns>
  96. List<Vector2[]> GetOutlines(GUID guid);
  97. /// <summary>Given a GUID, sets the Physics outline data used for the SpriteRect.</summary>
  98. /// <param name="guid">GUID of the SpriteRect.</param>
  99. /// <param name="data">Physics outline data for the SpriteRect.</param>
  100. void SetOutlines(GUID guid, List<Vector2[]> data);
  101. /// <summary>Given a GUID, returns the tessellation detail.Tessellation value should be between 0 to 1.</summary>
  102. /// <param name = "guid" > GUID of the SpriteRect.</param>
  103. /// <returns>The tessellation value.</returns>
  104. float GetTessellationDetail(GUID guid);
  105. /// <summary>Given a GUID, sets the tessellation detail.Tessellation value should be between 0 to 1.</summary>
  106. /// <param name = "guid" > GUID of the SpriteRect.</param>
  107. /// <param name="value">The tessellation value.</param>
  108. void SetTessellationDetail(GUID guid, float value);
  109. }
  110. /// <summary>Data provider that provides texture data needed for Sprite Editor Window.</summary>
  111. public interface ITextureDataProvider
  112. {
  113. /// <summary>Texture2D representation of the data provider.</summary>
  114. Texture2D texture { get; }
  115. /// <summary>Texture2D that represents the preview for ITextureDataProvider.texture.</summary>
  116. Texture2D previewTexture { get; }
  117. /// <summary>The actual width and height of the texture data.</summary>
  118. /// <param name="width">Out value for width.</param>
  119. /// <param name="height">Out value for height.</param>
  120. void GetTextureActualWidthAndHeight(out int width , out int height);
  121. /// <summary>Readable version of ITextureProvider.texture.</summary>
  122. /// <returns>Texture2D that is readable.</returns>
  123. Texture2D GetReadableTexture2D();
  124. }
  125. /// <summary>Data provider that provides secoondary texture data needed for Sprite Editor Window.</summary>
  126. public interface ISecondaryTextureDataProvider
  127. {
  128. /// <summary>
  129. /// Get set method for an array of SecondarySpriteTexture in the Data Provider
  130. /// </summary>
  131. SecondarySpriteTexture[] textures { get; set; }
  132. }
  133. /// <summary>A structure that contains meta data about vertices in a Sprite.</summary>
  134. [Serializable]
  135. public struct Vertex2DMetaData
  136. {
  137. /// <summary>The position of the vertex.</summary>
  138. public Vector2 position;
  139. /// <summary>The BoneWeight of the vertex.</summary>
  140. public BoneWeight boneWeight;
  141. }
  142. /// <summary>Data Provider interface that deals with Sprite mesh data.</summary>
  143. public interface ISpriteMeshDataProvider
  144. {
  145. /// <summary>Returns the list of vertex datas for the corresponding Sprite ID.</summary>
  146. /// <param name = "guid" > Sprite ID.</param>
  147. Vertex2DMetaData[] GetVertices(GUID guid);
  148. /// <summary>Sets a new list of vertices for the corresponding Sprite ID.</summary>
  149. /// <param name = "guid" > Sprite ID.</param>
  150. void SetVertices(GUID guid, Vertex2DMetaData[] vertices);
  151. /// <summary>Returns the list of mesh index for the corresponding Sprite ID.</summary>
  152. /// <param name = "guid" > Sprite ID.</param>
  153. int[] GetIndices(GUID guid);
  154. /// <summary>Sets a new list of indices for the corresponding Sprite ID.</summary>
  155. /// <param name = "guid" > Sprite ID.</param>
  156. void SetIndices(GUID guid, int[] indices);
  157. /// <summary>Returns the list of mesh edges for the corresponding Sprite ID.</summary>
  158. /// <param name = "guid" > Sprite ID.</param>
  159. Vector2Int[] GetEdges(GUID guid);
  160. /// <summary>Sets a new list of edges for the corresponding Sprite ID.</summary>
  161. /// <param name = "guid" > Sprite ID.</param>
  162. void SetEdges(GUID guid, Vector2Int[] edges);
  163. }
  164. }