ISpriteEditorDataProvider.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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>Data provider that provides the outline data for SpriteRect.</summary>
  54. /// <remarks>The outline data is used to tessellate a Sprite's mesh.</remarks>
  55. public interface ISpriteOutlineDataProvider
  56. {
  57. /// <summary>Given a GUID, returns the outline data used for tessellating the SpriteRect.</summary>
  58. /// <param name="guid">GUID of the SpriteRect.</param>
  59. /// <returns>Outline data for theSpriteRect.</returns>
  60. List<Vector2[]> GetOutlines(GUID guid);
  61. /// <summary>Given a GUID, sets the outline data used for tessellating the SpriteRect.</summary>
  62. /// <param name="guid">GUID of the SpriteRect.</param>
  63. /// <param name="data">Outline data for theSpriteRect.</param>
  64. void SetOutlines(GUID guid, List<Vector2[]> data);
  65. /// <summary>Given a GUID, returns the tessellation detail.Tessellation value should be between 0 to 1.</summary>
  66. /// <param name = "guid" > GUID of the SpriteRect.</param>
  67. /// <returns>The tessellation value.</returns>
  68. float GetTessellationDetail(GUID guid);
  69. /// <summary>Given a GUID, sets the tessellation detail.Tessellation value should be between 0 to 1.</summary>
  70. /// <param name = "guid" > GUID of the SpriteRect.</param>
  71. /// <param name="value">The tessellation value.</param>
  72. void SetTessellationDetail(GUID guid, float value);
  73. }
  74. /// <summary>Data provider that provides the Physics outline data for SpriteRect.</summary>
  75. /// <remarks>Uses the outline data to generate the Sprite's Physics shape for Polygon Collider 2D.</remarks>
  76. public interface ISpritePhysicsOutlineDataProvider
  77. {
  78. /// <summary>Given a GUID, returns the Physics outline data used for the SpriteRect.</summary>
  79. /// <param name="guid">GUID of the SpriteRect.</param>
  80. /// <returns>Physics outline data for the SpriteRect.</returns>
  81. List<Vector2[]> GetOutlines(GUID guid);
  82. /// <summary>Given a GUID, sets the Physics outline data used for the SpriteRect.</summary>
  83. /// <param name="guid">GUID of the SpriteRect.</param>
  84. /// <param name="data">Physics outline data for the SpriteRect.</param>
  85. void SetOutlines(GUID guid, List<Vector2[]> data);
  86. /// <summary>Given a GUID, returns the tessellation detail.Tessellation value should be between 0 to 1.</summary>
  87. /// <param name = "guid" > GUID of the SpriteRect.</param>
  88. /// <returns>The tessellation value.</returns>
  89. float GetTessellationDetail(GUID guid);
  90. /// <summary>Given a GUID, sets the tessellation detail.Tessellation value should be between 0 to 1.</summary>
  91. /// <param name = "guid" > GUID of the SpriteRect.</param>
  92. /// <param name="value">The tessellation value.</param>
  93. void SetTessellationDetail(GUID guid, float value);
  94. }
  95. /// <summary>Data provider that provides texture data needed for Sprite Editor Window.</summary>
  96. public interface ITextureDataProvider
  97. {
  98. /// <summary>Texture2D representation of the data provider.</summary>
  99. Texture2D texture { get; }
  100. /// <summary>Texture2D that represents the preview for ITextureDataProvider.texture.</summary>
  101. Texture2D previewTexture { get; }
  102. /// <summary>The actual width and height of the texture data.</summary>
  103. /// <param name="width">Out value for width.</param>
  104. /// <param name="height">Out value for height.</param>
  105. void GetTextureActualWidthAndHeight(out int width , out int height);
  106. /// <summary>Readable version of ITextureProvider.texture.</summary>
  107. /// <returns>Texture2D that is readable.</returns>
  108. Texture2D GetReadableTexture2D();
  109. }
  110. /// <summary>Data provider that provides secoondary texture data needed for Sprite Editor Window.</summary>
  111. public interface ISecondaryTextureDataProvider
  112. {
  113. /// <summary>
  114. /// Get set method for an array of SecondarySpriteTexture in the Data Provider
  115. /// </summary>
  116. SecondarySpriteTexture[] textures { get; set; }
  117. }
  118. /// <summary>A structure that contains meta data about vertices in a Sprite.</summary>
  119. [Serializable]
  120. public struct Vertex2DMetaData
  121. {
  122. /// <summary>The position of the vertex.</summary>
  123. public Vector2 position;
  124. /// <summary>The BoneWeight of the vertex.</summary>
  125. public BoneWeight boneWeight;
  126. }
  127. /// <summary>Data Provider interface that deals with Sprite mesh data.</summary>
  128. public interface ISpriteMeshDataProvider
  129. {
  130. /// <summary>Returns the list of vertex datas for the corresponding Sprite ID.</summary>
  131. /// <param name = "guid" > Sprite ID.</param>
  132. Vertex2DMetaData[] GetVertices(GUID guid);
  133. /// <summary>Sets a new list of vertices for the corresponding Sprite ID.</summary>
  134. /// <param name = "guid" > Sprite ID.</param>
  135. void SetVertices(GUID guid, Vertex2DMetaData[] vertices);
  136. /// <summary>Returns the list of mesh index for the corresponding Sprite ID.</summary>
  137. /// <param name = "guid" > Sprite ID.</param>
  138. int[] GetIndices(GUID guid);
  139. /// <summary>Sets a new list of indices for the corresponding Sprite ID.</summary>
  140. /// <param name = "guid" > Sprite ID.</param>
  141. void SetIndices(GUID guid, int[] indices);
  142. /// <summary>Returns the list of mesh edges for the corresponding Sprite ID.</summary>
  143. /// <param name = "guid" > Sprite ID.</param>
  144. Vector2Int[] GetEdges(GUID guid);
  145. /// <summary>Sets a new list of edges for the corresponding Sprite ID.</summary>
  146. /// <param name = "guid" > Sprite ID.</param>
  147. void SetEdges(GUID guid, Vector2Int[] edges);
  148. }
  149. }