Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
4
Question by Hupman · Nov 18, 2015 at 08:58 PM · 2d sprites

2D Sprites : Slice multiple sprite sheets at once

I have about 150 sprite sheets I need to slice. Each should be split by grid into 64 x 64 cells. It is an task in the Sprite Editor, except for the fact I need to do this 150 times. Is there a way to shift+click multiple sprite sheets then slice all at once? I can't seem to open the Sprite Editor with multiple sheets clicked.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Soos621 · Nov 18, 2015 at 09:08 PM 1
Share

nope sorry you will have to do this manually for each sprite sheet. Though i don't know if there is an editor extension you can purchase that will accomplish this.

avatar image Hupman Soos621 · Nov 18, 2015 at 09:26 PM 0
Share

Thats what I was worried about. I just clicked through it all - pretty tedious, but didn't take as long as I thought. I'd hate to do this for 1000+ sheets!

avatar image Soos621 Hupman · Nov 18, 2015 at 09:29 PM 0
Share

lol yeah sometimes it just comes with the territory

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by lucks17 · Dec 23, 2019 at 04:23 AM

Maybe this could help: https://answers.unity.com/questions/1113025/batch-operation-to-slice-sprites-in-editor.html?_ga=2.32794360.796740819.1577073889-1730206695.1568833357

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by FreeReignPublishing · Feb 05 at 07:12 AM

here's an overhaul to the script...


Added a seperate window under the menu item for slicing

Can now auto slice a sprite ie "can cut out nothing but the sprite from dead space"

To slice a sprite select one or more in the asset hierarchy then click the slice button in the window

Can change the pivot for each sprite sliced

Can change the threshold ie "the max pixel opacity to check for when auto slicing"


Make sure to put this script in a folder called: Editor


 using UnityEditor;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SpriteSlicer : EditorWindow
 {
 
     static float threshold = 1;
     static Vector2 pivot = new Vector2(0.5f, 0.5f);
 
     void OnGUI()
     {
         threshold = Mathf.Clamp(EditorGUILayout.FloatField("Threshold: ", threshold), 0, 1);
         pivot = EditorGUILayout.Vector2Field("Pivot: ", pivot);
 
         if (GUILayout.Button("Slice"))
         {
             Slice();
         }
 
         this.Repaint();
     }
 
     [MenuItem("Sprite Slicer/Open Slicer")]
     static void OpenSlicer()
     {
         EditorWindow.GetWindow(typeof(SpriteSlicer));
     }
 
     static void Slice()
     {  
         Object[] spriteSheets = Selection.GetFiltered<Texture2D>(SelectionMode.Assets);
 
         for (int z = 0; z < spriteSheets.Length; z++)
         {
             string path = AssetDatabase.GetAssetPath(spriteSheets[z]);
             TextureImporter ti = AssetImporter.GetAtPath(path) as TextureImporter;
             ti.isReadable = true;
             AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
 
             if (ti.spriteImportMode != SpriteImportMode.Single)
                 ti.spriteImportMode = SpriteImportMode.Single;
 
             ti.spriteImportMode = SpriteImportMode.Multiple;
 
             List<SpriteMetaData> newData = new List<SpriteMetaData>();
 
             Texture2D spriteSheet = spriteSheets[z] as Texture2D;
 
             int maxY = 0;
             int maxX = 0;
 
             int minY = spriteSheet.height;
             int minX = spriteSheet.width;
 
             for (int i = 0; i < spriteSheet.width; i++)
             {
                 for (int j = spriteSheet.height; j >= 0; j--)
                 {
                     if (spriteSheet.GetPixel(i, j).a >= threshold && j > maxY)
                         maxY = j;
 
                     if (spriteSheet.GetPixel(i, j).a >= threshold && j < minY)
                         minY = j;
 
                     if (spriteSheet.GetPixel(i, j).a >= threshold && i > maxX)
                         maxX = i;
 
                    if (spriteSheet.GetPixel(i, j).a >= threshold && i < minX)
                         minX = i;
                 }
             }
 
             SpriteMetaData smd = new SpriteMetaData();
             smd.pivot = pivot;
             smd.alignment = 9;
             smd.name = spriteSheet.name;
 
             smd.rect = new Rect(minX, minY, (maxX - minX) + 1, (maxY - minY) + 1);
 
             newData.Add(smd);
             ti.spritesheet = newData.ToArray();
             AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
         }
     }
 }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

39 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

RaycastHit2D point.x and render bound.size.x 0 Answers

SOLVED. How can I use one parent object animator to control multiple child sprite animations? 1 Answer

2d sprites jittering when I rotate. 0 Answers

2D mask that is modified every frame 0 Answers

Adding and swapping weapons in 2D rig animations 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges