* In the Unity Eiditor, 'Sprite Slice' is not simple. If they were many Sprites, should slice a lot of borders.
2. Drag and drop any texture of the folder to the object field or Input the path which contains textures on the path input field.
3 - 4. If you want slice each texture of path, could set 'Setting Apply Type' to 'Only This Texture' and then click the button 'Apply Only This Texture'.
private void Slice(){
var factory = new SpriteDataProviderFactories();
factory.Init();
var dataProvider = factory.GetSpriteEditorDataProviderFromObject(obj);
dataProvider.InitSpriteEditorDataProvider();
var textureImporter = (dataProvider.targetObject as TextureImporter);
textureImporter.textureType = TextureImporterType.Sprite;
textureImporter.spritePixelsPerUnit = 100;
textureImporter.spriteImportMode = SpriteImportMode.Single;
textureImporter.SaveAndReimport();
var textureProvider = dataProvider.GetDataProvider<ITextureDataProvider>();
if (textureProvider != null)
{
int width = 0, height = 0;
textureProvider.GetTextureActualWidthAndHeight(out width, out height);
//var rect = InternalSpriteUtility.GenerateGridSpriteRectangles(obj as Texture2D, Vector2.zero, new Vector2(64,64), Vector2.zero, true);
var rect = InternalSpriteUtility.GenerateAutomaticSpriteRectangles(obj as Texture2D, width,0);
List<SpriteRect> rects = new List<SpriteRect>();
for (int i = 0; i < rect.Length; i++)
{
SpriteRect r = new SpriteRect();
r.rect = rect[i];
r.alignment = SpriteAlignment.Center;
// left , bottom, right, top
r.border = new Vector4(width / 3, height / 3, width / 3,height / 3);
r.name = $"{obj.name}_{i}";
r.pivot = new Vector2(0.5f, 0.5f);
r.spriteID = GUID.Generate();
rects.Add(r);
}
dataProvider.SetSpriteRects(rects.ToArray());
dataProvider.Apply();
}
textureImporter.SaveAndReimport();
}