A game about forced loneliness, made by TACStudios
at master 294 lines 14 kB view raw
1using System; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.U2D; 5using UnityObject = UnityEngine.Object; 6 7namespace UnityEditor.U2D.Sprites 8{ 9 /// <summary>An interface that allows Sprite Editor Window to edit Sprite data for user custom importer.</summary> 10 /// <remarks> Use this interface to edit Sprite data. 11 /// <code> 12 /// using UnityEditor; 13 /// using UnityEditor.U2D.Sprites; 14 /// using UnityEngine; 15 /// 16 /// public class PivotUpdater : AssetPostprocessor 17 /// { 18 /// private void OnPreprocessTexture() 19 /// { 20 /// var factory = new SpriteDataProviderFactories(); 21 /// factory.Init(); 22 /// var dataProvider = factory.GetSpriteEditorDataProviderFromObject(assetImporter); 23 /// dataProvider.InitSpriteEditorDataProvider(); 24 /// 25 /// SetPivot(dataProvider, new Vector2(0.5f, 0.5f)); 26 /// 27 /// dataProvider.Apply(); 28 /// } 29 /// 30 /// static void SetPivot(ISpriteEditorDataProvider dataProvider, Vector2 pivot) 31 /// { 32 /// var spriteRects = dataProvider.GetSpriteRects(); 33 /// foreach (var rect in spriteRects) 34 /// { 35 /// rect.pivot = pivot; 36 /// rect.alignment = SpriteAlignment.Custom; 37 /// } 38 /// dataProvider.SetSpriteRects(spriteRects); 39 /// } 40 /// } 41 /// </code> 42 /// </remarks> 43 public interface ISpriteEditorDataProvider 44 { 45 /// <summary>SpriteImportMode to indicate how Sprite data will be imported.</summary> 46 SpriteImportMode spriteImportMode { get; } 47 /// <summary>The number of pixels in the sprite that correspond to one unit in world space.</summary> 48 float pixelsPerUnit { get; } 49 /// <summary>The object that this data provider is acquiring its data from.</summary> 50 UnityObject targetObject { get; } 51 /// <summary>Returns an array of SpriteRect representing Sprite data the provider has.</summary> 52 /// <returns>Array of SpriteRect.</returns> 53 SpriteRect[] GetSpriteRects(); 54 /// <summary>Sets the data provider's current SpriteRect.</summary> 55 /// <param name="spriteRects">Updated array of SpriteRect.</param> 56 void SetSpriteRects(SpriteRect[] spriteRects); 57 /// <summary>Applying any changed data.</summary> 58 void Apply(); 59 /// <summary>Allows the data provider to initialize any data if needed.</summary> 60 void InitSpriteEditorDataProvider(); 61 /// <summary>Gets other data providers that might be supported by ISpriteEditorDataProvider.targetObject.</summary> 62 /// <typeparam name="T">The data provider type to acquire.</typeparam> 63 /// <returns>Data provider type.</returns> 64 T GetDataProvider<T>() where T : class; 65 /// <summary>Queries if ISpriteEditorDataProvider.targetObject supports the data provider type.</summary> 66 /// <param name="type">Data provider type.</param> 67 /// <returns>True if supports, false otherwise.</returns> 68 bool HasDataProvider(Type type); 69 70 /// <summary> 71 /// Register callback for data change. 72 /// </summary> 73 /// <param name="action">Callback delegate.</param> 74 void RegisterDataChangeCallback(Action<ISpriteEditorDataProvider> action) 75 { } 76 77 /// <summary> 78 /// Unregister callback for data change. 79 /// </summary> 80 /// <param name="action">Callback delegate.</param> 81 void UnregisterDataChangeCallback(Action<ISpriteEditorDataProvider> action) 82 { } 83 } 84 85 /// <summary> 86 /// Data Provider interface that deals with Sprite Bone data. 87 /// </summary> 88 public interface ISpriteBoneDataProvider 89 { 90 /// <summary> 91 /// Returns the list of SpriteBone for the corresponding Sprite ID. 92 /// </summary> 93 /// <param name="guid">Sprite ID.</param> 94 /// <returns>The list of SpriteBone associated with the Sprite</returns> 95 List<SpriteBone> GetBones(GUID guid); 96 97 /// <summary>Sets a new set of SpriteBone for the corresponding Sprite ID.</summary> 98 /// <param name = "guid" > Sprite ID.</param> 99 /// <param name = "bones" > List of SpriteBone to associate with the Sprite.</param> 100 void SetBones(GUID guid, List<SpriteBone> bones); 101 } 102 103 /// <summary> 104 /// Data provider that provides data for ID to be used given a SpriteRect's name. 105 /// </summary> 106 /// <remarks> 107 /// The name and ID pair is used to allow mapping back a previous created SpriteRect. 108 /// </remarks> 109 public interface ISpriteNameFileIdDataProvider 110 { 111 /// <summary>Returns an IEnumerable of SpriteNameFileIdPair representing the name and file id pairs the provider has.</summary> 112 /// <returns>Name and file id pairs.</returns> 113 IEnumerable<SpriteNameFileIdPair> GetNameFileIdPairs(); 114 /// <summary>Sets the data provider's current NameFileIdPair.</summary> 115 /// <param name="nameFileIdPairs">Updated IEnumerable of SpriteNameFileIdPair.</param> 116 void SetNameFileIdPairs(IEnumerable<SpriteNameFileIdPair> nameFileIdPairs); 117 } 118 119 /// <summary>Data provider that provides the outline data for SpriteRect.</summary> 120 /// <remarks>The outline data is used to tessellate a Sprite's mesh.</remarks> 121 public interface ISpriteOutlineDataProvider 122 { 123 /// <summary>Given a GUID, returns the outline data used for tessellating the SpriteRect.</summary> 124 /// <param name="guid">GUID of the SpriteRect.</param> 125 /// <returns>Outline data for theSpriteRect.</returns> 126 List<Vector2[]> GetOutlines(GUID guid); 127 /// <summary>Given a GUID, sets the outline data used for tessellating the SpriteRect.</summary> 128 /// <param name="guid">GUID of the SpriteRect.</param> 129 /// <param name="data">Outline data for theSpriteRect.</param> 130 void SetOutlines(GUID guid, List<Vector2[]> data); 131 /// <summary>Given a GUID, returns the tessellation detail.Tessellation value should be between 0 to 1.</summary> 132 /// <param name = "guid" > GUID of the SpriteRect.</param> 133 /// <returns>The tessellation value.</returns> 134 float GetTessellationDetail(GUID guid); 135 /// <summary>Given a GUID, sets the tessellation detail.Tessellation value should be between 0 to 1.</summary> 136 /// <param name = "guid" > GUID of the SpriteRect.</param> 137 /// <param name="value">The tessellation value.</param> 138 void SetTessellationDetail(GUID guid, float value); 139 } 140 141 /// <summary>Data provider that provides the Physics outline data for SpriteRect.</summary> 142 /// <remarks>Uses the outline data to generate the Sprite's Physics shape for Polygon Collider 2D.</remarks> 143 public interface ISpritePhysicsOutlineDataProvider 144 { 145 /// <summary>Given a GUID, returns the Physics outline data used for the SpriteRect.</summary> 146 /// <param name="guid">GUID of the SpriteRect.</param> 147 /// <returns>Physics outline data for the SpriteRect.</returns> 148 List<Vector2[]> GetOutlines(GUID guid); 149 /// <summary>Given a GUID, sets the Physics outline data used for the SpriteRect.</summary> 150 /// <param name="guid">GUID of the SpriteRect.</param> 151 /// <param name="data">Physics outline data for the SpriteRect.</param> 152 void SetOutlines(GUID guid, List<Vector2[]> data); 153 /// <summary>Given a GUID, returns the tessellation detail.Tessellation value should be between 0 to 1.</summary> 154 /// <param name = "guid" > GUID of the SpriteRect.</param> 155 /// <returns>The tessellation value.</returns> 156 float GetTessellationDetail(GUID guid); 157 /// <summary>Given a GUID, sets the tessellation detail.Tessellation value should be between 0 to 1.</summary> 158 /// <param name = "guid" > GUID of the SpriteRect.</param> 159 /// <param name="value">The tessellation value.</param> 160 void SetTessellationDetail(GUID guid, float value); 161 } 162 163 /// <summary>Data provider that provides texture data needed for Sprite Editor Window.</summary> 164 public interface ITextureDataProvider 165 { 166 /// <summary>Texture2D representation of the data provider.</summary> 167 Texture2D texture { get; } 168 /// <summary>Texture2D that represents the preview for ITextureDataProvider.texture.</summary> 169 Texture2D previewTexture { get; } 170 /// <summary>The actual width and height of the texture data.</summary> 171 /// <param name="width">Out value for width.</param> 172 /// <param name="height">Out value for height.</param> 173 void GetTextureActualWidthAndHeight(out int width , out int height); 174 /// <summary>Readable version of ITextureProvider.texture.</summary> 175 /// <returns>Texture2D that is readable.</returns> 176 Texture2D GetReadableTexture2D(); 177 178 /// <summary> 179 /// Overrides the texture data with the given textures. 180 /// </summary> 181 /// <param name="mainTexture">Main texture data to override.</param> 182 /// <param name="previewTexture">Preview texture data to override.</param> 183 /// <param name="width">Width of the override source texture.</param> 184 /// <param name="height">Height of the override source texture.</param> 185 /// <returns>Returns true if override is successful, false otherwise</returns> 186 bool OverrideTextures(Texture2D mainTexture, Texture2D previewTexture, int width, int height) 187 { 188 return false; 189 } 190 191 /// <summary> 192 /// Registers a callback to override the source texture. 193 /// </summary> 194 /// <param name="action">Callback that will write to the source texture with the path of the source texture.</param> 195 void RegisterSourceTextureOverride(Action<string> action) 196 { } 197 198 /// <summary> 199 /// Unregister a callback to override the source texture. 200 /// </summary> 201 /// <param name="action">Callback that was registered to write to the source texture with the path of the source texture.</param> 202 void UnregisterSourceTextureOverride(Action<string> action) 203 { } 204 205 /// <summary> 206 /// Register callback for data change. 207 /// </summary> 208 /// <param name="action">Callback delegate.</param> 209 void RegisterDataChangeCallback(Action<ITextureDataProvider> action) 210 { } 211 212 /// <summary> 213 /// Unregister callback for data change. 214 /// </summary> 215 /// <param name="action">Callback delegate.</param> 216 void UnregisterDataChangeCallback(Action<ITextureDataProvider> action) 217 { } 218 } 219 220 /// <summary>Data provider that provides secoondary texture data needed for Sprite Editor Window.</summary> 221 public interface ISecondaryTextureDataProvider 222 { 223 /// <summary> 224 /// Get set method for an array of SecondarySpriteTexture in the Data Provider 225 /// </summary> 226 SecondarySpriteTexture[] textures { get; set; } 227 } 228 229 /// <summary>A structure that contains meta data about vertices in a Sprite.</summary> 230 [Serializable] 231 public struct Vertex2DMetaData 232 { 233 /// <summary>The position of the vertex.</summary> 234 public Vector2 position; 235 /// <summary>The BoneWeight of the vertex.</summary> 236 public BoneWeight boneWeight; 237 } 238 239 /// <summary>Data Provider interface that deals with Sprite mesh data.</summary> 240 public interface ISpriteMeshDataProvider 241 { 242 /// <summary>Returns the list of vertex datas for the corresponding Sprite ID.</summary> 243 /// <param name = "guid" > Sprite ID.</param> 244 Vertex2DMetaData[] GetVertices(GUID guid); 245 /// <summary>Sets a new list of vertices for the corresponding Sprite ID.</summary> 246 /// <param name = "guid" > Sprite ID.</param> 247 void SetVertices(GUID guid, Vertex2DMetaData[] vertices); 248 /// <summary>Returns the list of mesh index for the corresponding Sprite ID.</summary> 249 /// <param name = "guid" > Sprite ID.</param> 250 int[] GetIndices(GUID guid); 251 /// <summary>Sets a new list of indices for the corresponding Sprite ID.</summary> 252 /// <param name = "guid" > Sprite ID.</param> 253 void SetIndices(GUID guid, int[] indices); 254 /// <summary>Returns the list of mesh edges for the corresponding Sprite ID.</summary> 255 /// <param name = "guid" > Sprite ID.</param> 256 Vector2Int[] GetEdges(GUID guid); 257 /// <summary>Sets a new list of edges for the corresponding Sprite ID.</summary> 258 /// <param name = "guid" > Sprite ID.</param> 259 void SetEdges(GUID guid, Vector2Int[] edges); 260 } 261 262 /// <summary> 263 /// Data Provider interface that allows to get and set custom Sprite data. 264 /// </summary> 265 internal interface ISpriteCustomDataProvider 266 { 267 /// <summary> 268 /// Gets all available keys. 269 /// </summary> 270 /// <returns>Collection of all available keys.</returns> 271 public IEnumerable<string> GetKeys(); 272 273 /// <summary> 274 /// Sets the custom data at the given key. 275 /// </summary> 276 /// <param name="key">Name of the key.</param> 277 /// <param name="data">Value.</param> 278 public void SetData(string key, string data); 279 280 /// <summary> 281 /// Removes the custom data at the given key. 282 /// </summary> 283 /// <param name="key">Name of the key.</param> 284 public void RemoveData(string key); 285 286 /// <summary> 287 /// Gets the custom data at the given key. 288 /// </summary> 289 /// <param name="key">Name of the key.</param> 290 /// <param name="data">Value.</param> 291 /// <returns>True if the value retrieved successfully.</returns> 292 public bool GetData(string key, out string data); 293 } 294}