using System; using UnityEditor.U2D.Sprites; namespace Editor { static public partial class SpriteEditorUtility { /// /// Automatically slices a texture by detecting visible pixel regions and creating sprite rectangles. /// Uses Unity's internal automatic sprite detection algorithm to find sprite boundaries. /// /// The sprite data provider for the texture. /// The texture data provider. /// Minimum size in pixels for detected sprite rectangles. /// Number of pixels to extrude (expand) sprite boundaries. /// Method for handling existing sprites (DeleteAll, Smart, Safe). /// Function to generate sprite names based on index. /// Tolerance for detecting overlapping sprites. /// Tolerance for best-fit matching. /// Whether to use best-fit algorithm for overlap detection. /// True if slicing succeeded, false if texture is not readable. static public bool AutomaticSliceTexture(ISpriteEditorDataProvider spriteDataProvider, ITextureDataProvider textureProvider, int minRectSize, int extrudeSize, AddNewSpriteMethod addNewSpriteMethod, Func nameGenerator, float kOverlapTolerance= 0.00001f, float kBestFitTolerance = 0.5f, bool bestFit = false) { var texture = GetTextureToSlice(textureProvider); if (texture == null) { return false; } var rects = UnityEditorInternal.InternalSpriteUtility.GenerateAutomaticSpriteRectangles(texture, minRectSize, extrudeSize); var newRects = GenerateNewSpriteRects(spriteDataProvider, rects, addNewSpriteMethod, nameGenerator, kOverlapTolerance, kBestFitTolerance, bestFit); spriteDataProvider.SetSpriteRects(newRects.ToArray()); return true; } } }